Skip to content

Extension is no longer configuring WireMock for default instance due to @EnableWireMock being repeatable #131

@kzander91

Description

@kzander91

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:

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:
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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions