Basically, the question is if there's an AssertJ (preferred) or JUnit assertion for:
objA == objB
My class under test (CUT) extends JAXB's XmlAdapter. When unmarshalling a XML file, it should guarantee that equal objects exist exactly once. In order to verify this, my test currently looks like this (in the example the standard ctor creates equal objects):
MyType obj = cut.unmarshal(new MyType());
assertThat(cut.unmarshal(new MyType()) == obj).isTrue();
Is there a way to explicitly assert identity with AssertJ or JUnit?
My class under test (CUT) has a method (e.g. foo) which should guarantee that returned objects—that are equal—exist exactly once. Currently, I'm using the following assert statement:
assertThat(cut.foo() == obj).isTrue();
Is there a way to explicitly assert identity with AssertJ or JUnit?
If you are using AssertJ, you can use the isSameAs method to compare object identity:
assertThat(cut.foo()).isSameAs(obj);
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