From 4c310c57938e5c3168418acfd5dcd7ef35f4fa5c Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Thu, 10 Dec 2020 09:48:38 +0100 Subject: [PATCH] Extract assertions on the registry size into a method --- .../org/mvndaemon/mvnd/it/ExtensionsNativeIT.java | 12 +++++++++--- .../mvnd/it/NewManagedModuleNativeIT.java | 11 ++++++++--- .../java/org/mvndaemon/mvnd/it/StopStatusTest.java | 14 ++++++++++---- .../mvndaemon/mvnd/it/UpgradesInBomNativeIT.java | 14 +++++++++++--- 4 files changed, 38 insertions(+), 13 deletions(-) diff --git a/integration-tests/src/test/java/org/mvndaemon/mvnd/it/ExtensionsNativeIT.java b/integration-tests/src/test/java/org/mvndaemon/mvnd/it/ExtensionsNativeIT.java index b5477e87..b3953855 100644 --- a/integration-tests/src/test/java/org/mvndaemon/mvnd/it/ExtensionsNativeIT.java +++ b/integration-tests/src/test/java/org/mvndaemon/mvnd/it/ExtensionsNativeIT.java @@ -43,18 +43,24 @@ public class ExtensionsNativeIT { @Test void version() throws IOException, InterruptedException { registry.killAll(); - Assertions.assertThat(registry.getAll().size()).isEqualTo(0); + assertDaemonRegistrySize(0); final TestClientOutput o = new TestClientOutput(); client.execute(o, "-v").assertSuccess(); - Assertions.assertThat(registry.getAll().size()).isEqualTo(1); + assertDaemonRegistrySize(1); DaemonInfo daemon = registry.getAll().iterator().next(); assertTrue(daemon.getOptions().contains("mvnd.coreExtensions=io.takari.aether:takari-local-repository:0.11.3")); registry.awaitIdle(daemon.getUid()); client.execute(o, "-v").assertSuccess(); - Assertions.assertThat(registry.getAll().size()).isEqualTo(1); + assertDaemonRegistrySize(1); + } + + private void assertDaemonRegistrySize(int size) { + Assertions.assertThat(registry.getAll().size()) + .as("Daemon registry size should be " + size) + .isEqualTo(size); } } diff --git a/integration-tests/src/test/java/org/mvndaemon/mvnd/it/NewManagedModuleNativeIT.java b/integration-tests/src/test/java/org/mvndaemon/mvnd/it/NewManagedModuleNativeIT.java index 45f4d356..ad88442b 100644 --- a/integration-tests/src/test/java/org/mvndaemon/mvnd/it/NewManagedModuleNativeIT.java +++ b/integration-tests/src/test/java/org/mvndaemon/mvnd/it/NewManagedModuleNativeIT.java @@ -45,7 +45,7 @@ public class NewManagedModuleNativeIT { @Test void upgrade() throws IOException, InterruptedException { - Assertions.assertThat(registry.getAll().size()).isEqualTo(0); + assertDaemonRegistrySize(0); /* Build the initial state of the test project */ final Path parentDir = parameters.getTestDir().resolve("project/parent"); @@ -54,7 +54,7 @@ public class NewManagedModuleNativeIT { final TestClientOutput output = new TestClientOutput(); cl.execute(output, "clean", "install", "-e", "-B", "-ntp").assertSuccess(); } - Assertions.assertThat(registry.getAll().size()).isEqualTo(1); + assertDaemonRegistrySize(1); final DaemonInfo d = registry.getAll().get(0); /* Wait, till the instance becomes idle */ @@ -85,7 +85,12 @@ public class NewManagedModuleNativeIT { cl.execute(output, "clean", "install", "-e", "-B", "-ntp") .assertSuccess(); } - Assertions.assertThat(registry.getAll().size()).isEqualTo(1); + assertDaemonRegistrySize(1); + } + private void assertDaemonRegistrySize(int size) { + Assertions.assertThat(registry.getAll().size()) + .as("Daemon registry size should be " + size) + .isEqualTo(size); } } diff --git a/integration-tests/src/test/java/org/mvndaemon/mvnd/it/StopStatusTest.java b/integration-tests/src/test/java/org/mvndaemon/mvnd/it/StopStatusTest.java index 290de824..53721f46 100644 --- a/integration-tests/src/test/java/org/mvndaemon/mvnd/it/StopStatusTest.java +++ b/integration-tests/src/test/java/org/mvndaemon/mvnd/it/StopStatusTest.java @@ -39,11 +39,11 @@ public class StopStatusTest { void stopStatus() throws IOException, InterruptedException { /* The registry should be empty before we run anything */ - Assertions.assertThat(registry.getAll()).isEmpty(); + assertDaemonRegistrySize(0); client.execute(new TestClientOutput(), "clean").assertSuccess(); /* There should be exactly one item in the registry after the first build */ - Assertions.assertThat(registry.getAll().size()).isEqualTo(1); + assertDaemonRegistrySize(1); final DaemonInfo d = registry.getAll().get(0); { @@ -58,11 +58,11 @@ public class StopStatusTest { client.execute(new TestClientOutput(), "clean").assertSuccess(); /* There should still be exactly one item in the registry after the second build */ - Assertions.assertThat(registry.getAll().size()).isEqualTo(1); + assertDaemonRegistrySize(1); client.execute(new TestClientOutput(), "--stop").assertSuccess(); /* No items in the registry after we have killed all daemons */ - Assertions.assertThat(registry.getAll()).isEmpty(); + assertDaemonRegistrySize(0); { /* After --stop, the output of --status may not contain the UID we have seen before */ @@ -77,4 +77,10 @@ public class StopStatusTest { } } + + private void assertDaemonRegistrySize(int size) { + Assertions.assertThat(registry.getAll().size()) + .as("Daemon registry size should be " + size) + .isEqualTo(size); + } } diff --git a/integration-tests/src/test/java/org/mvndaemon/mvnd/it/UpgradesInBomNativeIT.java b/integration-tests/src/test/java/org/mvndaemon/mvnd/it/UpgradesInBomNativeIT.java index 1c64f781..dcccff20 100644 --- a/integration-tests/src/test/java/org/mvndaemon/mvnd/it/UpgradesInBomNativeIT.java +++ b/integration-tests/src/test/java/org/mvndaemon/mvnd/it/UpgradesInBomNativeIT.java @@ -44,18 +44,20 @@ public class UpgradesInBomNativeIT { @Test void upgrade() throws IOException, InterruptedException { + assertDaemonRegistrySize(0); /* Install the dependencies */ for (String artifactDir : Arrays.asList("project/hello-0.0.1", "project/hello-0.0.2-SNAPSHOT")) { final Client cl = clientFactory.newClient(parameters.cd(parameters.getTestDir().resolve(artifactDir))); final TestClientOutput output = new TestClientOutput(); cl.execute(output, "clean", "install", "-e").assertSuccess(); + assertDaemonRegistrySize(1); final DaemonInfo d = registry.getAll().get(0); /* Wait, till the instance becomes idle */ registry.awaitIdle(d.getUid()); registry.killAll(); } - Assertions.assertThat(registry.getAll().size()).isEqualTo(0); + assertDaemonRegistrySize(0); /* Build the initial state of the test project */ final Path parentDir = parameters.getTestDir().resolve("project/parent"); @@ -64,7 +66,7 @@ public class UpgradesInBomNativeIT { final TestClientOutput output = new TestClientOutput(); cl.execute(output, "clean", "install", "-e").assertSuccess(); } - Assertions.assertThat(registry.getAll().size()).isEqualTo(1); + assertDaemonRegistrySize(1); final DaemonInfo d = registry.getAll().get(0); /* Wait, till the instance becomes idle */ @@ -83,7 +85,13 @@ public class UpgradesInBomNativeIT { cl.execute(output, "clean", "install", "-e") .assertSuccess(); } - Assertions.assertThat(registry.getAll().size()).isEqualTo(1); + assertDaemonRegistrySize(1); } + + private void assertDaemonRegistrySize(int size) { + Assertions.assertThat(registry.getAll().size()) + .as("Daemon registry size should be " + size) + .isEqualTo(size); + } }