beatngu13 beatngu13 - 1 year ago 130
Java Question

Assert identity with AssertJ or JUnit

My class under test (CUT) has a method (e.g.

) which should guarantee that returned objects—that are equal—exist exactly once. Currently, I'm using the following assert statement:

assertThat( == obj).isTrue();

Is there a way to explicitly assert identity with AssertJ or JUnit?

Answer Source

If you are using AssertJ, you can use the isSameAs method to compare object identity:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download