Skip to content

Commit

Permalink
#134 Reorder the test case in CliRunnerTest
Browse files Browse the repository at this point in the history
  • Loading branch information
leungkinghin-ct committed Aug 12, 2020
1 parent f4f354e commit 546fdeb
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions src/test/java/com/commercetools/project/sync/CliRunnerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ void run_WithSyncAsArgumentWithNoArgs_ShouldFailAndLogError() {
}

@Test
void run_AsTaxCategoryDeltaSync_ShouldBuildSyncerAndExecuteSync() {
void run_AsProductDeltaSync_ShouldBuildSyncerAndExecuteSync() {
// preparation
final SphereClient sourceClient = mock(SphereClient.class);
when(sourceClient.getConfig()).thenReturn(SphereClientConfig.of("foo", "foo", "foo"));
Expand All @@ -214,16 +214,16 @@ void run_AsTaxCategoryDeltaSync_ShouldBuildSyncerAndExecuteSync() {
stubClientsCustomObjectService(targetClient, ZonedDateTime.now());

// test
CliRunner.of().run(new String[] {"-s", "taxCategories"}, syncerFactory);
CliRunner.of().run(new String[] {"-s", "products"}, syncerFactory);

// assertions
verify(syncerFactory, times(1)).sync("taxCategories", null, false);
verify(sourceClient, times(1)).execute(any(TaxCategoryQuery.class));
verify(syncerFactory, times(1)).sync("products", null, false);
verify(sourceClient, times(1)).execute(any(ProductQuery.class));
verify(syncerFactory, never()).syncAll(null, false);
}

@Test
void run_AsProductDeltaSync_ShouldBuildSyncerAndExecuteSync() {
void run_AsProductFullSync_ShouldBuildSyncerAndExecuteSync() {
// preparation
final SphereClient sourceClient = mock(SphereClient.class);
when(sourceClient.getConfig()).thenReturn(SphereClientConfig.of("foo", "foo", "foo"));
Expand All @@ -240,24 +240,24 @@ void run_AsProductDeltaSync_ShouldBuildSyncerAndExecuteSync() {
stubClientsCustomObjectService(targetClient, ZonedDateTime.now());

// test
CliRunner.of().run(new String[] {"-s", "products"}, syncerFactory);
CliRunner.of().run(new String[] {"-s", "products", "-f"}, syncerFactory);

// assertions
verify(syncerFactory, times(1)).sync("products", null, false);
verify(syncerFactory, times(1)).sync("products", null, true);
verify(sourceClient, times(1)).execute(any(ProductQuery.class));
verify(syncerFactory, never()).syncAll(null, false);
verify(syncerFactory, never()).syncAll(null, true);
}

@Test
void run_AsTaxCategoryFullSync_ShouldBuildSyncerAndExecuteSync() {
void run_AsTaxCategoryDeltaSync_ShouldBuildSyncerAndExecuteSync() {
// preparation
final SphereClient sourceClient = mock(SphereClient.class);
when(sourceClient.getConfig()).thenReturn(SphereClientConfig.of("foo", "foo", "foo"));

final SphereClient targetClient = mock(SphereClient.class);
when(targetClient.getConfig()).thenReturn(SphereClientConfig.of("bar", "bar", "bar"));

when(sourceClient.execute(any(TaxCategoryQuery.class)))
when(sourceClient.execute(any(ProductQuery.class)))
.thenReturn(CompletableFuture.completedFuture(PagedQueryResult.empty()));

final SyncerFactory syncerFactory =
Expand All @@ -266,24 +266,24 @@ void run_AsTaxCategoryFullSync_ShouldBuildSyncerAndExecuteSync() {
stubClientsCustomObjectService(targetClient, ZonedDateTime.now());

// test
CliRunner.of().run(new String[] {"-s", "taxCategories", "-f"}, syncerFactory);
CliRunner.of().run(new String[] {"-s", "taxCategories"}, syncerFactory);

// assertions
verify(syncerFactory, times(1)).sync("taxCategories", null, true);
verify(syncerFactory, times(1)).sync("taxCategories", null, false);
verify(sourceClient, times(1)).execute(any(TaxCategoryQuery.class));
verify(syncerFactory, never()).syncAll(null, true);
verify(syncerFactory, never()).syncAll(null, false);
}

@Test
void run_AsProductFullSync_ShouldBuildSyncerAndExecuteSync() {
void run_AsTaxCategoryFullSync_ShouldBuildSyncerAndExecuteSync() {
// preparation
final SphereClient sourceClient = mock(SphereClient.class);
when(sourceClient.getConfig()).thenReturn(SphereClientConfig.of("foo", "foo", "foo"));

final SphereClient targetClient = mock(SphereClient.class);
when(targetClient.getConfig()).thenReturn(SphereClientConfig.of("bar", "bar", "bar"));

when(sourceClient.execute(any(ProductQuery.class)))
when(sourceClient.execute(any(TaxCategoryQuery.class)))
.thenReturn(CompletableFuture.completedFuture(PagedQueryResult.empty()));

final SyncerFactory syncerFactory =
Expand All @@ -292,11 +292,11 @@ void run_AsProductFullSync_ShouldBuildSyncerAndExecuteSync() {
stubClientsCustomObjectService(targetClient, ZonedDateTime.now());

// test
CliRunner.of().run(new String[] {"-s", "products", "-f"}, syncerFactory);
CliRunner.of().run(new String[] {"-s", "taxCategories", "-f"}, syncerFactory);

// assertions
verify(syncerFactory, times(1)).sync("products", null, true);
verify(sourceClient, times(1)).execute(any(ProductQuery.class));
verify(syncerFactory, times(1)).sync("taxCategories", null, true);
verify(sourceClient, times(1)).execute(any(TaxCategoryQuery.class));
verify(syncerFactory, never()).syncAll(null, true);
}

Expand Down

0 comments on commit 546fdeb

Please sign in to comment.