lukas-krecan / JsonUnit

Compare JSON in your Unit Tests
Apache License 2.0
890 stars 114 forks source link

Numerical comparison regression in 2.36.0 #564

Closed adrogon closed 2 years ago

adrogon commented 2 years ago

Hello, using json-unit-fluent, this was passing in 2.35.0:

assertThatJson("{\"a\": 1.0, \"b\": 1.00}")
    .node("a").isEqualTo(1.0)
    .node("b").isEqualTo(1.0);
}

but is failing in 2.36.0 with Different value found in node "b", expected: <1.0> but was: <1.00>.

It does not look documented, so probably an unintended change?

Thank you :)

lukas-krecan commented 2 years ago

Hi, thanks for reporting. It's both. It was a fix of Jackson config I did back in May and I have forgotten to mention it in the release notes. But the new behavior is intended, see this. I will mention it in the release notes.

adrogon commented 2 years ago

So how do you make the second test pass without using withTolerance(0.0)? Do you need to use BigDecimal("1.00")? Because .node("b").isEqualTo(1.00) of course fails.

lukas-krecan commented 2 years ago
        assertThatJson("{\"a\": 1.0, \"b\": 1.00}")
            .node("b").isEqualTo("1.00");

should work

adrogon commented 2 years ago

Thank you for your reply, I'll stick with the .withTolerance(0.0) idea instead, and thank you for maintaining the library :)