Skip to content

Commit 48e57c8

Browse files
committed
More examples
Includes Before/After/Nested
1 parent db98f9c commit 48e57c8

File tree

1 file changed

+45
-3
lines changed

1 file changed

+45
-3
lines changed

junit5-examples/src/test/java/hello/SampleVerticleTest.java

+45-3
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,14 @@
1717
package hello;
1818

1919
import io.vertx.core.Vertx;
20+
import io.vertx.core.VertxOptions;
2021
import io.vertx.ext.web.client.WebClient;
2122
import io.vertx.ext.web.codec.BodyCodec;
2223
import io.vertx.junit5.Checkpoint;
2324
import io.vertx.junit5.VertxExtension;
2425
import io.vertx.junit5.VertxTestContext;
2526
import org.assertj.core.api.Assertions;
26-
import org.junit.jupiter.api.DisplayName;
27-
import org.junit.jupiter.api.RepeatedTest;
28-
import org.junit.jupiter.api.Test;
27+
import org.junit.jupiter.api.*;
2928
import org.junit.jupiter.api.extension.ExtendWith;
3029

3130
import java.util.concurrent.atomic.AtomicInteger;
@@ -80,4 +79,47 @@ void useSampleVerticle(Vertx vertx, VertxTestContext testContext) {
8079
}
8180
}));
8281
}
82+
83+
@DisplayName("➡️ A nested test with customized lifecycle")
84+
@Nested
85+
class CustomLifecycleTest {
86+
87+
Vertx vertx;
88+
89+
@BeforeEach
90+
void prepare() {
91+
vertx = Vertx.vertx(new VertxOptions()
92+
.setMaxEventLoopExecuteTime(1000)
93+
.setPreferNativeTransport(true)
94+
.setFileResolverCachingEnabled(true));
95+
}
96+
97+
@Test
98+
@DisplayName("⬆️ Deploy SampleVerticle")
99+
void deploySampleVerticle(VertxTestContext testContext) {
100+
vertx.deployVerticle(new SampleVerticle(), testContext.succeeding(id -> testContext.completeNow()));
101+
}
102+
103+
@Test
104+
@DisplayName("🛂 Make a HTTP client request to SampleVerticle")
105+
void httpRequest(VertxTestContext testContext) {
106+
WebClient webClient = WebClient.create(vertx);
107+
vertx.deployVerticle(new SampleVerticle(), testContext.succeeding(id -> {
108+
webClient.get(11981, "localhost", "/yo")
109+
.as(BodyCodec.string())
110+
.send(testContext.succeeding(resp -> {
111+
testContext.verify(() -> {
112+
assertThat(resp.statusCode()).isEqualTo(200);
113+
assertThat(resp.body()).contains("Yo!");
114+
testContext.completeNow();
115+
});
116+
}));
117+
}));
118+
}
119+
120+
@AfterEach
121+
void cleanup() {
122+
vertx.close();
123+
}
124+
}
83125
}

0 commit comments

Comments
 (0)