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.set;
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.Arrays;
24  import java.util.HashSet;
25  import java.util.Set;
26  
27  import org.apache.commons.collections4.Unmodifiable;
28  import org.junit.jupiter.api.Test;
29  
30  /**
31   * Extension of {@link AbstractSetTest} for exercising the
32   * {@link UnmodifiableSet} implementation.
33   */
34  public class UnmodifiableSetTest<E> extends AbstractSetTest<E> {
35  
36      public UnmodifiableSetTest() {
37          super(UnmodifiableSetTest.class.getSimpleName());
38      }
39  
40      @Override
41      public String getCompatibilityVersion() {
42          return "4";
43      }
44  
45      @Override
46      protected int getIterationBehaviour() {
47          return UNORDERED;
48      }
49  
50      @Override
51      public boolean isAddSupported() {
52          return false;
53      }
54  
55      @Override
56      public boolean isRemoveSupported() {
57          return false;
58      }
59  
60      @Override
61      public Set<E> makeFullCollection() {
62          final HashSet<E> set = new HashSet<>(Arrays.asList(getFullElements()));
63          return UnmodifiableSet.unmodifiableSet(set);
64      }
65  
66      @Override
67      public Set<E> makeObject() {
68          return UnmodifiableSet.unmodifiableSet(new HashSet<>());
69      }
70  
71      @Test
72      public void testDecorateFactory() {
73          final Set<E> set = makeFullCollection();
74          assertSame(set, UnmodifiableSet.unmodifiableSet(set));
75  
76          assertThrows(NullPointerException.class, () -> UnmodifiableSet.unmodifiableSet(null));
77      }
78  
79      @Test
80      public void testUnmodifiable() {
81          assertTrue(makeObject() instanceof Unmodifiable);
82          assertTrue(makeFullCollection() instanceof Unmodifiable);
83      }
84  
85  //    public void testCreate() throws Exception {
86  //        resetEmpty();
87  //        writeExternalFormToDisk((java.io.Serializable) getCollection(), "src/test/resources/data/test/UnmodifiableSet.emptyCollection.version4.obj");
88  //        resetFull();
89  //        writeExternalFormToDisk((java.io.Serializable) getCollection(), "src/test/resources/data/test/UnmodifiableSet.fullCollection.version4.obj");
90  //    }
91  
92  }