1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
32
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
86
87
88
89
90
91
92 }