diff --git a/src/main/java/no/rune/record/RecordMatcherGenerator.java b/src/main/java/no/rune/record/RecordMatcherGenerator.java index 27197a3..bfa5862 100644 --- a/src/main/java/no/rune/record/RecordMatcherGenerator.java +++ b/src/main/java/no/rune/record/RecordMatcherGenerator.java @@ -123,7 +123,7 @@ public String generateFromRecord(Class record, Package target, .map(component -> CodeBlock.builder().addNamed( """ if (!$matcherReference:N.matches(element.$componentName:N())) { - mismatchDescription.appendText("$componentName:N "); + mismatchDescription.appendText(" $componentName:N "); $matcherReference:N.describeMismatch(element.$componentName:N(), mismatchDescription); matches = false; } diff --git a/src/test/java/no/rune/record/matcher/example/singlestring/SingleStringRecordMatcher.java b/src/test/java/no/rune/record/matcher/example/singlestring/SingleStringRecordMatcher.java index c41005f..f789d24 100644 --- a/src/test/java/no/rune/record/matcher/example/singlestring/SingleStringRecordMatcher.java +++ b/src/test/java/no/rune/record/matcher/example/singlestring/SingleStringRecordMatcher.java @@ -42,7 +42,7 @@ public void describeTo(Description description) { protected boolean matchesSafely(SingleStringRecord element, Description mismatchDescription) { boolean matches = true; if (!valueMatcher.matches(element.value())) { - mismatchDescription.appendText("value "); + mismatchDescription.appendText(" value "); valueMatcher.describeMismatch(element.value(), mismatchDescription); matches = false; } diff --git a/src/test/java/no/rune/record/matcher/example/singlestring/SingleStringRecordMatcherTest.java b/src/test/java/no/rune/record/matcher/example/singlestring/SingleStringRecordMatcherTest.java index 21dd537..fe21bda 100644 --- a/src/test/java/no/rune/record/matcher/example/singlestring/SingleStringRecordMatcherTest.java +++ b/src/test/java/no/rune/record/matcher/example/singlestring/SingleStringRecordMatcherTest.java @@ -36,7 +36,7 @@ void matchesRecordWithValue() { void doesNotMatchRecordWithUnexpectedValue() { var assertionError = assertThrows(AssertionError.class, () -> assertThat(new SingleStringRecord("x"), aSingleStringRecord().withValue("y"))); assertThat(assertionError, where(AssertionError::getMessage, - containsString(SingleStringRecord.class.getSimpleName() + " record where value is \"y\"\n but: value was \"x\""))); + containsString(SingleStringRecord.class.getSimpleName() + " record where value is \"y\"\n but: value was \"x\""))); } @Test diff --git a/src/test/java/no/rune/record/matcher/example/twovalues/TwoValuesRecordMatcher.java b/src/test/java/no/rune/record/matcher/example/twovalues/TwoValuesRecordMatcher.java index 7ceb53f..ed07ac6 100644 --- a/src/test/java/no/rune/record/matcher/example/twovalues/TwoValuesRecordMatcher.java +++ b/src/test/java/no/rune/record/matcher/example/twovalues/TwoValuesRecordMatcher.java @@ -57,12 +57,12 @@ public void describeTo(Description description) { protected boolean matchesSafely(TwoValuesRecord element, Description mismatchDescription) { boolean matches = true; if (!textMatcher.matches(element.text())) { - mismatchDescription.appendText("text "); + mismatchDescription.appendText(" text "); textMatcher.describeMismatch(element.text(), mismatchDescription); matches = false; } if (!numberMatcher.matches(element.number())) { - mismatchDescription.appendText("number "); + mismatchDescription.appendText(" number "); numberMatcher.describeMismatch(element.number(), mismatchDescription); matches = false; } diff --git a/src/test/java/no/rune/record/matcher/example/twovalues/TwoValuesRecordMatcherTest.java b/src/test/java/no/rune/record/matcher/example/twovalues/TwoValuesRecordMatcherTest.java index 24f1a69..8bd12e5 100644 --- a/src/test/java/no/rune/record/matcher/example/twovalues/TwoValuesRecordMatcherTest.java +++ b/src/test/java/no/rune/record/matcher/example/twovalues/TwoValuesRecordMatcherTest.java @@ -48,7 +48,14 @@ void matchesRecordWithAllComponentsSpecified() { void doesNotMatchRecordWithUnexpectedValue() { var assertionError = assertThrows(AssertionError.class, () -> assertThat(new TwoValuesRecord("x", 0), aTwoValuesRecord().withText("y"))); assertThat(assertionError, where(AssertionError::getMessage, - containsString(TwoValuesRecord.class.getSimpleName() + " record where text is \"y\"\n but: text was \"x\""))); + containsString(TwoValuesRecord.class.getSimpleName() + " record where text is \"y\"\n but: text was \"x\""))); + } + + @Test + void doesNotMatchRecordWithTwoUnexpectedValues() { + var assertionError = assertThrows(AssertionError.class, () -> assertThat(new TwoValuesRecord("x", 0), aTwoValuesRecord().withText(containsString("y")).withNumber(2))); + assertThat(assertionError, where(AssertionError::getMessage, + containsString(TwoValuesRecord.class.getSimpleName() + " record where text a string containing \"y\" number is <2>\n but: text was \"x\" number was <0>"))); } @Test