Skip to content

Commit

Permalink
Better tolerance documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
lukas-krecan committed May 4, 2020
1 parent 987fbb2 commit 26af5b7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ Numbers are by default compared in the following way:
You can change this behavior by setting tolerance
```java
assertThatJson("{\"test\":1.00}").node("test").withTolerance(0).isEqualTo(1);
assertThatJson("{\"test\":1.00001}").node("test").withTolerance(0.001).isEqualTo(1);
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.opentest4j.AssertionFailedError;
import org.opentest4j.MultipleFailuresError;

import java.math.BigDecimal;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -31,6 +32,7 @@
import static java.util.Arrays.asList;
import static java.util.Collections.singletonList;
import static java.util.Collections.singletonMap;
import static net.javacrumbs.jsonunit.JsonAssert.assertJsonEquals;
import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson;
import static net.javacrumbs.jsonunit.assertj.JsonAssertions.json;
import static net.javacrumbs.jsonunit.assertj.JsonAssertions.value;
Expand Down Expand Up @@ -814,6 +816,24 @@ void pathShouldBeIgnoredForDifferentValue() {
.isEqualTo("{\"root\":{\"test\":1, \"ignored\": 2}}");
}


private static class TestBean {
final BigDecimal demo;
TestBean(BigDecimal demo) {
this.demo = demo;
}
public BigDecimal getDemo() {
return demo;
}
}

@Test
void shouldEqualNumberInObject() {
TestBean actual = new TestBean(new BigDecimal("2.00"));
String expected = "{ \"demo\": 2.00 }";
assertThatJson(actual).withTolerance(0).isEqualTo(expected);
}

@Test
void testEqualsToArray() {
assertThatJson("{\"test\":[1,2,3]}").node("test").isEqualTo(new int[]{1, 2, 3});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import static net.javacrumbs.jsonunit.JsonAssert.when;
import static net.javacrumbs.jsonunit.JsonAssert.whenIgnoringPaths;
import static net.javacrumbs.jsonunit.JsonAssert.withMatcher;
import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson;
import static net.javacrumbs.jsonunit.core.ConfigurationWhen.path;
import static net.javacrumbs.jsonunit.core.ConfigurationWhen.paths;
import static net.javacrumbs.jsonunit.core.ConfigurationWhen.rootPath;
Expand Down

0 comments on commit 26af5b7

Please sign in to comment.