s4.add("A"); Set<String> s_1 = HashSetCache.get(s1); Assert.assertTrue(s_1 != s1); Assert.assertEquals(2, s_1.size()); Assert.assertFalse(s_1.contains("D")); Set<String> s_2 = HashSetCache.get(s2); Assert.assertTrue(s_1 == s_2); Set<String> s_3 = HashSetCache.get(s3); Assert.assertTrue(s_3 != s3); Assert.assertEquals(2, s_3.size()); Assert.assertFalse(s_3.contains("D")); Set<String> s_4 = HashSetCache.get(s4); Assert.assertTrue(s_4 != s4); Assert.assertEquals(1, s_4.size());
@Test public void testHashSetCache_get_unmodifiable() { Set<String> s1 = new TreeSet<String>(); s1.add("A"); s1.add("B"); Set<String> s = HashSetCache.get(s1); Assert.assertTrue(s != s1); Assert.assertEquals(2, s.size()); Assert.assertTrue(s.contains("A")); Assert.assertTrue(s.contains("B")); Assert.assertFalse(s.contains("C")); Assert.assertFalse(s.contains("D")); try { s.add("D"); Assert.fail("Expected Exception, but got none"); } catch (UnsupportedOperationException e) { log.info("catched expected exception.", e); } s1.add("C"); Assert.assertEquals("the returned set must be independent of the given, original set.", 2, s.size()); }
@Test public void testHashSetCache_get_identicalObjects() { Set<String> s1 = new TreeSet<String>(); s1.add("A"); s1.add("B"); Set<String> s2 = new HashSet<String>(); s2.add("A"); s2.add("B"); Set<String> s3 = new HashSet<String>(); s3.add("C"); s3.add("B"); s3.add("A"); Set<String> s_1 = HashSetCache.get(s1); Assert.assertTrue(s_1 != s1); Assert.assertEquals(2, s_1.size()); Set<String> s_2 = HashSetCache.get(s2); Assert.assertTrue(s_1 == s_2); Set<String> s_3 = HashSetCache.get(s3); Assert.assertTrue(s_3 != s3); Assert.assertEquals(3, s_3.size()); }
@Override public final void setAllowedModes(final Set<String> modes) { this.allowedModes = HashSetCache.get(modes); }
@Test public void testHashSetCache_get_emptySet() { Set<String> s = HashSetCache.get(new TreeSet<String>()); Assert.assertNotNull(s); Assert.assertEquals(0, s.size()); }
@Test public void testHashSetCache_get_null() { Set<String> s = HashSetCache.get((Set<String>) null); Assert.assertNull(s); }