So I am wondering why two objects are failing in my unit test (Junit 5) when they are created differently.
First way:
static ObjectMapper mapper = new ObjectMapper();
JsonNode output = mapper.convertValue(jsonTransform, JsonNode.class);
Second way:
JsonNode expectedOutput = mapper.readTree(jsonString);
And then asserted:
Assertions.assertEquals(expectedOutput, output);
The failure:
is org.opentest4j.AssertionFailedError: expected: com.fasterxml.jackson.databind.node.ObjectNode@d6e7bab<jsonString> but was: com.fasterxml.jackson.databind.node.ObjectNode@5fa07e12<jsonString>
Further, if I then edit the assertion to be:
Assertions.assertEquals(expectedOutput, mapper.readTree(output.toString()));
It will pass. So what concept is causing the first assertion to fail?
I'm having the same issue, the only solution I have found so far is to make use of:
Assertions.assertEquals(expectedOutput.toPrettyString(), output.toPrettyString());
I know it's not optimal but does the job. Funny thing is InteliJ says that the "Contents are identical" on the Comparison Failure but the test fails if I remove the toPrettyString()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With