You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Adrian Wilkins <ad...@gmail.com> on 2010/08/16 12:25:58 UTC

Use of assertSame in Map tests.

Hello there... I've been writing an implementation of SortedMap that
doesn't have concrete objects for keys, but instead reconstructs them
on the fly where Entry<K, V> instances are required. Wanting a good
test suite for them, I've been re-using yours. :-)

The key objects satisfy the contract as far as .equals() and
.hashCode() go ; but some of the tests compare keys with the JUnit
Assert.assertSame() method, e.g. in
AbstractTestSortedMap.testFirstKey(), and hence fail because they
receive two keys that are different objects even where
key1.equals(key2).

I can of course, override the tests to behave as I wish, but would it
be more correct to use assertEqual() to check key equality, or use the
defined comparator if present?

The test acknowledges the existence of sorted maps that use a
Comparator also (by providing testComparator(), which contains no
substantive tests). If the key equality tests are worked over it would
seem to be a useful opportunity to provide some abstract methods to
allow the provision (and use) of a comparator for key tests also.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org