View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.collections4.bidimap;
18  
19  import static org.junit.jupiter.api.Assertions.assertSame;
20  import static org.junit.jupiter.api.Assertions.assertThrows;
21  import static org.junit.jupiter.api.Assertions.assertTrue;
22  
23  import java.util.HashMap;
24  import java.util.Map;
25  
26  import org.apache.commons.collections4.BidiMap;
27  import org.apache.commons.collections4.Unmodifiable;
28  import org.apache.commons.collections4.collection.AbstractCollectionTest;
29  import org.junit.jupiter.api.Test;
30  
31  /**
32   * JUnit tests.
33   */
34  public class UnmodifiableBidiMapTest<K, V> extends AbstractBidiMapTest<K, V> {
35  
36      public UnmodifiableBidiMapTest() {
37          super(UnmodifiableBidiMapTest.class.getSimpleName());
38      }
39  
40      @Override
41      protected int getIterationBehaviour() {
42          return AbstractCollectionTest.UNORDERED;
43      }
44  
45      /**
46       * Override to prevent infinite recursion of tests.
47       */
48      @Override
49      public String[] ignoredTests() {
50          return new String[] {"UnmodifiableBidiMapTest.bulkTestInverseMap.bulkTestInverseMap"};
51      }
52  
53      @Override
54      public boolean isPutAddSupported() {
55          return false;
56      }
57  
58      @Override
59      public boolean isPutChangeSupported() {
60          return false;
61      }
62  
63      @Override
64      public boolean isRemoveSupported() {
65          return false;
66      }
67  
68      @Override
69      public Map<K, V> makeConfirmedMap() {
70          return new HashMap<>();
71      }
72  
73      @Override
74      public BidiMap<K, V> makeFullMap() {
75          final BidiMap<K, V> bidi = new DualHashBidiMap<>();
76          addSampleMappings(bidi);
77          return UnmodifiableBidiMap.unmodifiableBidiMap(bidi);
78      }
79  
80      @Override
81      public BidiMap<K, V> makeObject() {
82          return UnmodifiableBidiMap.unmodifiableBidiMap(new DualHashBidiMap<>());
83      }
84  
85      @Test
86      public void testDecorateFactory() {
87          final BidiMap<K, V> map = makeFullMap();
88          assertSame(map, UnmodifiableBidiMap.unmodifiableBidiMap(map));
89  
90          assertThrows(NullPointerException.class, () -> UnmodifiableBidiMap.unmodifiableBidiMap(null));
91      }
92  
93      @Test
94      public void testUnmodifiable() {
95          assertTrue(makeObject() instanceof Unmodifiable);
96          assertTrue(makeFullMap() instanceof Unmodifiable);
97      }
98  
99  }