Skip to content

Commit

Permalink
Merge pull request #183 from lukas-krecan/fix-multierror
Browse files Browse the repository at this point in the history
Fixes #181 - correct formatting of multiple error messages
  • Loading branch information
lukas-krecan authored May 22, 2019
2 parents 6f4177e + 5033bcf commit 15bb4ab
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private JsonDifference(String message, Object[] args, Node expected, Node actual
}

AssertionFailedError getError() {
return new AssertionFailedError(message, expected.getValue(), actual.getValue());
return new AssertionFailedError(getMessage(), expected.getValue(), actual.getValue());
}

public Node getExpected() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
import net.javacrumbs.jsonunit.assertj.JsonAssert.ConfigurableJsonAssert;
import net.javacrumbs.jsonunit.core.Option;
import org.junit.jupiter.api.Test;
import org.opentest4j.MultipleFailuresError;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import static java.math.BigDecimal.valueOf;
Expand All @@ -33,6 +35,7 @@
import static net.javacrumbs.jsonunit.core.Option.TREATING_NULL_AS_ABSENT;
import static net.javacrumbs.jsonunit.core.internal.JsonUtils.jsonSource;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.entry;
import static org.hamcrest.Matchers.greaterThan;
Expand Down Expand Up @@ -396,6 +399,18 @@ void arraySimpleIgnoringOrderComparisonError() {
"Different value found in node \"a[1].c\", expected: <2> but was: <1>.\n");
}

@Test
void multipleFailuresErrorShouldbeCorrectlyFormatted() {
assertThatExceptionOfType(MultipleFailuresError.class)
.isThrownBy(() -> assertThatJson("{\"a\":[{\"b\": 1}, {\"c\": 1}, {\"d\": 1}]}").when(Option.IGNORING_ARRAY_ORDER).node("a").isArray()
.isEqualTo(json("[{\"c\": 2}, {\"b\": 1} ,{\"d\": 1}]")))
.satisfies(e -> {
List<Throwable> failures = e.getFailures();
assertThat(failures.get(0).getMessage()).isEqualTo("Different value found when comparing expected array element a[0] to actual element a[1].");
assertThat(failures.get(1).getMessage()).isEqualTo("Different value found in node \"a[1].c\", expected: <2> but was: <1>.");
});
}

@Test
void arraySimpleIgnoringOrderNotEqualComparison() {
assertThatJson("{\"a\":[{\"b\": 1}, {\"c\": 1}, {\"d\": 1}]}").when(Option.IGNORING_ARRAY_ORDER).node("a").isArray()
Expand Down

0 comments on commit 15bb4ab

Please sign in to comment.