File tree 2 files changed +35
-4
lines changed
src/main/java/org/wiremock/spring/internal
wiremock-spring-boot-example/src/test/java/app
2 files changed +35
-4
lines changed Original file line number Diff line number Diff line change 17
17
* @author Maciej Walkowiak
18
18
*/
19
19
public class WireMockContextCustomizerFactory implements ContextCustomizerFactory {
20
-
21
20
private static final ConfigureWireMock DEFAULT_CONFIGURE_WIREMOCK =
22
21
DefaultConfigureWireMock .class .getAnnotation (ConfigureWireMock .class );
23
22
@@ -32,8 +31,7 @@ public ContextCustomizer createContextCustomizer(
32
31
this .parseDefinitions (testClass , holder );
33
32
34
33
if (holder .isEmpty ()) {
35
- return new WireMockContextCustomizer (
36
- WireMockContextCustomizerFactory .DEFAULT_CONFIGURE_WIREMOCK );
34
+ return null ;
37
35
} else {
38
36
return new WireMockContextCustomizer (holder .asArray ());
39
37
}
@@ -56,7 +54,12 @@ void add(final ConfigureWireMock... annotations) {
56
54
void parse (final Class <?> clazz ) {
57
55
final EnableWireMock annotation = AnnotationUtils .findAnnotation (clazz , EnableWireMock .class );
58
56
if (annotation != null ) {
59
- this .add (annotation .value ());
57
+ final ConfigureWireMock [] value = annotation .value ();
58
+ if (value .length == 0 ) {
59
+ this .add (WireMockContextCustomizerFactory .DEFAULT_CONFIGURE_WIREMOCK );
60
+ } else {
61
+ this .add (value );
62
+ }
60
63
}
61
64
}
62
65
Original file line number Diff line number Diff line change
1
+ package app ;
2
+
3
+ import static com .github .tomakehurst .wiremock .client .WireMock .aResponse ;
4
+ import static com .github .tomakehurst .wiremock .client .WireMock .get ;
5
+ import static org .assertj .core .api .Assertions .assertThat ;
6
+ import static org .junit .jupiter .api .Assertions .assertThrows ;
7
+
8
+ import com .github .tomakehurst .wiremock .client .WireMock ;
9
+ import org .junit .jupiter .api .Test ;
10
+ import org .springframework .beans .factory .annotation .Autowired ;
11
+ import org .springframework .boot .test .context .SpringBootTest ;
12
+ import org .springframework .core .env .Environment ;
13
+ import wiremock .org .apache .hc .client5 .http .HttpHostConnectException ;
14
+
15
+ @ SpringBootTest
16
+ class NotEnabledTest {
17
+
18
+ @ Autowired private Environment env ;
19
+
20
+ @ Test
21
+ void shouldNotHaveWireMockConfigured () {
22
+ assertThrows (
23
+ HttpHostConnectException .class ,
24
+ () -> WireMock .stubFor (get ("/ping" ).willReturn (aResponse ().withStatus (200 ))));
25
+
26
+ assertThat (this .env .getProperty ("wiremock.server.baseUrl" )).isNull ();
27
+ }
28
+ }
You can’t perform that action at this time.
0 commit comments