Class WireMockJavaDslScanner
stubFor(get(urlEqualTo("/orders/1")).willReturn(aResponse().withStatus(200)));
Unlike WireMockStubScanner, which reads static *.json stub mapping files,
this scanner finds stubs registered programmatically at test run time - evidence
WireMockStubScanner cannot "see" since no mapping file for it exists on disk. Matches
by simple method name only, the same way ControllerScanner and
RestDocsScanner match by simple annotation/method name, so this scanner needs neither
WireMock nor Spring on its own classpath.
Recognises any call to a method named stubFor(...) with exactly one argument -
regardless of its scope, so both the statically-imported stubFor(...) and an instance
call like wireMockServer.stubFor(...) are matched - whose argument is a fluent chain
built from one of WireMock's verb builders (get/post/put/
delete/patch/head/options/trace) applied to one of its
URL matchers (urlEqualTo/urlPathEqualTo/urlMatching/
urlPathMatching/urlPathTemplate) with a literal string argument. Any other
builder calls chained in between - .willReturn(...), .atPriority(...),
.inScenario(...), etc. - are walked through transparently, since they are chained
directly onto the verb builder call.
A stubFor(...) call whose argument isn't shaped this way - e.g. the mapping builder
was assembled in a local variable first, the URL matcher argument is not a string literal, or
the matcher is a dynamic one like anyUrl() - is silently skipped, the same way
WireMockStubScanner skips a stub file missing a recognised method/URL field.
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
WireMockJavaDslScanner
public WireMockJavaDslScanner()Creates a newWireMockJavaDslScanner.
-
-
Method Details
-
scan
public List<com.arc_e_tect.gradle.detector.core.model.Endpoint> scan(File rootDir) throws IOException Scans every.javafile underrootDir, recursively, forstubFor(...)calls shaped as described in the class documentation.- Parameters:
rootDir- directory to search; may not exist, in which case an empty list is returned- Returns:
- one
Endpointper recognisedstubFor(...)call found - Throws:
IOException- if a source file cannot be read
-