Skip to content

Commit 323161a

Browse files
http: contain exactly matcher example (#1585)
1 parent d1ce656 commit 323161a

7 files changed

Lines changed: 44 additions & 2 deletions

File tree

webtau-core/src/main/java/org/testingisdocumenting/webtau/Matchers.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ public static ContainAllMatcher containingAll(Object... expected) {
217217
/**
218218
* Contain exactly matcher
219219
* <pre>
220-
* actual(collection).should(containExact(el1, el2, el3));
220+
* actual(collection).should(containExactly(el1, el2, el3));
221221
* </pre>
222222
* @param expected vararg list of values to check
223223
* @return matcher instance
@@ -229,7 +229,7 @@ public static ContainExactlyMatcher containExactly(Object... expected) {
229229
/**
230230
* Contain exactly matcher
231231
* <pre>
232-
* actual(collection).should(containExact(el1, el2, el3));
232+
* actual(collection).should(containExactly(el1, el2, el3));
233233
* </pre>
234234
* @param expected list of values to check
235235
* @return matcher instance

webtau-core/src/test/groovy/org/testingisdocumenting/webtau/expectation/contain/ContainAllMatcherTest.groovy

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ class ContainAllMatcherTest {
4040
actual(['a', 'b', 'd']).should(containAll('b', 'a'))
4141
}
4242

43+
@Test
44+
void "passes when all values are present as list"() {
45+
actual(['a', 'b', 'd']).should(containAll(['b', 'a']))
46+
}
47+
4348
@Test
4449
void "negative matcher fails only when all the values are present "() {
4550
runExpectExceptionAndValidateOutput(AssertionError, 'X failed expecting [value] to not contain all ["b", "a"]:\n' +

webtau-core/src/test/java/org/testingisdocumenting/webtau/expectation/contain/ContainExactlyMatcherJavaTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ public void match() {
3232
actual(list).should(containExactly("of", "world", "of", "hello", "testing"));
3333
}
3434

35+
@Test
36+
public void matchListAsExpected() {
37+
List<String> list = list("hello", "world", "of", "of", "testing");
38+
actual(list).should(containExactly(list("of", "world", "of", "hello", "testing")));
39+
}
40+
3541
@Test
3642
public void matchRecordsAndMaps() {
3743
// records-and-maps-example

webtau-docs/znai/HTTP/matchers.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,18 @@ Groovy: :include-groovy: org/testingisdocumenting/webtau/http/HttpGroovyTest.gro
123123
Java: :include-java: org/testingisdocumenting/webtau/http/HttpJavaTest.java {entry: "containContainingAllMatcher", bodyOnly: true, excludeRegexp: "doc.capture"}
124124
```
125125

126+
# Contain Exactly
127+
128+
Use `containExactly` when you cannot rely on order of values in a response and want to make sure that there are no extra values.
129+
:include-empty-block: {rightSide: true}
130+
131+
:include-json: listTestResponse.json {title: "response"}
132+
133+
```tabs {rightSide: true}
134+
Groovy: :include-groovy: org/testingisdocumenting/webtau/http/HttpGroovyTest.groovy {entry: "contain exactly matcher", bodyOnly: true, excludeRegexp: "doc.capture"}
135+
Java: :include-java: org/testingisdocumenting/webtau/http/HttpJavaTest.java {entry: "containExactlyMatcher", bodyOnly: true, excludeRegexp: "doc.capture"}
136+
```
137+
126138
# Date and Time
127139

128140
You can assert `actual` string against `LocalDate` and `ZonedDateTime`. String will be automatically converted
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* Doc: `http` [containExactly](HTTP/matchers#contain-exactly) matcher example

webtau-http-groovy/src/test/groovy/org/testingisdocumenting/webtau/http/HttpGroovyTest.groovy

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,6 +1038,15 @@ class HttpGroovyTest extends HttpTestBase {
10381038
http.doc.capture("end-point-list-contain-all-matchers")
10391039
}
10401040

1041+
@Test
1042+
void "contain exactly matcher"() {
1043+
http.get("/end-point-list") {
1044+
body[1].k2.should containExactly(30, 10, 20)
1045+
}
1046+
1047+
http.doc.capture("end-point-list-contain-exactly-matchers")
1048+
}
1049+
10411050
@Test
10421051
void "contain containing all matcher"() {
10431052
http.get("/prices") {

webtau-http/src/test/java/org/testingisdocumenting/webtau/http/HttpJavaTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,15 @@ public void containAllMatcher() {
289289
http.doc.capture("end-point-list-contain-all-matchers");
290290
}
291291

292+
@Test
293+
public void containExactlyMatcher() {
294+
http.get("/end-point-list", (header, body) -> {
295+
body.get(1).get("k2").should(containExactly(30, 10, 20));
296+
});
297+
298+
http.doc.capture("end-point-list-contain-exactly-matchers");
299+
}
300+
292301
@Test
293302
public void containContainingAllMatcher() {
294303
http.get("/prices", (header, body) -> {

0 commit comments

Comments
 (0)