-
Notifications
You must be signed in to change notification settings - Fork 22
Description
Proposal
I'm not sure if the new or the old behaviour is/was correct/intended, but this change broke our tests:
With #123, when both a test class and its parent declare @EnableWireMock(@ConfigureWireMock(...))
, no WireMock instance is configured as the default anymore.
Before that change, the instance configured on the test class itself was used as the default.
One could argue that in such a scenario, there shouldn't be a default because multiple instances exist, however it is a breaking change nonetheless.
Reproduction steps
@EnableWireMock(@ConfigureWireMock(name = "parent-instance"))
class Parent {}
@EnableWireMock(@ConfigureWireMock(name = "child-instance"))
class Child extends Parent {
@Test
void foo() {
stubFor(...); // <-- Fails with 3.10.6, because no default instance exists. With 3.10.0, `child-instance` was configured as the default
}
}
References
With #123, @EnableWireMock
became repeatable and WireMockSpringJunitExtension.getEnableWireMockAnnotations()
was changed such that it now returns all annotations from the test class hierarchy, when before it found only the first/closest one:
wiremock-spring-boot/src/main/java/org/wiremock/spring/internal/WireMockSpringJunitExtension.java
Lines 92 to 100 in 270e49a
private List<EnableWireMock> getEnableWireMockAnnotations(List<Object> instances) { | |
return instances.stream() | |
.flatMap( | |
it -> | |
AnnotationSupport.findRepeatableAnnotations(it.getClass(), EnableWireMock.class) | |
.stream()) | |
.filter(it -> it != null) | |
.toList(); | |
} |
Compare this with 3.10.0:
wiremock-spring-boot/src/main/java/org/wiremock/spring/internal/WireMockSpringJunitExtension.java
Lines 93 to 98 in 3c91092
private List<EnableWireMock> getEnableWireMockAnnotations(List<Object> instances) { | |
return instances.stream() | |
.map(it -> AnnotationUtils.findAnnotation(it.getClass(), EnableWireMock.class)) | |
.filter(it -> it != null) | |
.toList(); | |
} |
As a result, WireMockSpringJunitExtension.configureWireMockForDefaultInstance()
is now finding multiple configurations and skips configuring one as the default.