Skip to content

Commit

Permalink
Replace source utils usage in tests with mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
salander85 committed Dec 4, 2023
1 parent cbc5043 commit 16a763a
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import com.commercetools.api.defaultconfig.ApiRootBuilder;
import com.commercetools.api.models.product_type.AttributeConstraintEnum;
import com.commercetools.api.models.product_type.AttributeDefinition;
import com.commercetools.api.models.product_type.AttributeDefinitionBuilder;
import com.commercetools.api.models.product_type.AttributeDefinitionDraft;
import com.commercetools.api.models.product_type.AttributeDefinitionDraftBuilder;
import com.commercetools.api.models.product_type.AttributeLocalizedEnumValueBuilder;
Expand All @@ -36,7 +35,6 @@
import com.commercetools.sync.producttypes.ProductTypeSyncOptions;
import com.commercetools.sync.producttypes.ProductTypeSyncOptionsBuilder;
import com.commercetools.sync.producttypes.helpers.ProductTypeSyncStatistics;
import com.commercetools.sync.producttypes.helpers.ResourceToDraftConverters;
import io.vrap.rmf.base.client.ApiHttpMethod;
import io.vrap.rmf.base.client.ApiHttpResponse;
import io.vrap.rmf.base.client.error.BadGatewayException;
Expand Down Expand Up @@ -870,8 +868,8 @@ void sync_withProductTypeWithCategoryReference_ShouldAddNewAttributesToTheProduc
final ProductTypeSyncOptions productTypeSyncOptions =
ProductTypeSyncOptionsBuilder.of(CTP_TARGET_CLIENT).build();

