public void testIndex_nullValue() { List<Integer> values = Arrays.asList(1, null); try { Multimaps.index(values, Functions.identity()); fail(); } catch (NullPointerException expected) { } }
public void testIndex_nullKey() { List<Integer> values = Arrays.asList(1, 2); try { Multimaps.index(values, Functions.constant(null)); fail(); } catch (NullPointerException expected) { } }
public void testFilteredKeysSetMultimapGetBadValue() { SetMultimap<String, Integer> multimap = LinkedHashMultimap.create(); multimap.put("foo", 1); multimap.put("bar", 2); multimap.put("baz", 3); multimap.put("bar", 4); SetMultimap<String, Integer> filtered = Multimaps.filterKeys(multimap, Predicates.in(ImmutableSet.of("foo", "bar"))); Set<Integer> bazSet = filtered.get("baz"); assertThat(bazSet).isEmpty(); try { bazSet.add(5); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { } try { bazSet.addAll(ImmutableSet.of(6, 7)); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { } }
try { bazList.add(5); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException expected) {
public void testFilteredKeysSetMultimapReplaceValues() { SetMultimap<String, Integer> multimap = LinkedHashMultimap.create(); multimap.put("foo", 1); multimap.put("bar", 2); multimap.put("baz", 3); multimap.put("bar", 4); SetMultimap<String, Integer> filtered = Multimaps.filterKeys(multimap, Predicates.in(ImmutableSet.of("foo", "bar"))); assertEquals(ImmutableSet.of(), filtered.replaceValues("baz", ImmutableSet.<Integer>of())); try { filtered.replaceValues("baz", ImmutableSet.of(5)); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { } }
@SuppressWarnings("unchecked") public void testUnmodifiableMultimapEntries() { Multimap<String, Integer> mod = HashMultimap.create(); Multimap<String, Integer> unmod = Multimaps.unmodifiableMultimap(mod); mod.put("foo", 1); Entry<String, Integer> entry = unmod.entries().iterator().next(); try { entry.setValue(2); fail("UnsupportedOperationException expected"); } catch (UnsupportedOperationException expected) { } entry = (Entry<String, Integer>) unmod.entries().toArray()[0]; try { entry.setValue(2); fail("UnsupportedOperationException expected"); } catch (UnsupportedOperationException expected) { } Entry<String, Integer>[] array = (Entry<String, Integer>[]) new Entry<?, ?>[2]; assertSame(array, unmod.entries().toArray(array)); try { array[0].setValue(2); fail("UnsupportedOperationException expected"); } catch (UnsupportedOperationException expected) { } assertFalse(unmod.entries().contains(nefariousMapEntry("pwnd", 2))); assertFalse(unmod.keys().contains("pwnd")); }
try { multimapView.put("baz", 3); fail("UnsupportedOperationException expected"); } catch (UnsupportedOperationException expected) { fail("UnsupportedOperationException expected"); } catch (UnsupportedOperationException expected) { fail("UnsupportedOperationException expected"); } catch (UnsupportedOperationException expected) { fail("UnsupportedOperationException expected"); } catch (UnsupportedOperationException expected) {
public void testIndex_nullValue() { List<Integer> values = Arrays.asList(1, null); try { Multimaps.index(values, Functions.identity()); fail(); } catch (NullPointerException expected) { } }
public void testIndex_nullKey() { List<Integer> values = Arrays.asList(1, 2); try { Multimaps.index(values, Functions.constant(null)); fail(); } catch (NullPointerException expected) { } }
public void testFilteredKeysSetMultimapGetBadValue() { SetMultimap<String, Integer> multimap = LinkedHashMultimap.create(); multimap.put("foo", 1); multimap.put("bar", 2); multimap.put("baz", 3); multimap.put("bar", 4); SetMultimap<String, Integer> filtered = Multimaps.filterKeys( multimap, Predicates.in(ImmutableSet.of("foo", "bar"))); Set<Integer> bazSet = filtered.get("baz"); assertThat(bazSet).isEmpty(); try { bazSet.add(5); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { } try { bazSet.addAll(ImmutableSet.of(6, 7)); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { } }
try { bazList.add(5); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException expected) {
public void testFilteredKeysSetMultimapReplaceValues() { SetMultimap<String, Integer> multimap = LinkedHashMultimap.create(); multimap.put("foo", 1); multimap.put("bar", 2); multimap.put("baz", 3); multimap.put("bar", 4); SetMultimap<String, Integer> filtered = Multimaps.filterKeys( multimap, Predicates.in(ImmutableSet.of("foo", "bar"))); assertEquals( ImmutableSet.of(), filtered.replaceValues("baz", ImmutableSet.<Integer>of())); try { filtered.replaceValues("baz", ImmutableSet.of(5)); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { } }
@SuppressWarnings("unchecked") public void testUnmodifiableMultimapEntries() { Multimap<String, Integer> mod = HashMultimap.create(); Multimap<String, Integer> unmod = Multimaps.unmodifiableMultimap(mod); mod.put("foo", 1); Entry<String, Integer> entry = unmod.entries().iterator().next(); try { entry.setValue(2); fail("UnsupportedOperationException expected"); } catch (UnsupportedOperationException expected) {} entry = (Entry<String, Integer>) unmod.entries().toArray()[0]; try { entry.setValue(2); fail("UnsupportedOperationException expected"); } catch (UnsupportedOperationException expected) {} Entry<String, Integer>[] array = (Entry<String, Integer>[]) new Entry<?, ?>[2]; assertSame(array, unmod.entries().toArray(array)); try { array[0].setValue(2); fail("UnsupportedOperationException expected"); } catch (UnsupportedOperationException expected) {} assertFalse(unmod.entries().contains(nefariousMapEntry("pwnd", 2))); assertFalse(unmod.keys().contains("pwnd")); }
try { multimapView.put("baz", 3); fail("UnsupportedOperationException expected"); } catch (UnsupportedOperationException expected) {} try { multimapView.putAll("baz", Collections.singleton(3)); fail("UnsupportedOperationException expected"); } catch (UnsupportedOperationException expected) {} try { multimapView.putAll(multimap); fail("UnsupportedOperationException expected"); } catch (UnsupportedOperationException expected) {} try { multimapView.replaceValues("foo", Collections.<Integer>emptySet()); fail("UnsupportedOperationException expected"); } catch (UnsupportedOperationException expected) {} multimapView.remove("bar", 2);