Skip to content

Commit 0884dd5

Browse files
committed
More JUnit5 migration.
Some portions of this content were created with the assistance of Claude Code.
1 parent cf07ea0 commit 0884dd5

17 files changed

+2477
-1782
lines changed

vertx-web-client/src/test/java/io/vertx/ext/web/client/it/WebClientDatabindTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import io.vertx.core.json.JsonObject;
2121
import io.vertx.ext.web.client.HttpRequest;
2222
import io.vertx.ext.web.client.HttpResponse;
23-
import io.vertx.ext.web.client.tests.WebClientJUnit5TestBase;
23+
import io.vertx.ext.web.client.tests.WebClientTestBase;
2424
import io.vertx.ext.web.client.tests.jackson.WineAndCheese;
2525
import io.vertx.ext.web.codec.BodyCodec;
2626
import org.junit.jupiter.api.Test;
@@ -30,7 +30,7 @@
3030
/**
3131
* @author <a href="mailto:julien@julienviet.com">Julien Viet</a>
3232
*/
33-
public class WebClientDatabindTest extends WebClientJUnit5TestBase {
33+
public class WebClientDatabindTest extends WebClientTestBase {
3434

3535
@Test
3636
public void testResponseBodyAsJsonMapped() {

vertx-web-client/src/test/java/io/vertx/ext/web/client/tests/CachingWebClientTest.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
import io.vertx.core.buffer.Buffer;
77
import io.vertx.core.http.*;
88
import io.vertx.junit5.Checkpoint;
9-
import io.vertx.junit5.ReportHandlerFailures;
10-
import io.vertx.junit5.VertxExtension;
9+
import io.vertx.junit5.VertxTest;
1110
import io.vertx.junit5.VertxTestContext;
1211
import io.vertx.ext.web.client.*;
1312
import io.vertx.ext.web.client.impl.cache.CacheKey;
@@ -32,8 +31,7 @@
3231
/**
3332
* @author <a href="mailto:craigday3@gmail.com">Craig Day</a>
3433
*/
35-
@ExtendWith(VertxExtension.class)
36-
@ReportHandlerFailures
34+
@VertxTest
3735
public class CachingWebClientTest {
3836

3937
private static final int PORT = 8778;

vertx-web-client/src/test/java/io/vertx/ext/web/client/tests/HandlerExceptionTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import io.vertx.core.Vertx;
55
import io.vertx.ext.web.client.WebClient;
66
import io.vertx.junit5.VertxExtension;
7+
import io.vertx.junit5.VertxTest;
78
import io.vertx.junit5.VertxTestContext;
89
import org.junit.jupiter.api.BeforeEach;
910
import org.junit.jupiter.api.Test;
@@ -18,7 +19,7 @@
1819
/**
1920
* @author <a href="http://escoffier.me">Clement Escoffier</a>
2021
*/
21-
@ExtendWith(VertxExtension.class)
22+
@VertxTest
2223
public class HandlerExceptionTest {
2324

2425
private Vertx vertx;

vertx-web-client/src/test/java/io/vertx/ext/web/client/tests/Http3Test.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,13 @@
1010
import io.vertx.ext.web.client.HttpResponse;
1111
import io.vertx.ext.web.client.WebClient;
1212
import io.vertx.ext.web.client.WebClientConfig;
13-
import io.vertx.junit5.VertxExtension;
13+
import io.vertx.junit5.VertxTest;
1414
import io.vertx.test.tls.Cert;
1515
import org.junit.jupiter.api.Test;
16-
import org.junit.jupiter.api.extension.ExtendWith;
1716

1817
import java.util.List;
1918

20-
@ExtendWith(VertxExtension.class)
19+
@VertxTest
2120
public class Http3Test {
2221

2322
@Test

vertx-web-client/src/test/java/io/vertx/ext/web/client/tests/HttpContextTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import io.vertx.core.buffer.Buffer;
44
import io.vertx.ext.web.client.HttpRequest;
5-
import io.vertx.ext.web.client.WebClient;
65
import io.vertx.ext.web.client.impl.HttpContext;
76
import io.vertx.ext.web.client.impl.WebClientInternal;
87
import io.vertx.junit5.VertxTestContext;
@@ -13,7 +12,7 @@
1312

1413
import static org.junit.jupiter.api.Assertions.*;
1514

16-
public class HttpContextTest extends WebClientJUnit5TestBase {
15+
public class HttpContextTest extends WebClientTestBase {
1716

1817
private WebClientInternal webClientInternal;
1918

Lines changed: 224 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,224 @@
1+
package io.vertx.ext.web.client.tests;
2+
3+
import io.vertx.core.*;
4+
import io.vertx.core.buffer.Buffer;
5+
import io.vertx.core.http.*;
6+
import io.vertx.core.json.JsonObject;
7+
import io.vertx.ext.web.client.*;
8+
import io.vertx.test.core.TestUtils;
9+
import org.assertj.core.api.Assertions;
10+
import org.junit.jupiter.api.Test;
11+
12+
import java.util.*;
13+
import java.util.function.Consumer;
14+
15+
import static org.junit.jupiter.api.Assertions.*;
16+
17+
/**
18+
* @author <a href="mailto:julien@julienviet.com">Julien Viet</a>
19+
*/
20+
public class HttpResponseExpectationsTest extends WebClientTestBase {
21+
22+
@Test
23+
public void testExpectFail_2() throws Exception {
24+
testExpectation(true,
25+
value -> false,
26+
HttpServerResponse::end);
27+
}
28+
29+
@Test
30+
public void testExpectPass_2() throws Exception {
31+
testExpectation(false,
32+
value -> true,
33+
HttpServerResponse::end);
34+
}
35+
36+
@Test
37+
public void testExpectStatusFail_2() throws Exception {
38+
testExpectation(true,
39+
HttpResponseExpectation.status(200),
40+
resp -> resp.setStatusCode(201).end());
41+
}
42+
43+
@Test
44+
public void testExpectStatusPass_2() throws Exception {
45+
testExpectation(false,
46+
HttpResponseExpectation.status(200),
47+
resp -> resp.setStatusCode(200).end());
48+
}
49+
50+
@Test
51+
public void testExpectStatusRangeFail_2() throws Exception {
52+
testExpectation(true,
53+
HttpResponseExpectation.SC_SUCCESS,
54+
resp -> resp.setStatusCode(500).end());
55+
}
56+
57+
@Test
58+
public void testExpectStatusRangePass1_2() throws Exception {
59+
testExpectation(false,
60+
HttpResponseExpectation.SC_SUCCESS,
61+
resp -> resp.setStatusCode(200).end());
62+
}
63+
64+
@Test
65+
public void testExpectStatusRangePass2_2() throws Exception {
66+
testExpectation(false,
67+
HttpResponseExpectation.SC_SUCCESS,
68+
resp -> resp.setStatusCode(299).end());
69+
}
70+
71+
@Test
72+
public void testExpectContentTypeFail_2() throws Exception {
73+
testExpectation(true,
74+
HttpResponseExpectation.JSON,
75+
HttpServerResponse::end);
76+
}
77+
78+
@Test
79+
public void testExpectOneOfContentTypesFail_2() throws Exception {
80+
testExpectation(true,
81+
HttpResponseExpectation.contentType(Arrays.asList("text/plain", "text/csv")),
82+
httpServerResponse -> httpServerResponse.putHeader(HttpHeaders.CONTENT_TYPE, HttpHeaders.TEXT_HTML).end());
83+
}
84+
85+
@Test
86+
public void testExpectContentTypePass_2() throws Exception {
87+
testExpectation(false,
88+
HttpResponseExpectation.JSON,
89+
resp -> resp.putHeader("content-type", "application/JSON").end());
90+
}
91+
92+
@Test
93+
public void testExpectContentTypeWithEncodingPass_2() throws Exception {
94+
testExpectation(false,
95+
HttpResponseExpectation.JSON,
96+
resp -> resp.putHeader("content-type", "application/JSON;charset=UTF-8").end());
97+
}
98+
99+
@Test
100+
public void testExpectOneOfContentTypesPass_2() throws Exception {
101+
testExpectation(false,
102+
HttpResponseExpectation.contentType(Arrays.asList("text/plain", "text/HTML")),
103+
httpServerResponse -> httpServerResponse.putHeader(HttpHeaders.CONTENT_TYPE, HttpHeaders.TEXT_HTML).end());
104+
}
105+
106+
@Test
107+
public void testExpectCustomException_2() throws Exception {
108+
Expectation<HttpResponseHead> expectation = ((Expectation<HttpResponseHead>) value -> false)
109+
.wrappingFailure((head, err) -> new CustomException("boom"));
110+
testExpectation(true, expectation, HttpServerResponse::end, cause -> {
111+
Assertions.assertThat(cause).isInstanceOf(CustomException.class);
112+
CustomException customException = (CustomException) cause;
113+
assertEquals("boom", customException.getMessage());
114+
});
115+
}
116+
117+
@Test
118+
public void testExpectCustomExceptionWithResponseBody_2() throws Exception {
119+
UUID uuid = UUID.randomUUID();
120+
Expectation<HttpResponseHead> expectation = HttpResponseExpectation.SC_SUCCESS.wrappingFailure((head, err) -> {
121+
JsonObject body = ((HttpResponse<?>) head).bodyAsJsonObject();
122+
return new CustomException(UUID.fromString(body.getString("tag")), body.getString("message"));
123+
});
124+
testExpectation(true, expectation, httpServerResponse -> {
125+
httpServerResponse
126+
.setStatusCode(400)
127+
.end(new JsonObject().put("tag", uuid.toString()).put("message", "tilt").toBuffer());
128+
}, cause -> {
129+
Assertions.assertThat(cause).isInstanceOf(CustomException.class);
130+
CustomException customException = (CustomException) cause;
131+
assertEquals("tilt", customException.getMessage());
132+
assertEquals(uuid, customException.tag);
133+
});
134+
}
135+
136+
@Test
137+
public void testExpectCustomExceptionWithStatusCode_2() throws Exception {
138+
UUID uuid = UUID.randomUUID();
139+
int statusCode = 400;
140+
141+
Expectation<HttpResponseHead> expectation = HttpResponseExpectation.SC_SUCCESS
142+
.wrappingFailure((head, err) -> new CustomException(uuid, String.valueOf(head.statusCode())));
143+
144+
testExpectation(true, expectation, httpServerResponse -> {
145+
httpServerResponse
146+
.setStatusCode(statusCode)
147+
.end(TestUtils.randomBuffer(2048));
148+
}, cause -> {
149+
Assertions.assertThat(cause).isInstanceOf(CustomException.class);
150+
CustomException customException = (CustomException) cause;
151+
assertEquals(String.valueOf(statusCode), customException.getMessage());
152+
assertEquals(uuid, customException.tag);
153+
});
154+
}
155+
156+
@Test
157+
public void testExpectFunctionThrowsException_2() throws Exception {
158+
Expectation<HttpResponseHead> expectation = value -> {
159+
throw new IndexOutOfBoundsException("boom");
160+
};
161+
162+
testExpectation(true, expectation, HttpServerResponse::end, cause -> {
163+
Assertions.assertThat(cause).isInstanceOf(IndexOutOfBoundsException.class);
164+
});
165+
}
166+
167+
@Test
168+
public void testErrorConverterThrowsException_2() throws Exception {
169+
Expectation<HttpResponseHead> expectation = ((Expectation<HttpResponseHead>) value -> false).wrappingFailure((head, err) -> {
170+
throw new IndexOutOfBoundsException();
171+
});
172+
173+
testExpectation(true, expectation, HttpServerResponse::end, cause -> {
174+
Assertions.assertThat(cause).isInstanceOf(IndexOutOfBoundsException.class);
175+
});
176+
}
177+
178+
@Test
179+
public void testErrorConverterReturnsNull_2() throws Exception {
180+
Expectation<HttpResponseHead> expectation = ((Expectation<HttpResponseHead>) value -> false)
181+
.wrappingFailure((head, err) -> null);
182+
183+
testExpectation(true, expectation, HttpServerResponse::end, cause -> {
184+
Assertions.assertThat(cause).isNotInstanceOf(NullPointerException.class);
185+
});
186+
}
187+
188+
private void testExpectation(boolean shouldFail,
189+
Expectation<HttpResponseHead> expectation,
190+
Consumer<HttpServerResponse> bilto) throws Exception {
191+
testExpectation(shouldFail, expectation, bilto, ignore -> {});
192+
}
193+
194+
private void testExpectation(boolean shouldFail,
195+
Expectation<HttpResponseHead> expectation,
196+
Consumer<HttpServerResponse> bilto,
197+
Consumer<Throwable> failureTest) throws Exception {
198+
server.requestHandler(request -> bilto.accept(request.response()));
199+
startServer();
200+
HttpRequest<Buffer> request = webClient
201+
.get("/test");
202+
if (shouldFail) {
203+
Assertions
204+
.assertThatThrownBy(() -> request.send().expecting(expectation).await())
205+
.satisfies(failureTest);
206+
} else {
207+
request.send().expecting(expectation).await();
208+
}
209+
}
210+
211+
private static class CustomException extends Exception {
212+
213+
UUID tag;
214+
215+
CustomException(String message) {
216+
super(message);
217+
}
218+
219+
CustomException(UUID tag, String message) {
220+
super(message);
221+
this.tag = tag;
222+
}
223+
}
224+
}

vertx-web-client/src/test/java/io/vertx/ext/web/client/tests/InterceptorTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@
1010
import io.vertx.core.json.JsonArray;
1111
import io.vertx.ext.web.client.HttpRequest;
1212
import io.vertx.ext.web.client.HttpResponse;
13-
import io.vertx.ext.web.client.WebClient;
1413
import io.vertx.ext.web.client.impl.ClientPhase;
1514
import io.vertx.ext.web.client.impl.HttpContext;
16-
import io.vertx.ext.web.client.impl.WebClientInternal;
1715
import io.vertx.ext.web.codec.BodyCodec;
1816

1917
import org.assertj.core.api.Assertions;
@@ -35,7 +33,7 @@
3533
/**
3634
* @author <a href="mailto:julien@julienviet.com">Julien Viet</a>
3735
*/
38-
public class InterceptorTest extends WebClientJUnit5TestBase {
36+
public class InterceptorTest extends WebClientTestBase {
3937

4038
private void handleMutateRequest(HttpContext<?> context) {
4139
if (context.phase() == ClientPhase.PREPARE_REQUEST) {

vertx-web-client/src/test/java/io/vertx/ext/web/client/tests/JsonStreamTest.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@
77
import io.vertx.ext.web.client.WebClient;
88
import io.vertx.ext.web.client.WebClientOptions;
99
import io.vertx.ext.web.codec.BodyCodec;
10-
import io.vertx.junit5.ReportHandlerFailures;
11-
import io.vertx.junit5.VertxExtension;
10+
import io.vertx.junit5.VertxTest;
1211
import io.vertx.junit5.VertxTestContext;
1312
import org.junit.jupiter.api.BeforeEach;
1413
import org.junit.jupiter.api.Test;
15-
import org.junit.jupiter.api.extension.ExtendWith;
1614

1715
import java.util.concurrent.atomic.AtomicInteger;
1816

@@ -21,8 +19,7 @@
2119
/**
2220
* Checks the behavior of the {@link io.vertx.ext.web.codec.impl.JsonStreamBodyCodec}.
2321
*/
24-
@ExtendWith(VertxExtension.class)
25-
@ReportHandlerFailures
22+
@VertxTest
2623
public class JsonStreamTest {
2724

2825
private WebClient client;
@@ -90,5 +87,4 @@ public void testSimpleStreamUsingBlankLine(VertxTestContext testContext) {
9087
}
9188
});
9289
}
93-
9490
}

vertx-web-client/src/test/java/io/vertx/ext/web/client/tests/SessionAwareWebClientTest.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import io.vertx.ext.web.client.WebClient;
3030
import io.vertx.ext.web.client.WebClientSession;
3131
import io.vertx.junit5.Checkpoint;
32-
import io.vertx.junit5.ReportHandlerFailures;
32+
import io.vertx.junit5.VertxTest;
3333
import org.junit.jupiter.api.BeforeEach;
3434
import org.junit.jupiter.api.Test;
3535
import org.junit.jupiter.api.extension.ExtendWith;
@@ -42,7 +42,6 @@
4242
import io.vertx.core.file.AsyncFile;
4343
import io.vertx.core.file.OpenOptions;
4444
import io.vertx.core.json.JsonObject;
45-
import io.vertx.junit5.VertxExtension;
4645
import io.vertx.junit5.VertxTestContext;
4746
import io.vertx.ext.web.client.impl.CookieStoreImpl;
4847
import io.vertx.ext.web.client.spi.CookieStore;
@@ -51,8 +50,7 @@
5150
/**
5251
* @author <a href="mailto:tommaso.nolli@gmail.com">Tommaso Nolli</a>
5352
*/
54-
@ExtendWith(VertxExtension.class)
55-
@ReportHandlerFailures
53+
@VertxTest
5654
public class SessionAwareWebClientTest {
5755
private static final int PORT = 8080;
5856

0 commit comments

Comments
 (0)