Skip to content

Commit 141797b

Browse files
matchers: containExactly more details for single mismatch (#1594)
1 parent c8f0320 commit 141797b

3 files changed

Lines changed: 22 additions & 6 deletions

File tree

webtau-core/src/main/java/org/testingisdocumenting/webtau/expectation/contain/ContainExactlyMatcher.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ public boolean matches(ValuePath actualPath, Object actualIterable) {
112112
return result;
113113
}
114114

115+
@Override
116+
public Set<ValuePath> matchedPaths() {
117+
return comparator.generateEqualMatchPaths();
118+
}
119+
115120
@Override
116121
public TokenizedMessage negativeMatchingTokenizedMessage(ValuePath actualPath, Object actual) {
117122
comparator = CompareToComparator.comparator(CompareToComparator.AssertionMode.NOT_EQUAL);
@@ -246,7 +251,7 @@ private ValuePathLazyMessageList extractPotentialNotEqualMessages() {
246251
List<ValuePathLazyMessageList> messagesWithMinFailures = notEqualMessageBatches.stream()
247252
.filter(v -> v.size() == minNumberOMismatches).toList();
248253

249-
if (notEqualMessageBatches.size() != messagesWithMinFailures.size()) {
254+
if (messagesWithMinFailures.size() == 1 || notEqualMessageBatches.size() != messagesWithMinFailures.size()) {
250255
messagesWithMinFailures.forEach(notEqualCandidateMessages::addAll);
251256
}
252257
}

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

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,17 @@ public void suspectCandidateWithMissing() {
130130
{"id": "id2", "level": 4, "monthsAtCompany": 20}
131131
]:
132132
no matches found for: [{"id": "id1", "level": 8, "monthsAtCompany": 10}]
133-
unexpected elements: [{"id": "id1", "level": 5}]
133+
possible mismatches:
134+
\s
135+
[value][0].level: actual: 5 <java.lang.Integer>
136+
expected: 8 <java.lang.Integer>
137+
\s
134138
missing values:
135139
\s
136140
[value][0].monthsAtCompany: 10 (Xms)
137141
\s
138142
[
139-
{"id": "id1", "level": 5, "monthsAtCompany": **<missing>**},
143+
{"id": "id1", "level": **5**, "monthsAtCompany": **<missing>**},
140144
{"id": "id1", "level": 7, "monthsAtCompany": 12},
141145
{"id": "id2", "level": 4, "monthsAtCompany": 20}
142146
]""", () -> {
@@ -161,13 +165,19 @@ public void suspectCandidateWithExtra() {
161165
{"id": "id2", "level": 4, "monthsAtCompany": 20}
162166
]:
163167
no matches found for: [{"id": "id1", "level": 8, "monthsAtCompany": 10}]
164-
unexpected elements: [{"id": "id1", "level": 5, "monthsAtCompany": 14, "salary": "yes"}]
168+
possible mismatches:
169+
\s
170+
[value][0].level: actual: 5 <java.lang.Integer>
171+
expected: 8 <java.lang.Integer>
172+
[value][0].monthsAtCompany: actual: 14 <java.lang.Integer>
173+
expected: 10 <java.lang.Integer>
174+
\s
165175
extra values:
166176
\s
167177
[value][0].salary: "yes" (Xms)
168178
\s
169179
[
170-
{"id": "id1", "level": 5, "monthsAtCompany": 14, "salary": **"yes"**},
180+
{"id": "id1", "level": **5**, "monthsAtCompany": **14**, "salary": **"yes"**},
171181
{"id": "id1", "level": 7, "monthsAtCompany": 12},
172182
{"id": "id2", "level": 4, "monthsAtCompany": 20}
173183
]""", () -> {
@@ -210,7 +220,7 @@ public void negativeMismatch() {
210220
X failed expecting [value] to not contain exactly ["of", "world", "of", "hello", "testing"]:
211221
contains exactly ["of", "world", "of", "hello", "testing"] (Xms)
212222
\s
213-
["hello", "world", "of", "of", "testing"]""", () -> {
223+
[**"hello"**, **"world"**, **"of"**, **"of"**, **"testing"**]""", () -> {
214224
List<String> list = List.of("hello", "world", "of", "of", "testing");
215225
actual(list).shouldNot(containExactly("of", "world", "of", "hello", "testing"));
216226
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* Add: More details when [containExactly](matchers/contain-exactly) mismatching a single element

0 commit comments

Comments
 (0)