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   * @param <K> the key type.
35   * @param <V> the value type.
36   */
37  public class UnmodifiableBidiMapTest<K, V> extends AbstractBidiMapTest<K, V> {
38  
39      @Override
40      protected int getIterationBehaviour() {
41          return AbstractCollectionTest.UNORDERED;
42      }
43  
44      @Override
45      public boolean isPutAddSupported() {
46          return false;
47      }
48  
49      @Override
50      public boolean isPutChangeSupported() {
51          return false;
52      }
53  
54      @Override
55      public boolean isRemoveSupported() {
56          return false;
57      }
58  
59      @Override
60      public Map<K, V> makeConfirmedMap() {
61          return new HashMap<>();
62      }
63  
64      @Override
65      public BidiMap<K, V> makeFullMap() {
66          final BidiMap<K, V> bidi = new DualHashBidiMap<>();
67          addSampleMappings(bidi);
68          return UnmodifiableBidiMap.unmodifiableBidiMap(bidi);
69      }
70  
71      @Override
72      public BidiMap<K, V> makeObject() {
73          return UnmodifiableBidiMap.unmodifiableBidiMap(new DualHashBidiMap<>());
74      }
75  
76      @Test
77      public void testDecorateFactory() {
78          final BidiMap<K, V> map = makeFullMap();
79          assertSame(map, UnmodifiableBidiMap.unmodifiableBidiMap(map));
80  
81          assertThrows(NullPointerException.class, () -> UnmodifiableBidiMap.unmodifiableBidiMap(null));
82      }
83  
84      @Test
85      public void testUnmodifiable() {
86          assertTrue(makeObject() instanceof Unmodifiable);
87          assertTrue(makeFullMap() instanceof Unmodifiable);
88      }
89  
90  }