@Test public void retainAllFromEntrySet() { MutableMapIterable<String, Integer> map = this.newMapWithKeysValues("One", 1, "Two", 2, "Three", 3); Assert.assertFalse( map.entrySet() .retainAll( FastList.newListWith( ImmutableEntry.of("One", 1), ImmutableEntry.of("Two", 2), ImmutableEntry.of("Three", 3), ImmutableEntry.of("Four", 4)))); Assert.assertTrue( map.entrySet() .retainAll( FastList.newListWith( ImmutableEntry.of("One", 1), ImmutableEntry.of("Three", 3), ImmutableEntry.of("Four", 4)))); Assert.assertEquals(UnifiedMap.newWithKeysValues("One", 1, "Three", 3), map); MutableMapIterable<Integer, Integer> integers = this.newMapWithKeysValues(1, 1, 2, 2, 3, 3); Integer copy = new Integer(1); Assert.assertTrue(integers.entrySet().retainAll(mList(ImmutableEntry.of(copy, copy)))); Assert.assertEquals(iMap(copy, copy), integers); Assert.assertNotSame(copy, Iterate.getOnly(integers.entrySet()).getKey()); Assert.assertNotSame(copy, Iterate.getOnly(integers.entrySet()).getValue()); }
@Test public void clearEntrySet() { MutableMapIterable<String, Integer> map = this.newMapWithKeysValues("One", 1, "Two", 2, "Three", 3); map.entrySet().clear(); Verify.assertEmpty(map); }
@Test public void removeFromEntrySet() { MutableMapIterable<String, Integer> map = this.newMapWithKeysValues("One", 1, "Two", 2, "Three", 3); Assert.assertTrue(map.entrySet().remove(ImmutableEntry.of("Two", 2))); Assert.assertEquals(UnifiedMap.newWithKeysValues("One", 1, "Three", 3), map); Assert.assertFalse(map.entrySet().remove(ImmutableEntry.of("Four", 4))); Assert.assertEquals(UnifiedMap.newWithKeysValues("One", 1, "Three", 3), map); Assert.assertFalse(map.entrySet().remove(null)); MutableMapIterable<String, Integer> mapWithNullKey = this.newMapWithKeysValues("One", 1, null, 2, "Three", 3); Assert.assertTrue( mapWithNullKey.entrySet().remove(new ImmutableEntry<String, Integer>(null, 2))); }
@Test public void entrySetEqualsAndHashCode() { MutableMapIterable<String, Integer> map = this.newMapWithKeysValues("One", 1, "Two", 2, "Three", 3); Verify.assertEqualsAndHashCode( UnifiedSet.newSetWith( ImmutableEntry.of("One", 1), ImmutableEntry.of("Two", 2), ImmutableEntry.of("Three", 3)), map.entrySet()); }