Skip to content

Commit

Permalink
Add space to delimit multiple failing components
Browse files Browse the repository at this point in the history
  • Loading branch information
runeflobakk committed Oct 25, 2023
1 parent 49a7b1f commit 3ca9443
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/main/java/no/rune/record/RecordMatcherGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public String generateFromRecord(Class<? extends Record> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3ca9443

Please sign in to comment.