Skip to content

Commit aea7556

Browse files
matchers: anyOf renders bean details when compared against maps (#1442)
1 parent 4a25634 commit aea7556

File tree

11 files changed

+48
-41
lines changed

11 files changed

+48
-41
lines changed

webtau-cli/src/main/java/org/testingisdocumenting/webtau/cli/CliCommand.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,11 @@
1818

1919
import org.testingisdocumenting.webtau.cli.expectation.CliValidationExitCodeOutputHandler;
2020
import org.testingisdocumenting.webtau.cli.expectation.CliValidationOutputOnlyHandler;
21-
import org.testingisdocumenting.webtau.data.ResourceNameAware;
2221

2322
import java.nio.file.Path;
2423
import java.util.function.Supplier;
2524

26-
public class CliCommand implements ResourceNameAware {
25+
public class CliCommand {
2726
private Supplier<Object> commandBaseSupplier;
2827
private String commandBase;
2928

@@ -147,9 +146,4 @@ private synchronized String fullCommand(String args) {
147146
commandBase:
148147
commandBase + " " + args;
149148
}
150-
151-
@Override
152-
public String resourceName() {
153-
return commandBase;
154-
}
155149
}

webtau-core/src/main/java/org/testingisdocumenting/webtau/data/ResourceNameAware.java

Lines changed: 0 additions & 21 deletions
This file was deleted.

webtau-core/src/main/java/org/testingisdocumenting/webtau/expectation/equality/AnyOfMatcher.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.testingisdocumenting.webtau.expectation.equality;
1818

1919
import org.testingisdocumenting.webtau.data.ValuePath;
20+
import org.testingisdocumenting.webtau.data.converters.ValueConverter;
2021
import org.testingisdocumenting.webtau.expectation.ExpectedValuesAware;
2122
import org.testingisdocumenting.webtau.expectation.ValueMatcher;
2223
import org.testingisdocumenting.webtau.reporter.TokenizedMessage;
@@ -34,13 +35,19 @@ public AnyOfMatcher(Collection<Object> expected) {
3435
this.expectedList = expected;
3536
}
3637

38+
@Override
39+
public ValueConverter valueConverter() {
40+
return comparator.createValueConverter();
41+
}
42+
3743
@Override
3844
public Stream<Object> expectedValues() {
3945
return expectedList.stream();
4046
}
4147

4248
@Override
4349
public TokenizedMessage matchingTokenizedMessage(ValuePath actualPath, Object actual) {
50+
comparator = CompareToComparator.comparator();
4451
return tokenizedMessage().matcher("to match any of").valueFirstLinesOnly(expectedList);
4552
}
4653

@@ -58,7 +65,7 @@ public TokenizedMessage mismatchedTokenizedMessage(ValuePath actualPath, Object
5865
public boolean matches(ValuePath actualPath, Object actual) {
5966
boolean result = false;
6067

61-
comparator = CompareToComparator.comparator();
68+
comparator.resetReportData();
6269
for (Object expected : expectedList) {
6370
result = result || comparator.compareIsEqual(actualPath, actual, expected);
6471
}
@@ -68,6 +75,7 @@ public boolean matches(ValuePath actualPath, Object actual) {
6875

6976
@Override
7077
public TokenizedMessage negativeMatchingTokenizedMessage(ValuePath actualPath, Object actual) {
78+
comparator = CompareToComparator.comparator();
7179
return tokenizedMessage().matcher("to not match any of").valueFirstLinesOnly(expectedList);
7280
}
7381

@@ -85,7 +93,7 @@ public TokenizedMessage negativeMismatchedTokenizedMessage(ValuePath actualPath,
8593
public boolean negativeMatches(ValuePath actualPath, Object actual) {
8694
boolean result = true;
8795

88-
comparator = CompareToComparator.comparator();
96+
comparator.resetReportData();
8997
for (Object expected : expectedList) {
9098
result = result && comparator.compareIsNotEqual(actualPath, actual, expected);
9199
}

webtau-core/src/test/groovy/org/testingisdocumenting/webtau/data/converters/ObjectPropertiesTest.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
package org.testingisdocumenting.webtau.data.converters
1818

1919
import org.junit.Test
20-
import org.testingisdocumenting.webtau.data.Account
21-
import org.testingisdocumenting.webtau.data.GameConfig
20+
import org.example.domain.Account
21+
import org.example.domain.GameConfig
2222
import org.testingisdocumenting.webtau.expectation.equality.handlers.SmallBean
2323

2424
import java.nio.file.Paths

webtau-core/src/test/groovy/org/testingisdocumenting/webtau/expectation/equality/AnyOfMatcherTest.groovy

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717
package org.testingisdocumenting.webtau.expectation.equality
1818

1919
import org.junit.Test
20-
import org.testingisdocumenting.webtau.data.ValuePath
20+
import org.example.domain.Account
21+
22+
import static org.testingisdocumenting.webtau.WebTauCore.*
23+
import org.testingisdocumenting.webtau.data.DummyLiveValue
2124

22-
import static org.testingisdocumenting.webtau.Matchers.*
2325
import static org.testingisdocumenting.webtau.testutils.TestConsoleOutput.*
2426

2527
class AnyOfMatcherTest {
26-
private final ValuePath actualPath = new ValuePath("value")
27-
2828
@Test
2929
void "positive match"() {
3030
runAndValidateOutput('. [value] matches any of [3, 10, <greater than 8>, 10] (Xms)') {
@@ -60,4 +60,29 @@ class AnyOfMatcherTest {
6060
actual(10).shouldNotBe(anyOf(3, 11, lessThan(12)))
6161
}
6262
}
63+
64+
@Test
65+
void "wait on live value"() {
66+
def liveValue = new DummyLiveValue([1, 10, 100, 1000, 2000])
67+
actual(liveValue).waitToBe(anyOf(100, 1000))
68+
}
69+
70+
@Test
71+
void "renders converted java bean in case of mismatch"() {
72+
def bean = new Account("id1", "name1", 100)
73+
74+
runExpectExceptionAndValidateOutput(AssertionError, 'X failed expecting [value] to match any of [{"id": "id1", "name": "name2"}, {"id": "id1", "name": "name2"}]:\n' +
75+
' [value].name: actual: "name1" <java.lang.String>\n' +
76+
' expected: "name2" <java.lang.String>\n' +
77+
' ^\n' +
78+
' [value].name: actual: "name1" <java.lang.String>\n' +
79+
' expected: "name2" <java.lang.String>\n' +
80+
' ^ (Xms)\n' +
81+
' \n' +
82+
' {"id": "id1", "money": org.example.domain.Money@<ref>, "name": "name1"}') {
83+
actual(bean).shouldBe(anyOf(
84+
map("id", "id1", "name", "name2"),
85+
map("id", "id1", "name", "name2")))
86+
}
87+
}
6388
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.testingisdocumenting.webtau.data;
17+
package org.example.domain;
1818

1919
public class Account {
2020
private final String id;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.testingisdocumenting.webtau.data;
17+
package org.example.domain;
1818

1919
public class GameAchievement {
2020
private final String id;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.testingisdocumenting.webtau.data;
17+
package org.example.domain;
1818

1919
import java.nio.file.Path;
2020
import java.util.ArrayList;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.testingisdocumenting.webtau.data;
17+
package org.example.domain;
1818

1919
public class Money {
2020
private final long dollars;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* Fix: `anyOf` [Matcher](matchers/introduction) now properly renders java bean details when compared against multiple maps

0 commit comments

Comments
 (0)