Skip to content

Commit cf50c85

Browse files
authored
Merge pull request #399 from wiremock/immutable-classes-migration
document v4 immutable data class changes.
2 parents 59edfa2 + e875ce0 commit cf50c85

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/content/docs/docs/v4.mdx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,29 @@ The following transitive dependencies have been replaced and may require changes
5454
* org.eclipse.jetty.http2:http2-common -> org.eclipse.jetty.http2:jetty-http2-common
5555
* org.eclipse.jetty.http2:http2-hpack -> org.eclipse.jetty.http2:jetty-http2-hpack
5656
* org.eclipse.jetty.http2:http2-server -> org.eclipse.jetty.http2:jetty-http2-server
57+
58+
### Immutable data classes
59+
60+
Several of the core data classes in WireMock are now immutable, and can only be transformed via their respective builder classes.
61+
This decision was made to reduce the likelihood of bugs due to reliance on in-place mutation of objects,
62+
especially objects within in-memory stores, and to increase code clarity.
63+
64+
#### Usage
65+
66+
Previously, a `StubMapping` instance's request pattern could be mutated via the `setRequest` method on the `StubMapping` class, like so:
67+
``` java
68+
stubMapping.setRequest(newRequestPattern);
69+
```
70+
Now, the `transform` method on the `StubMapping` class can be used to copy the existing instance and return a new instance with an updated request pattern, like so:
71+
``` java
72+
StubMapping newStubMapping =
73+
oldStubMapping.transform(builder -> builder.setRequest(newRequestPattern));
74+
```
75+
76+
The following data classes have all been updated to be immutable and use the builder pattern:
77+
* `com.github.tomakehurst.wiremock.stubbing.StubMapping`
78+
* `com.github.tomakehurst.wiremock.common.Metadata`
79+
* `com.github.tomakehurst.wiremock.extension.Parameters`
80+
* `com.github.tomakehurst.wiremock.global.GlobalSettings`
81+
* `com.github.tomakehurst.wiremock.http.ResponseDefinition`
82+
* `com.github.tomakehurst.wiremock.matching.RequestPattern`

0 commit comments

Comments
 (0)