Skip to content

Commit

Permalink
Improve singular/plural wording of differences
Browse files Browse the repository at this point in the history
  • Loading branch information
joel-costigliola committed Feb 13, 2019
1 parent 3217cf3 commit 4ab1c40
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 9 deletions.
Expand Up @@ -49,15 +49,16 @@ public static ErrorMessageFactory shouldBeEqualByComparingFieldByFieldRecursivel
Representation representation) {
String differencesDescription = join(differences.stream()
.map(difference -> difference.multiLineDescription(representation))
.collect(toList())).with(format("%n"));
.collect(toList())).with(format("%n%n"));
String recursiveComparisonConfigurationDescription = recursiveComparisonConfiguration.multiLineDescription(representation);
String differencesCount = differences.size() == 1 ? "difference:%n" : "%s differences:%n";
// @format:off
return new ShouldBeEqualByComparingFieldByFieldRecursively("%n" +
"Expecting:%n" +
" <%s>%n" +
"to be equal to:%n" +
" <%s>%n" +
"when recursively comparing field by field, but found the following %s difference(s):%n"+
"when recursively comparing field by field, but found the following " + differencesCount +
"%n" +
differencesDescription + "%n" +
"%n"+
Expand Down
Expand Up @@ -197,10 +197,10 @@ public void should_display_difference_with_percent() {
}

@Test
public void should_show_that_all_actual_null_fields_were_ignored_in_the_comparison() {
public void should_show_multiple_differences() {
// GIVEN
final Name actualName = new Name("Andy");
final Name nullName = new Name(null);
final Name actualName = new Name("Magic", "Johnson");
final Name nullName = new Name(null, "Ginobili");
RecursiveComparisonConfiguration recursiveComparisonConfiguration = new RecursiveComparisonConfiguration();
recursiveComparisonConfiguration.setIgnoreAllActualNullFields(true);
List<ComparisonDifference> differences = determineDifferences(actualName, nullName, recursiveComparisonConfiguration);
Expand All @@ -216,13 +216,50 @@ public void should_show_that_all_actual_null_fields_were_ignored_in_the_comparis
// THEN
assertThat(message).isEqualTo(format("[Test] %n" +
"Expecting:%n" +
" <Name[first='Andy', last='null']>%n" +
" <Name[first='Magic', last='Johnson']>%n" +
"to be equal to:%n" +
" <Name[first='null', last='Ginobili']>%n" +
"when recursively comparing field by field, but found the following 2 differences:%n" +
"%n" +
"field/property 'first' differ:%n" +
"- actual value : \"Magic\"%n" +
"- expected value : null%n" +
"%n" +
"field/property 'last' differ:%n" +
"- actual value : \"Johnson\"%n" +
"- expected value : \"Ginobili\"%n" +
"%n" +
"The recursive comparison was performed with this configuration:%n%s",
CONFIGURATION_PROVIDER.representation().toStringOf(recursiveComparisonConfiguration)));
}

@Test
public void should_show_one_difference() {
// GIVEN
final Name actualName = new Name("Magic", "Johnson");
final Name nullName = new Name(null, "Johnson");
RecursiveComparisonConfiguration recursiveComparisonConfiguration = new RecursiveComparisonConfiguration();
recursiveComparisonConfiguration.setIgnoreAllActualNullFields(true);
List<ComparisonDifference> differences = determineDifferences(actualName, nullName, recursiveComparisonConfiguration);
// WHEN
// @format:off
String message = shouldBeEqualByComparingFieldByFieldRecursively(actualName,
nullName,
differences,
recursiveComparisonConfiguration,
REPRESENTATION)
.create(new TextDescription("Test"), REPRESENTATION);
// @format:on
// THEN
assertThat(message).isEqualTo(format("[Test] %n" +
"Expecting:%n" +
" <Name[first='Magic', last='Johnson']>%n" +
"to be equal to:%n" +
" <Name[first='null', last='null']>%n" +
"when recursively comparing field by field, but found the following 1 difference(s):%n" +
" <Name[first='null', last='Johnson']>%n" +
"when recursively comparing field by field, but found the following difference:%n" +
"%n" +
"field/property 'first' differ:%n" +
"- actual value : \"Andy\"%n" +
"- actual value : \"Magic\"%n" +
"- expected value : null%n" +
"%n" +
"The recursive comparison was performed with this configuration:%n%s",
Expand Down

0 comments on commit 4ab1c40

Please sign in to comment.