Skip to content

Commit 68286b5

Browse files
committed
fix: Hoist getClass() out of assertThatThrownBy lambdas
Sonar S5778 — each lambda should have at most one invocation that can throw a runtime exception. Both getClass() and Spec.fromClasspath were inside the lambda; the call we're actually asserting against is Spec.fromClasspath, so pull the class lookup out into a local first.
1 parent 074df3b commit 68286b5

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

src/test/java/com/retailsvc/http/spec/SpecFromClasspathTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,16 @@ void loadsYmlSpecFromClasspath() {
3434

3535
@Test
3636
void rejectsMissingResource() {
37-
assertThatThrownBy(() -> Spec.fromClasspath(getClass(), "/does-not-exist.yaml"))
37+
Class<?> loader = getClass();
38+
assertThatThrownBy(() -> Spec.fromClasspath(loader, "/does-not-exist.yaml"))
3839
.isInstanceOf(IllegalArgumentException.class)
3940
.hasMessageContaining("classpath resource not found");
4041
}
4142

4243
@Test
4344
void rejectsUnknownExtension() {
44-
assertThatThrownBy(() -> Spec.fromClasspath(getClass(), "/openapi.txt"))
45+
Class<?> loader = getClass();
46+
assertThatThrownBy(() -> Spec.fromClasspath(loader, "/openapi.txt"))
4547
.isInstanceOf(IllegalStateException.class)
4648
.hasMessageContaining("Unrecognised OpenAPI spec extension");
4749
}

0 commit comments

Comments
 (0)