final AttributeDefinition referenceTypeAttr =
AttributeDefinitionBuilder.of()
final AttributeDefinitionDraft referenceTypeAttr =
AttributeDefinitionDraftBuilder.of()
.name("referenceTypeAttr")
.label(ofEnglish("referenceTypeAttr"))
.type(
Expand All @@ -893,9 +891,7 @@ void sync_withProductTypeWithCategoryReference_ShouldAddNewAttributesToTheProduc
.key(PRODUCT_TYPE_KEY_3)
.name(PRODUCT_TYPE_NAME_3)
.description(PRODUCT_TYPE_DESCRIPTION_3)
.attributes(
ResourceToDraftConverters.toAttributeDefinitionDraftBuilder(referenceTypeAttr)
.build())
.attributes(referenceTypeAttr)
.build();

final ProductTypeSync productTypeSync = new ProductTypeSync(productTypeSyncOptions);
Expand All @@ -906,10 +902,7 @@ void sync_withProductTypeWithCategoryReference_ShouldAddNewAttributesToTheProduc
.key(PRODUCT_TYPE_KEY_3)
.name(PRODUCT_TYPE_NAME_3)
.description(PRODUCT_TYPE_DESCRIPTION_3)
.attributes(
ATTRIBUTE_DEFINITION_DRAFT_1,
ResourceToDraftConverters.toAttributeDefinitionDraftBuilder(referenceTypeAttr)
.build())
.attributes(ATTRIBUTE_DEFINITION_DRAFT_1, referenceTypeAttr)
.build();

productTypeSync.sync(singletonList(updatedProductTypeDraft)).toCompletableFuture().join();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.commercetools.sync.producttypes.utils;

import static com.commercetools.api.models.common.LocalizedString.ofEnglish;
import static com.commercetools.sync.producttypes.MockBuilderUtils.createMockAttributeDefinitionDraftBuilder;
import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -30,7 +31,6 @@
import com.commercetools.api.models.product_type.ProductTypeUpdateAction;
import com.commercetools.api.models.product_type.TextInputHint;
import com.commercetools.sync.producttypes.MockBuilderUtils;
import com.commercetools.sync.producttypes.helpers.ResourceToDraftConverters;
import java.util.List;
import java.util.Optional;
import org.junit.jupiter.api.Test;
Expand All @@ -51,7 +51,7 @@ class AttributeDefinitionUpdateActionUtilsTest {
void buildChangeLabelAction_WithDifferentValues_ShouldReturnAction() {
// Preparation
final AttributeDefinitionDraft draft =
MockBuilderUtils.createMockAttributeDefinitionDraftBuilder().label(ofEnglish("x")).build();
createMockAttributeDefinitionDraftBuilder().label(ofEnglish("x")).build();

final AttributeDefinition attributeDefinition =
MockBuilderUtils.createMockAttributeDefinitionBuilder().label(ofEnglish("y")).build();
Expand All @@ -73,8 +73,7 @@ void buildChangeLabelAction_WithDifferentValues_ShouldReturnAction() {
@Test
void buildChangeLabelAction_WithSameValues_ShouldReturnEmptyOptional() {
// Preparation
final AttributeDefinitionDraft draft =
MockBuilderUtils.createMockAttributeDefinitionDraftBuilder().build();
final AttributeDefinitionDraft draft = createMockAttributeDefinitionDraftBuilder().build();

final AttributeDefinition attributeDefinition =
MockBuilderUtils.createMockAttributeDefinitionBuilder().build();
Expand All @@ -92,9 +91,7 @@ void buildChangeLabelAction_WithSameValues_ShouldReturnEmptyOptional() {
void buildSetInputTipAction_WithDifferentValues_ShouldReturnAction() {
// Preparation
final AttributeDefinitionDraft draft =
MockBuilderUtils.createMockAttributeDefinitionDraftBuilder()
.inputTip(ofEnglish("foo"))
.build();
createMockAttributeDefinitionDraftBuilder().inputTip(ofEnglish("foo")).build();

final AttributeDefinition attributeDefinition =
MockBuilderUtils.createMockAttributeDefinitionBuilder().inputTip(ofEnglish("bar")).build();
Expand All @@ -117,9 +114,7 @@ void buildSetInputTipAction_WithDifferentValues_ShouldReturnAction() {
void buildSetInputTipAction_WithSameValues_ShouldReturnEmptyOptional() {
// Preparation
final AttributeDefinitionDraft draft =
MockBuilderUtils.createMockAttributeDefinitionDraftBuilder()
.inputTip(ofEnglish("foo"))
.build();
createMockAttributeDefinitionDraftBuilder().inputTip(ofEnglish("foo")).build();

final AttributeDefinition attributeDefinition =
MockBuilderUtils.createMockAttributeDefinitionBuilder().inputTip(ofEnglish("foo")).build();
Expand All @@ -137,9 +132,7 @@ void buildSetInputTipAction_WithSameValues_ShouldReturnEmptyOptional() {
void buildSetInputTipAction_WithSourceNullValues_ShouldReturnAction() {
// Preparation
final AttributeDefinitionDraft draft =
MockBuilderUtils.createMockAttributeDefinitionDraftBuilder()
.inputTip((LocalizedString) null)
.build();
createMockAttributeDefinitionDraftBuilder().inputTip((LocalizedString) null).build();

final AttributeDefinition attributeDefinition =
MockBuilderUtils.createMockAttributeDefinitionBuilder().inputTip(ofEnglish("foo")).build();
Expand All @@ -162,9 +155,7 @@ void buildSetInputTipAction_WithSourceNullValues_ShouldReturnAction() {
void buildSetInputTipAction_WithTargetNullValues_ShouldReturnAction() {
// Preparation
final AttributeDefinitionDraft draft =
MockBuilderUtils.createMockAttributeDefinitionDraftBuilder()
.inputTip(ofEnglish("foo"))
.build();
createMockAttributeDefinitionDraftBuilder().inputTip(ofEnglish("foo")).build();

final AttributeDefinition attributeDefinition =
MockBuilderUtils.createMockAttributeDefinitionBuilder()
Expand All @@ -189,7 +180,7 @@ void buildSetInputTipAction_WithTargetNullValues_ShouldReturnAction() {
void buildChangeIsSearchableAction_WithDifferentValues_ShouldReturnAction() {
// Preparation
final AttributeDefinitionDraft draft =
MockBuilderUtils.createMockAttributeDefinitionDraftBuilder().isSearchable(true).build();
createMockAttributeDefinitionDraftBuilder().isSearchable(true).build();

final AttributeDefinition attributeDefinition =
MockBuilderUtils.createMockAttributeDefinitionBuilder().isSearchable(false).build();
Expand All @@ -211,7 +202,7 @@ void buildChangeIsSearchableAction_WithDifferentValues_ShouldReturnAction() {
void buildChangeIsSearchableAction_WithSameValues_ShouldReturnEmptyOptional() {
// Preparation
final AttributeDefinitionDraft draft =
MockBuilderUtils.createMockAttributeDefinitionDraftBuilder().isSearchable(true).build();
createMockAttributeDefinitionDraftBuilder().isSearchable(true).build();

final AttributeDefinition attributeDefinition =
MockBuilderUtils.createMockAttributeDefinitionBuilder().isSearchable(true).build();
Expand All @@ -228,7 +219,7 @@ void buildChangeIsSearchableAction_WithSameValues_ShouldReturnEmptyOptional() {
void buildChangeIsSearchableAction_WithNullSourceAndNonDefaultTarget_ShouldBuildAction() {
// Preparation
final AttributeDefinitionDraft draft =
MockBuilderUtils.createMockAttributeDefinitionDraftBuilder().isSearchable(null).build();
createMockAttributeDefinitionDraftBuilder().isSearchable(null).build();

final AttributeDefinition attributeDefinition =
MockBuilderUtils.createMockAttributeDefinitionBuilder().isSearchable(false).build();
Expand All @@ -250,7 +241,7 @@ void buildChangeIsSearchableAction_WithNullSourceAndNonDefaultTarget_ShouldBuild
void buildChangeIsSearchableAction_WithNullSourceAndDefaultTarget_ShouldNotBuildAction() {
// Preparation
final AttributeDefinitionDraft draft =
MockBuilderUtils.createMockAttributeDefinitionDraftBuilder().isSearchable(null).build();
createMockAttributeDefinitionDraftBuilder().isSearchable(null).build();

final AttributeDefinition attributeDefinition =
MockBuilderUtils.createMockAttributeDefinitionBuilder().isSearchable(true).build();
Expand All @@ -267,9 +258,7 @@ void buildChangeIsSearchableAction_WithNullSourceAndDefaultTarget_ShouldNotBuild
void buildChangeInputHintAction_WithDifferentValues_ShouldReturnAction() {
// Preparation
final AttributeDefinitionDraft draft =
MockBuilderUtils.createMockAttributeDefinitionDraftBuilder()
.inputHint(TextInputHint.MULTI_LINE)
.build();
createMockAttributeDefinitionDraftBuilder().inputHint(TextInputHint.MULTI_LINE).build();

final AttributeDefinition attributeDefinition =
MockBuilderUtils.createMockAttributeDefinitionBuilder()
Expand All @@ -293,9 +282,7 @@ void buildChangeInputHintAction_WithDifferentValues_ShouldReturnAction() {
void buildChangeInputHintAction_WithSameValues_ShouldReturnEmptyOptional() {
// Preparation
final AttributeDefinitionDraft draft =
MockBuilderUtils.createMockAttributeDefinitionDraftBuilder()
.inputHint(TextInputHint.MULTI_LINE)
.build();
createMockAttributeDefinitionDraftBuilder().inputHint(TextInputHint.MULTI_LINE).build();

final AttributeDefinition attributeDefinition =
MockBuilderUtils.createMockAttributeDefinitionBuilder()
Expand All @@ -314,7 +301,7 @@ void buildChangeInputHintAction_WithSameValues_ShouldReturnEmptyOptional() {
void buildChangeInputHintAction_WithSourceNullValuesAndNonDefaultTargetValue_ShouldBuildAction() {
// Preparation
final AttributeDefinitionDraft draft =
MockBuilderUtils.createMockAttributeDefinitionDraftBuilder().inputHint(null).build();
createMockAttributeDefinitionDraftBuilder().inputHint(null).build();

final AttributeDefinition attributeDefinition =
MockBuilderUtils.createMockAttributeDefinitionBuilder()
Expand All @@ -338,7 +325,7 @@ void buildChangeInputHintAction_WithSourceNullValuesAndNonDefaultTargetValue_Sho
void buildChangeInputHintAction_WithSourceNullValuesAndDefaultTargetValue_ShouldNotBuildAction() {
// Preparation
final AttributeDefinitionDraft draft =
MockBuilderUtils.createMockAttributeDefinitionDraftBuilder().inputHint(null).build();
createMockAttributeDefinitionDraftBuilder().inputHint(null).build();

final AttributeDefinition attributeDefinition =
MockBuilderUtils.createMockAttributeDefinitionBuilder()
Expand All @@ -358,7 +345,7 @@ void buildChangeAttributeConstraintAction_WithDifferentValues_ShouldBuildAction(
throws UnsupportedOperationException {
// Preparation
final AttributeDefinitionDraft draft =
MockBuilderUtils.createMockAttributeDefinitionDraftBuilder()
createMockAttributeDefinitionDraftBuilder()
.attributeConstraint(AttributeConstraintEnum.NONE)
.build();

Expand All @@ -385,7 +372,7 @@ void buildChangeAttributeConstraintAction_WithSameValues_ShouldReturnEmptyOption
throws UnsupportedOperationException {
// Preparation
final AttributeDefinitionDraft draft =
MockBuilderUtils.createMockAttributeDefinitionDraftBuilder()
createMockAttributeDefinitionDraftBuilder()
.attributeConstraint(AttributeConstraintEnum.COMBINATION_UNIQUE)
.build();

Expand All @@ -408,9 +395,7 @@ void buildChangeAttributeConstraintAction_WithSameValues_ShouldReturnEmptyOption
throws UnsupportedOperationException {
// Preparation
final AttributeDefinitionDraft draft =
MockBuilderUtils.createMockAttributeDefinitionDraftBuilder()
.attributeConstraint(null)
.build();
createMockAttributeDefinitionDraftBuilder().attributeConstraint(null).build();

final AttributeDefinition attributeDefinition =
MockBuilderUtils.createMockAttributeDefinitionBuilder()
Expand Down Expand Up @@ -440,7 +425,7 @@ void buildChangeAttributeConstraintAction_WithSameValues_ShouldReturnEmptyOption
.build();

final AttributeDefinitionDraft draft =
MockBuilderUtils.createMockAttributeDefinitionDraftBuilder()
createMockAttributeDefinitionDraftBuilder()
.attributeConstraint(AttributeConstraintEnum.COMBINATION_UNIQUE)
.build();
// test
Expand Down Expand Up @@ -469,7 +454,7 @@ void buildActions_WithNewDifferentValues_ShouldReturnActions()
.build();

final AttributeDefinitionDraft newDifferent =
MockBuilderUtils.createMockAttributeDefinitionDraftBuilder()
createMockAttributeDefinitionDraftBuilder()
.label(ofEnglish("label2"))
.isRequired(true)
.attributeConstraint(AttributeConstraintEnum.NONE)
Expand Down Expand Up @@ -509,8 +494,7 @@ void buildActions_WithNewDifferentValues_ShouldReturnActions()
void buildActions_WithSameValues_ShouldReturnEmpty() throws UnsupportedOperationException {
final AttributeDefinition old = MockBuilderUtils.createMockAttributeDefinitionBuilder().build();

final AttributeDefinitionDraft newSame =
ResourceToDraftConverters.toAttributeDefinitionDraftBuilder(old).build();
final AttributeDefinitionDraft newSame = createMockAttributeDefinitionDraftBuilder().build();

final List<ProductTypeUpdateAction> result =
AttributeDefinitionUpdateActionUtils.buildActions(old, newSame);
Expand All @@ -525,9 +509,7 @@ void buildActions_WithStringAttributeTypesWithLabelChanges_ShouldBuildChangeLabe
MockBuilderUtils.createMockAttributeDefinitionBuilder().label(ofEnglish("label1")).build();

final AttributeDefinitionDraft attributeDefinitionDraft =
MockBuilderUtils.createMockAttributeDefinitionDraftBuilder()
.label(ofEnglish("label2"))
.build();
createMockAttributeDefinitionDraftBuilder().label(ofEnglish("label2")).build();

final List<ProductTypeUpdateAction> result =
AttributeDefinitionUpdateActionUtils.buildActions(
Expand Down Expand Up @@ -568,7 +550,7 @@ void buildActions_WithChangedSetOfEnumAttributeTypes_ShouldBuildEnumActions()
.build();

final AttributeDefinitionDraft newDraft =
MockBuilderUtils.createMockAttributeDefinitionDraftBuilder()
createMockAttributeDefinitionDraftBuilder()
.type(
attributeTypeBuilder ->
attributeTypeBuilder
Expand Down Expand Up @@ -653,7 +635,7 @@ void buildActions_WithChangedSetOfLocalizedEnumAttributeTypes_ShouldBuildEnumAct
.build();

final AttributeDefinitionDraft newDefinition =
MockBuilderUtils.createMockAttributeDefinitionDraftBuilder()
createMockAttributeDefinitionDraftBuilder()
.type(
attributeTypeBuilder ->
attributeTypeBuilder
Expand Down Expand Up @@ -722,7 +704,7 @@ void buildActions_WithNewPlainEnum_ShouldReturnAddEnumValueAction() {
.build();

final AttributeDefinitionDraft attributeDefinitionDraft =
MockBuilderUtils.createMockAttributeDefinitionDraftBuilder()
createMockAttributeDefinitionDraftBuilder()
.type(
attributeTypeBuilder ->
attributeTypeBuilder.enumBuilder().values(ENUM_VALUE_A, ENUM_VALUE_B))
Expand All @@ -748,7 +730,7 @@ void buildActions_WithoutOldPlainEnum_ShouldReturnRemoveEnumValueAction() {
.build();

final AttributeDefinitionDraft attributeDefinitionDraft =
MockBuilderUtils.createMockAttributeDefinitionDraftBuilder()
createMockAttributeDefinitionDraftBuilder()
.type(attributeTypeBuilder -> attributeTypeBuilder.enumBuilder().values(emptyList()))
.build();

Expand All @@ -775,7 +757,7 @@ void buildActions_WitDifferentPlainEnumValueLabel_ShouldReturnChangeEnumValueLab
AttributePlainEnumValueBuilder.of().key("a").label("label_a_different").build();

final AttributeDefinitionDraft attributeDefinitionDraft =
MockBuilderUtils.createMockAttributeDefinitionDraftBuilder()
createMockAttributeDefinitionDraftBuilder()
.type(
attributeTypeBuilder ->
attributeTypeBuilder.enumBuilder().values(enumValueDiffLabel))
Expand Down Expand Up @@ -803,7 +785,7 @@ void buildActions_WithNewLocalizedEnum_ShouldReturnAddLocalizedEnumValueAction()
.build();

final AttributeDefinitionDraft attributeDefinitionDraft =
MockBuilderUtils.createMockAttributeDefinitionDraftBuilder()
createMockAttributeDefinitionDraftBuilder()
.type(
attributeTypeBuilder ->
attributeTypeBuilder
Expand Down Expand Up @@ -833,7 +815,7 @@ void buildActions_WithoutOldLocalizedEnum_ShouldReturnRemoveLocalizedEnumValueAc
.build();

final AttributeDefinitionDraft attributeDefinitionDraft =
MockBuilderUtils.createMockAttributeDefinitionDraftBuilder()
createMockAttributeDefinitionDraftBuilder()
.type(attributeTypeBuilder -> attributeTypeBuilder.lenumBuilder().values(emptyList()))
.build();

Expand Down Expand Up @@ -863,7 +845,7 @@ void buildActions_WithoutOldLocalizedEnum_ShouldReturnRemoveLocalizedEnumValueAc
AttributeLocalizedEnumValueBuilder.of().key("a").label(ofEnglish("label_a_diff")).build();

final AttributeDefinitionDraft attributeDefinitionDraft =
MockBuilderUtils.createMockAttributeDefinitionDraftBuilder()
createMockAttributeDefinitionDraftBuilder()
.type(
attributeTypeBuilder ->
attributeTypeBuilder.lenumBuilder().values(localizedEnumValueDiffLabel))
Expand Down
Loading

0 comments on commit 16a763a

Please sign in to comment.