Skip to content

Commit

Permalink
A better test
Browse files Browse the repository at this point in the history
  • Loading branch information
strangepleasures committed Nov 26, 2019
1 parent 9a3b49d commit cd4c516
Showing 1 changed file with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@

import static java.util.stream.Collectors.toMap;
import static java.util.stream.IntStream.rangeClosed;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.*;

import org.apache.jena.atlas.lib.Cache;
import org.junit.Test;
Expand All @@ -44,9 +43,17 @@ public void testFixedSize() {

@Test
public void testSameHash() {
Cache<String, Integer> cache = new CacheSimple<>(10);
assertEquals("Aa".hashCode(), "BB".hashCode());
cache.put("Aa", 1);
assertFalse("Keys with same hash code should not be considered equal", cache.containsKey("BB"));
Object key1 = new Object() {
@Override public int hashCode() { return 1; }
};
Object key2 = new Object() {
@Override public int hashCode() { return 1; }
};
assertEquals(key1.hashCode(), key2.hashCode());
assertNotEquals(key1, key2);
Cache<Object, Integer> cache = new CacheSimple<>(10);
cache.put(key1, 1);
assertTrue("Same key, expected in cache", cache.containsKey(key1));
assertFalse("Keys with same hash code should not be considered equal", cache.containsKey(key2));
}
}

0 comments on commit cd4c516

Please sign in to comment.