|
5 | 5 | import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; |
6 | 6 |
|
7 | 7 | import com.retailsvc.http.spec.Spec; |
| 8 | +import com.sun.net.httpserver.HttpHandler; |
8 | 9 | import java.util.List; |
9 | 10 | import java.util.Map; |
10 | 11 | import org.junit.jupiter.api.Test; |
@@ -32,39 +33,41 @@ void buildsWithRequiredFieldsOnly() { |
32 | 33 |
|
33 | 34 | @Test |
34 | 35 | void rejectsDuplicateExtraPathOnSecondAddHandler() { |
| 36 | + HttpHandler duplicate = Handlers.aliveHandler(); |
35 | 37 | OpenApiServer.Builder b = |
36 | 38 | OpenApiServer.builder() |
37 | 39 | .spec(spec) |
38 | 40 | .jsonMapper(jsonMapper) |
39 | 41 | .handlers(emptyMap()) |
40 | | - .addHandler("/alive", Handlers.aliveHandler()); |
| 42 | + .addHandler("/alive", duplicate); |
41 | 43 |
|
42 | | - assertThatThrownBy(() -> b.addHandler("/alive", Handlers.aliveHandler())) |
| 44 | + assertThatThrownBy(() -> b.addHandler("/alive", duplicate)) |
43 | 45 | .isInstanceOf(IllegalStateException.class) |
44 | 46 | .hasMessageContaining("/alive"); |
45 | 47 | } |
46 | 48 |
|
47 | 49 | @Test |
48 | 50 | void rejectsExtraPathEqualToSpecBasePathAtBuildTime() { |
49 | 51 | // testSpec() uses "/api" as the basePath (servers[0].url = http://localhost:8080/api). |
50 | | - assertThatThrownBy( |
51 | | - () -> |
52 | | - OpenApiServer.builder() |
53 | | - .spec(spec) |
54 | | - .jsonMapper(jsonMapper) |
55 | | - .handlers(emptyMap()) |
56 | | - .addHandler("/api", Handlers.aliveHandler()) |
57 | | - .port(0) |
58 | | - .build()) |
| 52 | + OpenApiServer.Builder b = |
| 53 | + OpenApiServer.builder() |
| 54 | + .spec(spec) |
| 55 | + .jsonMapper(jsonMapper) |
| 56 | + .handlers(emptyMap()) |
| 57 | + .addHandler("/api", Handlers.aliveHandler()) |
| 58 | + .port(0); |
| 59 | + |
| 60 | + assertThatThrownBy(b::build) |
59 | 61 | .isInstanceOf(IllegalStateException.class) |
60 | 62 | .hasMessageContaining("/api"); |
61 | 63 | } |
62 | 64 |
|
63 | 65 | @Test |
64 | 66 | void rejectsNullSpec() { |
65 | | - assertThatThrownBy( |
66 | | - () -> |
67 | | - OpenApiServer.builder().jsonMapper(jsonMapper).handlers(emptyMap()).port(0).build()) |
| 67 | + OpenApiServer.Builder b = |
| 68 | + OpenApiServer.builder().jsonMapper(jsonMapper).handlers(emptyMap()).port(0); |
| 69 | + |
| 70 | + assertThatThrownBy(b::build) |
68 | 71 | .isInstanceOf(NullPointerException.class) |
69 | 72 | .hasMessageContaining("Spec"); |
70 | 73 | } |
|
0 commit comments