View Javadoc
1   /*
2    * Copyright (C) 2012 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  package com.google.common.collect.testing.google;
17  
18  import static com.google.common.collect.testing.Helpers.assertEqualIgnoringOrder;
19  import static com.google.common.collect.testing.Helpers.mapEntry;
20  import static com.google.common.collect.testing.features.CollectionFeature.KNOWN_ORDER;
21  
22  import com.google.common.annotations.GwtCompatible;
23  import com.google.common.collect.Multimap;
24  import com.google.common.collect.testing.features.CollectionFeature;
25  import java.util.ArrayList;
26  import java.util.List;
27  import java.util.Map.Entry;
28  
29  /**
30   * Tests for {@link Multimap#forEach}.
31   *
32   * @author Louis Wasserman
33   */
34  @GwtCompatible
35  public class MultimapForEachTester<K, V> extends AbstractMultimapTester<K, V, Multimap<K, V>> {
36    public void testForEach() {
37      List<Entry<K, V>> entries = new ArrayList<>();
38      multimap().forEach((k, v) -> entries.add(mapEntry(k, v)));
39      assertEqualIgnoringOrder(getSampleElements(), multimap().entries());
40    }
41  
42    @CollectionFeature.Require(KNOWN_ORDER)
43    public void testForEachOrder() {
44      List<Entry<K, V>> entries = new ArrayList<>();
45      multimap().forEach((k, v) -> entries.add(mapEntry(k, v)));
46      assertEqualIgnoringOrder(getSampleElements(), multimap().entries());
47    }
48  }