From 28974b48408daccfb418d2bb6cf8771ce52dbc88 Mon Sep 17 00:00:00 2001 From: Thomas Segismont Date: Fri, 3 Jan 2025 16:18:24 +0100 Subject: [PATCH] More tests in VertxApplicationExtensibilityTest Verify the exit code is not zero when some hooks throw a runtime exception. Signed-off-by: Thomas Segismont --- .../VertxApplicationExtensibilityTest.java | 34 +++++++++++++++++-- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/application/src/test/java/io/vertx/launcher/application/VertxApplicationExtensibilityTest.java b/application/src/test/java/io/vertx/launcher/application/VertxApplicationExtensibilityTest.java index 98cb2aa..ae8ce69 100644 --- a/application/src/test/java/io/vertx/launcher/application/VertxApplicationExtensibilityTest.java +++ b/application/src/test/java/io/vertx/launcher/application/VertxApplicationExtensibilityTest.java @@ -27,8 +27,7 @@ import static io.vertx.launcher.application.VertxApplicationTest.assertServerStarted; import static io.vertx.launcher.application.VertxApplicationTest.getContent; import static java.lang.Boolean.TRUE; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.*; public class VertxApplicationExtensibilityTest { @@ -111,7 +110,8 @@ public void beforeStartingVertx(HookContext context) { @Override public VertxBuilder createVertxBuilder(VertxOptions options) { - return super.createVertxBuilder(options).withMetrics(o -> new VertxMetrics() {}); + return super.createVertxBuilder(options).withMetrics(o -> new VertxMetrics() { + }); } }; TestVertxApplication app = new TestVertxApplication(new String[0], hooks); @@ -141,6 +141,34 @@ public VertxBuilder createVertxBuilder(VertxOptions options) { assertSame(clusterManager, ((VertxInternal) hooks.vertx).getClusterManager()); } + @Test + public void testExceptionInBeforeStartingVertx() throws Exception { + hooks = new TestHooks() { + @Override + public void beforeStartingVertx(HookContext context) { + super.beforeStartingVertx(context); + throw new RuntimeException("boom"); + } + }; + TestVertxApplication app = new TestVertxApplication(new String[]{}, hooks); + int exitCode = app.launch(); + assertNotEquals(0, exitCode); + } + + @Test + public void testExceptionInAfterVertxStarted() throws Exception { + hooks = new TestHooks() { + @Override + public void afterVertxStarted(HookContext context) { + super.afterVertxStarted(context); + throw new RuntimeException("boom"); + } + }; + TestVertxApplication app = new TestVertxApplication(new String[]{}, hooks); + int exitCode = app.launch(); + assertNotEquals(0, exitCode); + } + private static class TestVertxApplication extends VertxApplication { public TestVertxApplication(String[] args, VertxApplicationHooks hooks) {