Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public static ContainAllMatcher containingAll(Object... expected) {
/**
* Contain exactly matcher
* <pre>
* actual(collection).should(containExact(el1, el2, el3));
* actual(collection).should(containExactly(el1, el2, el3));
* </pre>
* @param expected vararg list of values to check
* @return matcher instance
Expand All @@ -229,7 +229,7 @@ public static ContainExactlyMatcher containExactly(Object... expected) {
/**
* Contain exactly matcher
* <pre>
* actual(collection).should(containExact(el1, el2, el3));
* actual(collection).should(containExactly(el1, el2, el3));
* </pre>
* @param expected list of values to check
* @return matcher instance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ class ContainAllMatcherTest {
actual(['a', 'b', 'd']).should(containAll('b', 'a'))
}

@Test
void "passes when all values are present as list"() {
actual(['a', 'b', 'd']).should(containAll(['b', 'a']))
}

@Test
void "negative matcher fails only when all the values are present "() {
runExpectExceptionAndValidateOutput(AssertionError, 'X failed expecting [value] to not contain all ["b", "a"]:\n' +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ public void match() {
actual(list).should(containExactly("of", "world", "of", "hello", "testing"));
}

@Test
public void matchListAsExpected() {
List<String> list = list("hello", "world", "of", "of", "testing");
actual(list).should(containExactly(list("of", "world", "of", "hello", "testing")));
}

@Test
public void matchRecordsAndMaps() {
// records-and-maps-example
Expand Down
12 changes: 12 additions & 0 deletions webtau-docs/znai/HTTP/matchers.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,18 @@ Groovy: :include-groovy: org/testingisdocumenting/webtau/http/HttpGroovyTest.gro
Java: :include-java: org/testingisdocumenting/webtau/http/HttpJavaTest.java {entry: "containContainingAllMatcher", bodyOnly: true, excludeRegexp: "doc.capture"}
```

# Contain Exactly

Use `containExactly` when you cannot rely on order of values in a response and want to make sure that there are no extra values.
:include-empty-block: {rightSide: true}

:include-json: listTestResponse.json {title: "response"}

```tabs {rightSide: true}
Groovy: :include-groovy: org/testingisdocumenting/webtau/http/HttpGroovyTest.groovy {entry: "contain exactly matcher", bodyOnly: true, excludeRegexp: "doc.capture"}
Java: :include-java: org/testingisdocumenting/webtau/http/HttpJavaTest.java {entry: "containExactlyMatcher", bodyOnly: true, excludeRegexp: "doc.capture"}
```

# Date and Time

You can assert `actual` string against `LocalDate` and `ZonedDateTime`. String will be automatically converted
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Doc: `http` [containExactly](HTTP/matchers#contain-exactly) matcher example
Original file line number Diff line number Diff line change
Expand Up @@ -1038,6 +1038,15 @@ class HttpGroovyTest extends HttpTestBase {
http.doc.capture("end-point-list-contain-all-matchers")
}

@Test
void "contain exactly matcher"() {
http.get("/end-point-list") {
body[1].k2.should containExactly(30, 10, 20)
}

http.doc.capture("end-point-list-contain-exactly-matchers")
}

@Test
void "contain containing all matcher"() {
http.get("/prices") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,15 @@ public void containAllMatcher() {
http.doc.capture("end-point-list-contain-all-matchers");
}

@Test
public void containExactlyMatcher() {
http.get("/end-point-list", (header, body) -> {
body.get(1).get("k2").should(containExactly(30, 10, 20));
});

http.doc.capture("end-point-list-contain-exactly-matchers");
}

@Test
public void containContainingAllMatcher() {
http.get("/prices", (header, body) -> {
Expand Down