/**
* Tests {@link MapFromIntToString}.
*/
public void testMapsFromIntstoStrings() {
// This is our test subject.
final MapFromIntToString map = Collections.mapFromIntToString();
// These are his keys.
final int[] keys = new int[] {1, 2, 3};
// These are the values for those keys.
final String[] vals = new String[] {"val-0", "val-1", "val-2"};
// Let's put those values in.
for (int i = 0, n = keys.length; i < n; ++i) {
map.put(keys[i], vals[i]);
}
// Are they all in the right place?
for (int i = 0, n = keys.length; i < n; ++i) {
assertTrue(map.hasKey(keys[i]));
assertEquals(vals[i], map.get(keys[i]));
}
// These are some new values.
final String[] newVals = new String[] {"val-3", "val-4", "val-5"};
// Let's update those keys, ok.
for (int i = 0, n = keys.length; i < n; ++i) {
map.put(keys[i], newVals[i]);
}
// Are they all in the right place?
for (int i = 0, n = keys.length; i < n; ++i) {
assertTrue(map.hasKey(keys[i]));
assertEquals(newVals[i], map.get(keys[i]));
}
checkMapContents(map, keys, newVals);
// Let's remove a key, did it go away?
map.remove(keys[0]);
assertNull(map.get(keys[0]));
assertFalse(map.hasKey(keys[0]));
}