Testcontainers
Java module
Duplicate configuration
This inspection reports duplicate and redundant configuration in WireMockContainer
builder call chains.
withMapping()
: When a mapping name is specified in multiple.withMapping()
calls, the value for that mapping name would be overridden.withFile()
,withFileFromResource()
: When a name associated with response body files is specified in multiple.withFile()
orwithFileFromResource()
calls, the value for that file would be overridden.
Quick fixes are also available to remove duplicate calls for the selected name and file. It keeps the call that the user invokes the quick fix on.
This is similar to what is done in case of stubbing and requests matching.
withMapping
//From:
@Container
WireMockContainer wiremockServer = new WireMockContainer("wiremock/wiremock:2.35.0")
.withMapping("redirection mapping", """
{
"request": {
"method": "GET",
"urlPath": "/some/url"
},
"response": {
"status": 301
}
}
""")
.withMapping("redirection mapping", getClass(), "redirection_mapping.json"); //<- selected to be kept
//to:
@Container
WireMockContainer wiremockServer = new WireMockContainer("wiremock/wiremock:2.35.0")
.withMapping("redirection mapping", getClass(), "redirection_mapping.json");
withFile / withFileFromResource
//From:
@Container
WireMockContainer wiremockServer = new WireMockContainer("wiremock/wiremock:2.35.0")
.withFile("success mapping", file) //<- selected to be kept
.withFileFromResource("file", "<resource>")
.withFileFromResource("success mapping", getClass(), "success_mapping.json");
//to:
@Container
WireMockContainer wiremockServer = new WireMockContainer("wiremock/wiremock:2.35.0")
.withFile("success mapping", file)
.withFileFromResource("file", "<resource>");
Code completion for CLI arguments
WireMockContainer.withCliArg()
accepts WireMock CLI arguments, so to make the discovery of the available and supported arguments easier, code completion provides these options. This feature uses WireMock’s CommandLineOptions class the single source of truth, coupled with occasional extra details from the WireMock Standalone documentation.
The plugin tries to parse a valid version number from the WireMockContainer(String)
constructor, considering only the image name wiremock/wiremock
at the moment:
- if it can, completion will show only the CLI options that are available in that version,
- otherwise, all possible options are listed regardless of version.
Deprecated items will appear with a strikethrough style.
Code completion and reference for WireMock Extension class names
Extension implementations in WireMock must implement the com.github.tomakehurst.wiremock.extension.Extension
interface. Then, when configuring WireMockContainer
with said extensions, these are the ones accepted by the WireMockContainer#withExtension()
method.
To simplify code completion, only classes that satisfy the following criteria are shown when completing the class name argument in withExtension(String, String)
:
- implement
com.github.tomakehurst.wiremock.extension.Extension
- not interfaces and not abstract classes
- not anonymous classes
In addition to this, the fully qualified name resolves to the referenced Java class, and can be navigated to via Ctrl+click and similar actions.