beatngu13 beatngu13 - 6 months ago 57
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?


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