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 java.util.SortedMap;
20  import java.util.TreeMap;
21  
22  import org.apache.commons.collections4.OrderedBidiMap;
23  
24  /**
25   * Test class for AbstractOrderedBidiMapDecorator.
26   *
27   * @param <K> the type of the keys in this map
28   * @param <V> the type of the values in this map
29   */
30  public class AbstractOrderedBidiMapDecoratorTest<K, V>
31          extends AbstractOrderedBidiMapTest<K, V> {
32  
33      /**
34       * Simple class to actually test.
35       */
36      private static final class TestOrderedBidiMap<K, V> extends AbstractOrderedBidiMapDecorator<K, V> {
37  
38          private TestOrderedBidiMap<V, K> inverse;
39  
40          TestOrderedBidiMap() {
41              super(new DualTreeBidiMap<>());
42          }
43  
44          TestOrderedBidiMap(final OrderedBidiMap<K, V> map) {
45              super(map);
46          }
47  
48          @Override
49          public OrderedBidiMap<V, K> inverseBidiMap() {
50              if (inverse == null) {
51                  inverse = new TestOrderedBidiMap<>(decorated().inverseBidiMap());
52                  inverse.inverse = this;
53              }
54              return inverse;
55          }
56      }
57  
58      public AbstractOrderedBidiMapDecoratorTest(final String testName) {
59          super(testName);
60      }
61  
62      @Override
63      public boolean isAllowNullKey() {
64          return false;
65      }
66  
67      @Override
68      public boolean isAllowNullValue() {
69          return false;
70      }
71  
72      @Override
73      public boolean isSetValueSupported() {
74          return true;
75      }
76  
77      @Override
78      public SortedMap<K, V> makeConfirmedMap() {
79          return new TreeMap<>();
80      }
81  
82      /**
83       * {@inheritDoc}
84       */
85      @Override
86      public OrderedBidiMap<K, V> makeObject() {
87          return new TestOrderedBidiMap<>();
88      }
89  }