The error message from assertSame() does not make it clear the failure was that the objects aren't identical. Consider assertSame("foo", new String("foo")) - this fails with java.lang.AssertionError: expected [foo] but found [foo]. Granted, the stack trace indicates the error came from assertSame(), but a quick glance at the error text is confusing - didn't it get what it expected?
I'd suggest adding an assertEquals() call inside assertSame() after the equality check, and if that passes (meaning they're equal but not identical) failing with a different message, like expected [foo] but found equivalent but not same [foo].
Less important, but the assertNotSame() error message contains both expected and actual, which are known at that time to be the same object. It seems somewhat unhelpful to include the same object twice in the error.
The error message from
assertSame()does not make it clear the failure was that the objects aren't identical. ConsiderassertSame("foo", new String("foo"))- this fails withjava.lang.AssertionError: expected [foo] but found [foo]. Granted, the stack trace indicates the error came from assertSame(), but a quick glance at the error text is confusing - didn't it get what it expected?I'd suggest adding an
assertEquals()call insideassertSame()after the equality check, and if that passes (meaning they're equal but not identical) failing with a different message, likeexpected [foo] but found equivalent but not same [foo].Less important, but the
assertNotSame()error message contains bothexpectedandactual, which are known at that time to be the same object. It seems somewhat unhelpful to include the same object twice in the error.