Skip to content

Commit 966827e

Browse files
committed
refactor: Hoist builder setup out of assertThatThrownBy lambdas
1 parent 8b29ab0 commit 966827e

1 file changed

Lines changed: 20 additions & 19 deletions

File tree

src/test/java/com/retailsvc/http/MultiSpecServerTest.java

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,14 @@ void rejectsTwoBindingsWithSameBasePath() {
9191
Map<String, RequestHandler> handlersA = handlersFor(a, req -> Response.ok(Map.of()));
9292
Map<String, RequestHandler> handlersB = handlersFor(b, req -> Response.ok(Map.of()));
9393

94-
assertThatThrownBy(
95-
() ->
96-
OpenApiServer.builder()
97-
.port(0)
98-
.addSpec(a, handlersA)
99-
.addSpec(b, handlersB)
100-
.useExternalAuthentication()
101-
.build())
94+
OpenApiServer.Builder builder =
95+
OpenApiServer.builder()
96+
.port(0)
97+
.addSpec(a, handlersA)
98+
.addSpec(b, handlersB)
99+
.useExternalAuthentication();
100+
101+
assertThatThrownBy(builder::build)
102102
.isInstanceOf(IllegalStateException.class)
103103
.hasMessageContaining("duplicate basePath")
104104
.hasMessageContaining("/api/v1");
@@ -112,8 +112,9 @@ void missingValidatorOnOneBindingFailsIndependently() {
112112

113113
Map<String, RequestHandler> handlers = handlersFor(v1, req -> Response.ok(Map.of()));
114114

115-
assertThatThrownBy(
116-
() -> OpenApiServer.builder().port(0).addSpec(v1, handlers, Map.of()).build())
115+
OpenApiServer.Builder builder = OpenApiServer.builder().port(0).addSpec(v1, handlers, Map.of());
116+
117+
assertThatThrownBy(builder::build)
117118
.isInstanceOf(IllegalStateException.class)
118119
.hasMessageContaining("no SchemeValidator registered for security scheme");
119120
}
@@ -125,15 +126,15 @@ void rejectsMixingLegacySpecMethodsWithAddSpec() {
125126
Map<String, RequestHandler> handlersA = handlersFor(a, req -> Response.ok(Map.of()));
126127
Map<String, RequestHandler> handlersB = handlersFor(b, req -> Response.ok(Map.of()));
127128

128-
assertThatThrownBy(
129-
() ->
130-
OpenApiServer.builder()
131-
.port(0)
132-
.spec(a)
133-
.handlers(handlersA)
134-
.addSpec(b, handlersB)
135-
.useExternalAuthentication()
136-
.build())
129+
OpenApiServer.Builder builder =
130+
OpenApiServer.builder()
131+
.port(0)
132+
.spec(a)
133+
.handlers(handlersA)
134+
.addSpec(b, handlersB)
135+
.useExternalAuthentication();
136+
137+
assertThatThrownBy(builder::build)
137138
.isInstanceOf(IllegalStateException.class)
138139
.hasMessageContaining("use either spec()/handler()/securityValidator() or addSpec()");
139140
}

0 commit comments

Comments
 (0)