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.map;
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  
25  import org.apache.commons.collections4.OrderedMap;
26  import org.apache.commons.collections4.Unmodifiable;
27  import org.junit.jupiter.api.Test;
28  
29  /**
30   * Extension of {@link AbstractOrderedMapTest} for exercising the
31   * {@link UnmodifiableOrderedMap} implementation.
32   */
33  public class UnmodifiableOrderedMapTest<K, V> extends AbstractOrderedMapTest<K, V> {
34  
35      public UnmodifiableOrderedMapTest() {
36          super(UnmodifiableOrderedMapTest.class.getSimpleName());
37      }
38  
39      @Override
40      public String getCompatibilityVersion() {
41          return "4";
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 OrderedMap<K, V> makeFullMap() {
61          final OrderedMap<K, V> m = ListOrderedMap.listOrderedMap(new HashMap<>());
62          addSampleMappings(m);
63          return UnmodifiableOrderedMap.unmodifiableOrderedMap(m);
64      }
65  
66      @Override
67      public OrderedMap<K, V> makeObject() {
68          return UnmodifiableOrderedMap.unmodifiableOrderedMap(ListOrderedMap.listOrderedMap(new HashMap<>()));
69      }
70  
71      @Test
72      public void testDecorateFactory() {
73          final OrderedMap<K, V> map = makeFullMap();
74          assertSame(map, UnmodifiableOrderedMap.unmodifiableOrderedMap(map));
75  
76          assertThrows(NullPointerException.class, () -> UnmodifiableOrderedMap.unmodifiableOrderedMap(null));
77      }
78  
79      @Test
80      public void testUnmodifiable() {
81          assertTrue(makeObject() instanceof Unmodifiable);
82          assertTrue(makeFullMap() instanceof Unmodifiable);
83      }
84  
85  //    public void testCreate() throws Exception {
86  //        resetEmpty();
87  //        writeExternalFormToDisk(
88  //            (java.io.Serializable) map,
89  //            "src/test/resources/data/test/UnmodifiableOrderedMap.emptyCollection.version4.obj");
90  //        resetFull();
91  //        writeExternalFormToDisk(
92  //            (java.io.Serializable) map,
93  //            "src/test/resources/data/test/UnmodifiableOrderedMap.fullCollection.version4.obj");
94  //    }
95  
96  }