Skip to content

Commit

Permalink
Revert "Fix spotbugs violations"
Browse files Browse the repository at this point in the history
This reverts commit 31da628.
  • Loading branch information
salander85 committed Oct 24, 2023
1 parent 69dabaf commit aa93239
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand All @@ -704,7 +704,8 @@ private static <T> 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());
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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> T readObjectFromResource(final String resourcePath, final Class<T> objectType) {
Expand Down Expand Up @@ -248,8 +250,7 @@ public static void stubClientsCustomObjectService(

public static ProjectApiRoot withTestClient(
final String projectKey,
final TriFunction<String, ApiHttpMethod, String, CompletableFuture<ApiHttpResponse<byte[]>>>
fn) {
final TriFunction<String, ApiHttpMethod, String, CompletableFuture<ApiHttpResponse<byte[]>>> fn) {
return ApiRootBuilder.of(
request -> {
final String uri = request.getUri() != null ? request.getUri().toString() : "";
Expand Down

0 comments on commit aa93239

Please sign in to comment.