• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 The Guava Authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.google.common.collect;
18 
19 import static com.google.common.base.Preconditions.checkArgument;
20 import static com.google.common.truth.Truth.assertThat;
21 import static java.util.Arrays.asList;
22 
23 import com.google.common.annotations.GwtCompatible;
24 import com.google.common.annotations.GwtIncompatible;
25 import com.google.common.annotations.J2ktIncompatible;
26 import com.google.common.collect.testing.ListTestSuiteBuilder;
27 import com.google.common.collect.testing.MinimalCollection;
28 import com.google.common.collect.testing.SetTestSuiteBuilder;
29 import com.google.common.collect.testing.TestStringListGenerator;
30 import com.google.common.collect.testing.TestStringSetGenerator;
31 import com.google.common.collect.testing.features.CollectionFeature;
32 import com.google.common.collect.testing.features.CollectionSize;
33 import com.google.common.collect.testing.google.MultisetTestSuiteBuilder;
34 import com.google.common.collect.testing.google.TestStringMultisetGenerator;
35 import com.google.common.collect.testing.google.UnmodifiableCollectionTests;
36 import com.google.common.testing.EqualsTester;
37 import com.google.common.testing.NullPointerTester;
38 import com.google.common.testing.SerializableTester;
39 import java.util.ArrayList;
40 import java.util.Arrays;
41 import java.util.Collection;
42 import java.util.HashSet;
43 import java.util.Iterator;
44 import java.util.List;
45 import java.util.Set;
46 import junit.framework.Test;
47 import junit.framework.TestCase;
48 import junit.framework.TestSuite;
49 import org.checkerframework.checker.nullness.qual.Nullable;
50 
51 /**
52  * Tests for {@link ImmutableMultiset}.
53  *
54  * @author Jared Levy
55  */
56 @GwtCompatible(emulated = true)
57 @ElementTypesAreNonnullByDefault
58 public class ImmutableMultisetTest extends TestCase {
59 
60   @J2ktIncompatible
61   @GwtIncompatible // suite // TODO(cpovirk): add to collect/gwt/suites
suite()62   public static Test suite() {
63     TestSuite suite = new TestSuite();
64     suite.addTestSuite(ImmutableMultisetTest.class);
65 
66     suite.addTest(
67         MultisetTestSuiteBuilder.using(
68                 new TestStringMultisetGenerator() {
69                   @Override
70                   protected Multiset<String> create(String[] elements) {
71                     return ImmutableMultiset.copyOf(elements);
72                   }
73                 })
74             .named("ImmutableMultiset")
75             .withFeatures(
76                 CollectionSize.ANY,
77                 CollectionFeature.SERIALIZABLE_INCLUDING_VIEWS,
78                 CollectionFeature.ALLOWS_NULL_QUERIES)
79             .createTestSuite());
80 
81     suite.addTest(
82         SetTestSuiteBuilder.using(
83                 new TestStringSetGenerator() {
84                   @Override
85                   protected Set<String> create(String[] elements) {
86                     return ImmutableMultiset.copyOf(elements).elementSet();
87                   }
88                 })
89             .named("ImmutableMultiset, element set")
90             .withFeatures(
91                 CollectionSize.ANY,
92                 CollectionFeature.SERIALIZABLE,
93                 CollectionFeature.ALLOWS_NULL_QUERIES)
94             .createTestSuite());
95 
96     suite.addTest(
97         ListTestSuiteBuilder.using(
98                 new TestStringListGenerator() {
99                   @Override
100                   protected List<String> create(String[] elements) {
101                     return ImmutableMultiset.copyOf(elements).asList();
102                   }
103 
104                   @Override
105                   public List<String> order(List<String> insertionOrder) {
106                     List<String> order = new ArrayList<>();
107                     for (String s : insertionOrder) {
108                       int index = order.indexOf(s);
109                       if (index == -1) {
110                         order.add(s);
111                       } else {
112                         order.add(index, s);
113                       }
114                     }
115                     return order;
116                   }
117                 })
118             .named("ImmutableMultiset.asList")
119             .withFeatures(
120                 CollectionSize.ANY,
121                 CollectionFeature.SERIALIZABLE,
122                 CollectionFeature.ALLOWS_NULL_QUERIES)
123             .createTestSuite());
124 
125     suite.addTest(
126         ListTestSuiteBuilder.using(
127                 new TestStringListGenerator() {
128                   @Override
129                   protected List<String> create(String[] elements) {
130                     Set<String> set = new HashSet<>();
131                     ImmutableMultiset.Builder<String> builder = ImmutableMultiset.builder();
132                     for (String s : elements) {
133                       checkArgument(set.add(s));
134                       builder.addCopies(s, 2);
135                     }
136                     ImmutableSet<String> elementSet =
137                         (ImmutableSet<String>) builder.build().elementSet();
138                     return elementSet.asList();
139                   }
140                 })
141             .named("ImmutableMultiset.elementSet.asList")
142             .withFeatures(
143                 CollectionSize.ANY,
144                 CollectionFeature.REJECTS_DUPLICATES_AT_CREATION,
145                 CollectionFeature.SERIALIZABLE,
146                 CollectionFeature.ALLOWS_NULL_QUERIES)
147             .createTestSuite());
148 
149     return suite;
150   }
151 
testCreation_noArgs()152   public void testCreation_noArgs() {
153     Multiset<String> multiset = ImmutableMultiset.of();
154     assertTrue(multiset.isEmpty());
155   }
156 
testCreation_oneElement()157   public void testCreation_oneElement() {
158     Multiset<String> multiset = ImmutableMultiset.of("a");
159     assertEquals(HashMultiset.create(asList("a")), multiset);
160   }
161 
testCreation_twoElements()162   public void testCreation_twoElements() {
163     Multiset<String> multiset = ImmutableMultiset.of("a", "b");
164     assertEquals(HashMultiset.create(asList("a", "b")), multiset);
165   }
166 
testCreation_threeElements()167   public void testCreation_threeElements() {
168     Multiset<String> multiset = ImmutableMultiset.of("a", "b", "c");
169     assertEquals(HashMultiset.create(asList("a", "b", "c")), multiset);
170   }
171 
testCreation_fourElements()172   public void testCreation_fourElements() {
173     Multiset<String> multiset = ImmutableMultiset.of("a", "b", "c", "d");
174     assertEquals(HashMultiset.create(asList("a", "b", "c", "d")), multiset);
175   }
176 
testCreation_fiveElements()177   public void testCreation_fiveElements() {
178     Multiset<String> multiset = ImmutableMultiset.of("a", "b", "c", "d", "e");
179     assertEquals(HashMultiset.create(asList("a", "b", "c", "d", "e")), multiset);
180   }
181 
testCreation_sixElements()182   public void testCreation_sixElements() {
183     Multiset<String> multiset = ImmutableMultiset.of("a", "b", "c", "d", "e", "f");
184     assertEquals(HashMultiset.create(asList("a", "b", "c", "d", "e", "f")), multiset);
185   }
186 
testCreation_sevenElements()187   public void testCreation_sevenElements() {
188     Multiset<String> multiset = ImmutableMultiset.of("a", "b", "c", "d", "e", "f", "g");
189     assertEquals(HashMultiset.create(asList("a", "b", "c", "d", "e", "f", "g")), multiset);
190   }
191 
testCreation_emptyArray()192   public void testCreation_emptyArray() {
193     String[] array = new String[0];
194     Multiset<String> multiset = ImmutableMultiset.copyOf(array);
195     assertTrue(multiset.isEmpty());
196   }
197 
testCreation_arrayOfOneElement()198   public void testCreation_arrayOfOneElement() {
199     String[] array = new String[] {"a"};
200     Multiset<String> multiset = ImmutableMultiset.copyOf(array);
201     assertEquals(HashMultiset.create(asList("a")), multiset);
202   }
203 
testCreation_arrayOfArray()204   public void testCreation_arrayOfArray() {
205     String[] array = new String[] {"a"};
206     Multiset<String[]> multiset = ImmutableMultiset.<String[]>of(array);
207     Multiset<String[]> expected = HashMultiset.create();
208     expected.add(array);
209     assertEquals(expected, multiset);
210   }
211 
testCreation_arrayContainingOnlyNull()212   public void testCreation_arrayContainingOnlyNull() {
213     @Nullable String[] array = new @Nullable String[] {null};
214     try {
215       ImmutableMultiset.copyOf((String[]) array);
216       fail();
217     } catch (NullPointerException expected) {
218     }
219   }
220 
testCopyOf_collection_empty()221   public void testCopyOf_collection_empty() {
222     // "<String>" is required to work around a javac 1.5 bug.
223     Collection<String> c = MinimalCollection.<String>of();
224     Multiset<String> multiset = ImmutableMultiset.copyOf(c);
225     assertTrue(multiset.isEmpty());
226   }
227 
testCopyOf_collection_oneElement()228   public void testCopyOf_collection_oneElement() {
229     Collection<String> c = MinimalCollection.of("a");
230     Multiset<String> multiset = ImmutableMultiset.copyOf(c);
231     assertEquals(HashMultiset.create(asList("a")), multiset);
232   }
233 
testCopyOf_collection_general()234   public void testCopyOf_collection_general() {
235     Collection<String> c = MinimalCollection.of("a", "b", "a");
236     Multiset<String> multiset = ImmutableMultiset.copyOf(c);
237     assertEquals(HashMultiset.create(asList("a", "b", "a")), multiset);
238   }
239 
testCopyOf_collectionContainingNull()240   public void testCopyOf_collectionContainingNull() {
241     Collection<@Nullable String> c = MinimalCollection.of("a", null, "b");
242     try {
243       ImmutableMultiset.copyOf((Collection<String>) c);
244       fail();
245     } catch (NullPointerException expected) {
246     }
247   }
248 
testCopyOf_multiset_empty()249   public void testCopyOf_multiset_empty() {
250     Multiset<String> c = HashMultiset.create();
251     Multiset<String> multiset = ImmutableMultiset.copyOf(c);
252     assertTrue(multiset.isEmpty());
253   }
254 
testCopyOf_multiset_oneElement()255   public void testCopyOf_multiset_oneElement() {
256     Multiset<String> c = HashMultiset.create(asList("a"));
257     Multiset<String> multiset = ImmutableMultiset.copyOf(c);
258     assertEquals(HashMultiset.create(asList("a")), multiset);
259   }
260 
testCopyOf_multiset_general()261   public void testCopyOf_multiset_general() {
262     Multiset<String> c = HashMultiset.create(asList("a", "b", "a"));
263     Multiset<String> multiset = ImmutableMultiset.copyOf(c);
264     assertEquals(HashMultiset.create(asList("a", "b", "a")), multiset);
265   }
266 
testCopyOf_multisetContainingNull()267   public void testCopyOf_multisetContainingNull() {
268     Multiset<@Nullable String> c =
269         HashMultiset.create(Arrays.<@Nullable String>asList("a", null, "b"));
270     try {
271       ImmutableMultiset.copyOf((Multiset<String>) c);
272       fail();
273     } catch (NullPointerException expected) {
274     }
275   }
276 
testCopyOf_iterator_empty()277   public void testCopyOf_iterator_empty() {
278     Iterator<String> iterator = Iterators.emptyIterator();
279     Multiset<String> multiset = ImmutableMultiset.copyOf(iterator);
280     assertTrue(multiset.isEmpty());
281   }
282 
testCopyOf_iterator_oneElement()283   public void testCopyOf_iterator_oneElement() {
284     Iterator<String> iterator = Iterators.singletonIterator("a");
285     Multiset<String> multiset = ImmutableMultiset.copyOf(iterator);
286     assertEquals(HashMultiset.create(asList("a")), multiset);
287   }
288 
testCopyOf_iterator_general()289   public void testCopyOf_iterator_general() {
290     Iterator<String> iterator = asList("a", "b", "a").iterator();
291     Multiset<String> multiset = ImmutableMultiset.copyOf(iterator);
292     assertEquals(HashMultiset.create(asList("a", "b", "a")), multiset);
293   }
294 
testCopyOf_iteratorContainingNull()295   public void testCopyOf_iteratorContainingNull() {
296     Iterator<@Nullable String> iterator =
297         Arrays.<@Nullable String>asList("a", null, "b").iterator();
298     try {
299       ImmutableMultiset.copyOf((Iterator<String>) iterator);
300       fail();
301     } catch (NullPointerException expected) {
302     }
303   }
304 
305   private static class CountingIterable implements Iterable<String> {
306     int count = 0;
307 
308     @Override
iterator()309     public Iterator<String> iterator() {
310       count++;
311       return asList("a", "b", "a").iterator();
312     }
313   }
314 
testCopyOf_plainIterable()315   public void testCopyOf_plainIterable() {
316     CountingIterable iterable = new CountingIterable();
317     Multiset<String> multiset = ImmutableMultiset.copyOf(iterable);
318     assertEquals(HashMultiset.create(asList("a", "b", "a")), multiset);
319     assertEquals(1, iterable.count);
320   }
321 
testCopyOf_hashMultiset()322   public void testCopyOf_hashMultiset() {
323     Multiset<String> iterable = HashMultiset.create(asList("a", "b", "a"));
324     Multiset<String> multiset = ImmutableMultiset.copyOf(iterable);
325     assertEquals(HashMultiset.create(asList("a", "b", "a")), multiset);
326   }
327 
testCopyOf_treeMultiset()328   public void testCopyOf_treeMultiset() {
329     Multiset<String> iterable = TreeMultiset.create(asList("a", "b", "a"));
330     Multiset<String> multiset = ImmutableMultiset.copyOf(iterable);
331     assertEquals(HashMultiset.create(asList("a", "b", "a")), multiset);
332   }
333 
testCopyOf_shortcut_empty()334   public void testCopyOf_shortcut_empty() {
335     Collection<String> c = ImmutableMultiset.of();
336     assertSame(c, ImmutableMultiset.copyOf(c));
337   }
338 
testCopyOf_shortcut_singleton()339   public void testCopyOf_shortcut_singleton() {
340     Collection<String> c = ImmutableMultiset.of("a");
341     assertSame(c, ImmutableMultiset.copyOf(c));
342   }
343 
testCopyOf_shortcut_immutableMultiset()344   public void testCopyOf_shortcut_immutableMultiset() {
345     Collection<String> c = ImmutableMultiset.of("a", "b", "c");
346     assertSame(c, ImmutableMultiset.copyOf(c));
347   }
348 
testBuilderAdd()349   public void testBuilderAdd() {
350     ImmutableMultiset<String> multiset =
351         new ImmutableMultiset.Builder<String>().add("a").add("b").add("a").add("c").build();
352     assertEquals(HashMultiset.create(asList("a", "b", "a", "c")), multiset);
353   }
354 
testBuilderAddAll()355   public void testBuilderAddAll() {
356     List<String> a = asList("a", "b");
357     List<String> b = asList("c", "d");
358     ImmutableMultiset<String> multiset =
359         new ImmutableMultiset.Builder<String>().addAll(a).addAll(b).build();
360     assertEquals(HashMultiset.create(asList("a", "b", "c", "d")), multiset);
361   }
362 
testBuilderAddAllHashMultiset()363   public void testBuilderAddAllHashMultiset() {
364     Multiset<String> a = HashMultiset.create(asList("a", "b", "b"));
365     Multiset<String> b = HashMultiset.create(asList("c", "b"));
366     ImmutableMultiset<String> multiset =
367         new ImmutableMultiset.Builder<String>().addAll(a).addAll(b).build();
368     assertEquals(HashMultiset.create(asList("a", "b", "b", "b", "c")), multiset);
369   }
370 
testBuilderAddAllImmutableMultiset()371   public void testBuilderAddAllImmutableMultiset() {
372     Multiset<String> a = ImmutableMultiset.of("a", "b", "b");
373     Multiset<String> b = ImmutableMultiset.of("c", "b");
374     ImmutableMultiset<String> multiset =
375         new ImmutableMultiset.Builder<String>().addAll(a).addAll(b).build();
376     assertEquals(HashMultiset.create(asList("a", "b", "b", "b", "c")), multiset);
377   }
378 
testBuilderAddAllTreeMultiset()379   public void testBuilderAddAllTreeMultiset() {
380     Multiset<String> a = TreeMultiset.create(asList("a", "b", "b"));
381     Multiset<String> b = TreeMultiset.create(asList("c", "b"));
382     ImmutableMultiset<String> multiset =
383         new ImmutableMultiset.Builder<String>().addAll(a).addAll(b).build();
384     assertEquals(HashMultiset.create(asList("a", "b", "b", "b", "c")), multiset);
385   }
386 
testBuilderAddAllIterator()387   public void testBuilderAddAllIterator() {
388     Iterator<String> iterator = asList("a", "b", "a", "c").iterator();
389     ImmutableMultiset<String> multiset =
390         new ImmutableMultiset.Builder<String>().addAll(iterator).build();
391     assertEquals(HashMultiset.create(asList("a", "b", "a", "c")), multiset);
392   }
393 
testBuilderAddCopies()394   public void testBuilderAddCopies() {
395     ImmutableMultiset<String> multiset =
396         new ImmutableMultiset.Builder<String>()
397             .addCopies("a", 2)
398             .addCopies("b", 3)
399             .addCopies("c", 0)
400             .build();
401     assertEquals(HashMultiset.create(asList("a", "a", "b", "b", "b")), multiset);
402   }
403 
testBuilderSetCount()404   public void testBuilderSetCount() {
405     ImmutableMultiset<String> multiset =
406         new ImmutableMultiset.Builder<String>().add("a").setCount("a", 2).setCount("b", 3).build();
407     assertEquals(HashMultiset.create(asList("a", "a", "b", "b", "b")), multiset);
408   }
409 
testBuilderAddHandlesNullsCorrectly()410   public void testBuilderAddHandlesNullsCorrectly() {
411     ImmutableMultiset.Builder<String> builder = ImmutableMultiset.builder();
412     try {
413       builder.add((String) null);
414       fail("expected NullPointerException");
415     } catch (NullPointerException expected) {
416     }
417   }
418 
testBuilderAddAllHandlesNullsCorrectly()419   public void testBuilderAddAllHandlesNullsCorrectly() {
420     ImmutableMultiset.Builder<String> builder = ImmutableMultiset.builder();
421     try {
422       builder.addAll((Collection<String>) null);
423       fail("expected NullPointerException");
424     } catch (NullPointerException expected) {
425     }
426 
427     builder = ImmutableMultiset.builder();
428     List<@Nullable String> listWithNulls = asList("a", null, "b");
429     try {
430       builder.addAll((List<String>) listWithNulls);
431       fail("expected NullPointerException");
432     } catch (NullPointerException expected) {
433     }
434 
435     builder = ImmutableMultiset.builder();
436     Multiset<@Nullable String> multisetWithNull =
437         LinkedHashMultiset.create(Arrays.<@Nullable String>asList("a", null, "b"));
438     try {
439       builder.addAll((Multiset<String>) multisetWithNull);
440       fail("expected NullPointerException");
441     } catch (NullPointerException expected) {
442     }
443   }
444 
testBuilderAddCopiesHandlesNullsCorrectly()445   public void testBuilderAddCopiesHandlesNullsCorrectly() {
446     ImmutableMultiset.Builder<String> builder = ImmutableMultiset.builder();
447     try {
448       builder.addCopies(null, 2);
449       fail("expected NullPointerException");
450     } catch (NullPointerException expected) {
451     }
452   }
453 
testBuilderAddCopiesIllegal()454   public void testBuilderAddCopiesIllegal() {
455     ImmutableMultiset.Builder<String> builder = ImmutableMultiset.builder();
456     try {
457       builder.addCopies("a", -2);
458       fail("expected IllegalArgumentException");
459     } catch (IllegalArgumentException expected) {
460     }
461   }
462 
testBuilderSetCountHandlesNullsCorrectly()463   public void testBuilderSetCountHandlesNullsCorrectly() {
464     ImmutableMultiset.Builder<String> builder = ImmutableMultiset.builder();
465     try {
466       builder.setCount(null, 2);
467       fail("expected NullPointerException");
468     } catch (NullPointerException expected) {
469     }
470   }
471 
testBuilderSetCountIllegal()472   public void testBuilderSetCountIllegal() {
473     ImmutableMultiset.Builder<String> builder = ImmutableMultiset.builder();
474     try {
475       builder.setCount("a", -2);
476       fail("expected IllegalArgumentException");
477     } catch (IllegalArgumentException expected) {
478     }
479   }
480 
481   @J2ktIncompatible
482   @GwtIncompatible // NullPointerTester
testNullPointers()483   public void testNullPointers() {
484     NullPointerTester tester = new NullPointerTester();
485     tester.testAllPublicStaticMethods(ImmutableMultiset.class);
486   }
487 
488   @J2ktIncompatible
489   @GwtIncompatible // SerializableTester
testSerialization_empty()490   public void testSerialization_empty() {
491     Collection<String> c = ImmutableMultiset.of();
492     assertSame(c, SerializableTester.reserialize(c));
493   }
494 
495   @J2ktIncompatible
496   @GwtIncompatible // SerializableTester
testSerialization_multiple()497   public void testSerialization_multiple() {
498     Collection<String> c = ImmutableMultiset.of("a", "b", "a");
499     Collection<String> copy = SerializableTester.reserializeAndAssert(c);
500     assertThat(copy).containsExactly("a", "a", "b").inOrder();
501   }
502 
503   @J2ktIncompatible
504   @GwtIncompatible // SerializableTester
testSerialization_elementSet()505   public void testSerialization_elementSet() {
506     Multiset<String> c = ImmutableMultiset.of("a", "b", "a");
507     Collection<String> copy = LenientSerializableTester.reserializeAndAssertLenient(c.elementSet());
508     assertThat(copy).containsExactly("a", "b").inOrder();
509   }
510 
511   @J2ktIncompatible
512   @GwtIncompatible // SerializableTester
testSerialization_entrySet()513   public void testSerialization_entrySet() {
514     Multiset<String> c = ImmutableMultiset.of("a", "b", "c");
515     SerializableTester.reserializeAndAssert(c.entrySet());
516   }
517 
testEquals_immutableMultiset()518   public void testEquals_immutableMultiset() {
519     Collection<String> c = ImmutableMultiset.of("a", "b", "a");
520     assertEquals(c, ImmutableMultiset.of("a", "b", "a"));
521     assertEquals(c, ImmutableMultiset.of("a", "a", "b"));
522     assertThat(c).isNotEqualTo(ImmutableMultiset.of("a", "b"));
523     assertThat(c).isNotEqualTo(ImmutableMultiset.of("a", "b", "c", "d"));
524   }
525 
testIterationOrder()526   public void testIterationOrder() {
527     Collection<String> c = ImmutableMultiset.of("a", "b", "a");
528     assertThat(c).containsExactly("a", "a", "b").inOrder();
529     assertThat(ImmutableMultiset.of("c", "b", "a", "c").elementSet())
530         .containsExactly("c", "b", "a")
531         .inOrder();
532   }
533 
testMultisetWrites()534   public void testMultisetWrites() {
535     Multiset<String> multiset = ImmutableMultiset.of("a", "b", "a");
536     UnmodifiableCollectionTests.assertMultisetIsUnmodifiable(multiset, "test");
537   }
538 
testAsList()539   public void testAsList() {
540     ImmutableMultiset<String> multiset = ImmutableMultiset.of("a", "a", "b", "b", "b");
541     ImmutableList<String> list = multiset.asList();
542     assertEquals(ImmutableList.of("a", "a", "b", "b", "b"), list);
543     assertEquals(2, list.indexOf("b"));
544     assertEquals(4, list.lastIndexOf("b"));
545   }
546 
547   @J2ktIncompatible
548   @GwtIncompatible // SerializableTester
testSerialization_asList()549   public void testSerialization_asList() {
550     ImmutableMultiset<String> multiset = ImmutableMultiset.of("a", "a", "b", "b", "b");
551     SerializableTester.reserializeAndAssert(multiset.asList());
552   }
553 
testEquals()554   public void testEquals() {
555     new EqualsTester()
556         .addEqualityGroup(ImmutableMultiset.of(), ImmutableMultiset.of())
557         .addEqualityGroup(ImmutableMultiset.of(1), ImmutableMultiset.of(1))
558         .addEqualityGroup(ImmutableMultiset.of(1, 1), ImmutableMultiset.of(1, 1))
559         .addEqualityGroup(ImmutableMultiset.of(1, 2, 1), ImmutableMultiset.of(2, 1, 1))
560         .testEquals();
561   }
562 
testIterationOrderThroughBuilderRemovals()563   public void testIterationOrderThroughBuilderRemovals() {
564     ImmutableMultiset.Builder<String> builder = ImmutableMultiset.builder();
565     builder.addCopies("a", 2);
566     builder.add("b");
567     builder.add("c");
568     builder.setCount("b", 0);
569     ImmutableMultiset<String> multiset = builder.build();
570     assertThat(multiset.elementSet()).containsExactly("a", "c").inOrder();
571     builder.add("b");
572     assertThat(builder.build().elementSet()).containsExactly("a", "c", "b").inOrder();
573     assertThat(multiset.elementSet()).containsExactly("a", "c").inOrder();
574   }
575 }
576