From aa93239f1a310df91982b822ff7b1f782e0f49ea Mon Sep 17 00:00:00 2001 From: salander85 Date: Tue, 24 Oct 2023 14:48:03 +0200 Subject: [PATCH] Revert "Fix spotbugs violations" This reverts commit 31da628e8809d82c6babc53841e8ea862938fc77. --- .../project/sync/util/CtpClientUtils.java | 5 ++-- .../project/sync/SyncerFactoryTest.java | 28 +++++++++++++------ .../project/sync/util/TestUtils.java | 7 +++-- 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/commercetools/project/sync/util/CtpClientUtils.java b/src/main/java/com/commercetools/project/sync/util/CtpClientUtils.java index 265a2d68..d304e6c9 100644 --- a/src/main/java/com/commercetools/project/sync/util/CtpClientUtils.java +++ b/src/main/java/com/commercetools/project/sync/util/CtpClientUtils.java @@ -43,8 +43,7 @@ private static ProjectApiRoot getCtpClient(@Nonnull final String propertiesPrefi properties = loadFromEnvVars(propertiesPrefix); } if (properties.isEmpty()) { - throw new InvalidPropertiesFormatException( - "Please provide CTP credentials for running project sync."); + throw new InvalidPropertiesFormatException("Please provide CTP credentials for running project sync."); } final String projectKey = @@ -53,7 +52,7 @@ private static ProjectApiRoot getCtpClient(@Nonnull final String propertiesPrefi extract(properties, propertiesPrefix, PROPERTIES_KEY_CLIENT_ID_SUFFIX); final String clientSecret = extract(properties, propertiesPrefix, PROPERTIES_KEY_CLIENT_SECRET_SUFFIX); - final String apiUrl = + final String apiUrl = extract( properties, propertiesPrefix, diff --git a/src/test/java/com/commercetools/project/sync/SyncerFactoryTest.java b/src/test/java/com/commercetools/project/sync/SyncerFactoryTest.java index 9244ccc6..f178d25b 100644 --- a/src/test/java/com/commercetools/project/sync/SyncerFactoryTest.java +++ b/src/test/java/com/commercetools/project/sync/SyncerFactoryTest.java @@ -21,7 +21,6 @@ import static com.commercetools.project.sync.util.TestUtils.readObjectFromResource; import static com.commercetools.project.sync.util.TestUtils.readStringFromFile; import static com.commercetools.project.sync.util.TestUtils.stubClientsCustomObjectService; -import static com.commercetools.project.sync.util.TestUtils.verifyInteractionsWithClientAfterSync; import static com.commercetools.project.sync.util.TestUtils.withTestClient; import static java.lang.String.format; import static org.assertj.core.api.Assertions.assertThat; @@ -210,7 +209,8 @@ void sync_WithUnknownOptionValue_ShouldCompleteExceptionallyWithIllegalArgumentE @SuppressWarnings("unchecked") void sync_AsProductsDeltaSync_ShouldBuildSyncerAndExecuteSync() { // preparation - stubClientsCustomObjectService(targetClient, ZonedDateTime.now()); + final ZonedDateTime currentCtpTimestamp = ZonedDateTime.now(); + stubClientsCustomObjectService(targetClient, currentCtpTimestamp); final SyncerFactory syncerFactory = SyncerFactory.of(() -> sourceClient, () -> targetClient, getMockedClock()); @@ -265,7 +265,8 @@ void sync_AsProductsDeltaSync_ShouldBuildSyncerAndExecuteSync() { @SuppressWarnings("unchecked") void sync_AsProductsFullSync_ShouldBuildSyncerAndExecuteSync() { // preparation - stubClientsCustomObjectService(targetClient, ZonedDateTime.now()); + final ZonedDateTime currentCtpTimestamp = ZonedDateTime.now(); + stubClientsCustomObjectService(targetClient, currentCtpTimestamp); final SyncerFactory syncerFactory = SyncerFactory.of(() -> sourceClient, () -> targetClient, getMockedClock()); @@ -682,9 +683,8 @@ private static void verifyLastSyncCustomObjectQuery( format("commercetools-project-sync.%s.%s", syncRunnerName, syncModuleName); if (expectedInvocations > 0) { - verify( - client.customObjects().withContainerAndKey(container, sourceProjectKey), - times(expectedInvocations)); + verify(client.customObjects(), times(expectedInvocations)) + .withContainerAndKey(container, sourceProjectKey); } else { verifyNoInteractions( client.customObjects().withContainerAndKey(anyString(), anyString()).get()); @@ -704,7 +704,8 @@ private static String createJsonStringFromPagedQueryResponse( @SuppressWarnings("unchecked") void sync_AsCategoriesDeltaSync_ShouldBuildSyncerAndExecuteSync() { // preparation - stubClientsCustomObjectService(targetClient, ZonedDateTime.now()); + final ZonedDateTime currentCtpTimestamp = ZonedDateTime.now(); + stubClientsCustomObjectService(targetClient, currentCtpTimestamp); final SyncerFactory syncerFactory = SyncerFactory.of(() -> sourceClient, () -> targetClient, getMockedClock()); @@ -756,7 +757,8 @@ void sync_AsCategoriesDeltaSync_ShouldBuildSyncerAndExecuteSync() { @SuppressWarnings("unchecked") void sync_AsProductTypesDeltaSync_ShouldBuildSyncerAndExecuteSync() { // preparation - stubClientsCustomObjectService(targetClient, ZonedDateTime.now()); + final ZonedDateTime currentCtpTimestamp = ZonedDateTime.now(); + stubClientsCustomObjectService(targetClient, currentCtpTimestamp); final SyncerFactory syncerFactory = SyncerFactory.of(() -> sourceClient, () -> targetClient, getMockedClock()); @@ -811,6 +813,7 @@ void sync_AsProductTypesDeltaSync_ShouldBuildSyncerAndExecuteSync() { @SuppressWarnings("unchecked") void sync_AsTypesDeltaSync_ShouldBuildSyncerAndExecuteSync() { // preparation + final ZonedDateTime currentCtpTimestamp = ZonedDateTime.now(); stubClientsCustomObjectService(targetClient, ZonedDateTime.now()); final SyncerFactory syncerFactory = @@ -1324,4 +1327,13 @@ void sync_AsDelta_WithSyncOptionValuesAndAll_ShouldResultIllegalArgumentExceptio .withCauseExactlyInstanceOf(CliException.class) .withMessageContaining(errorMessage); } + + private void verifyInteractionsWithClientAfterSync( + @Nonnull final ProjectApiRoot client, final int numberOfGetConfigInvocations) { + + verify(client, times(1)).close(); + // Verify config is accessed for the success message after sync: + // " example: Syncing products from CTP project with key 'x' to project with key 'y' is done"," + verify(client, times(numberOfGetConfigInvocations)).getProjectKey(); + } } diff --git a/src/test/java/com/commercetools/project/sync/util/TestUtils.java b/src/test/java/com/commercetools/project/sync/util/TestUtils.java index 76ccaa82..33be5fef 100644 --- a/src/test/java/com/commercetools/project/sync/util/TestUtils.java +++ b/src/test/java/com/commercetools/project/sync/util/TestUtils.java @@ -8,6 +8,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; import com.commercetools.api.client.ByProjectKeyCustomObjectsPost; @@ -201,7 +202,8 @@ public static void verifyInteractionsWithClientAfterSync( verify(client, times(1)).close(); // Verify config is accessed for the success message after sync: // " example: Syncing products from CTP project with key 'x' to project with key 'y' is done"," - verify(client.getProjectKey(), times(numberOfGetConfigInvocations)); + verify(client, times(numberOfGetConfigInvocations)).getProjectKey(); + verifyNoMoreInteractions(client); } public static T readObjectFromResource(final String resourcePath, final Class objectType) { @@ -248,8 +250,7 @@ public static void stubClientsCustomObjectService( public static ProjectApiRoot withTestClient( final String projectKey, - final TriFunction>> - fn) { + final TriFunction>> fn) { return ApiRootBuilder.of( request -> { final String uri = request.getUri() != null ? request.getUri().toString() : "";