Skip to content

Commit

Permalink
More tests in VertxApplicationExtensibilityTest
Browse files Browse the repository at this point in the history
Verify the exit code is not zero when some hooks throw a runtime exception.

Signed-off-by: Thomas Segismont <[email protected]>
  • Loading branch information
tsegismont committed Jan 3, 2025
1 parent fac1e52 commit 28974b4
Showing 1 changed file with 31 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 28974b4

Please sign in to comment.