1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.collections4.collection;
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.ArrayList;
24 import java.util.Arrays;
25 import java.util.Collection;
26
27 import org.apache.commons.collections4.BoundedCollection;
28 import org.apache.commons.collections4.Unmodifiable;
29 import org.apache.commons.collections4.list.FixedSizeList;
30 import org.junit.jupiter.api.Test;
31
32
33
34
35
36 public class UnmodifiableBoundedCollectionTest<E> extends AbstractCollectionTest<E> {
37
38 public UnmodifiableBoundedCollectionTest() {
39 super(UnmodifiableBoundedCollectionTest.class.getSimpleName());
40 }
41
42 @Override
43 public String getCompatibilityVersion() {
44 return "4";
45 }
46
47 @Override
48 public boolean isAddSupported() {
49 return false;
50 }
51
52 @Override
53 public boolean isRemoveSupported() {
54 return false;
55 }
56
57 @Override
58 public Collection<E> makeConfirmedCollection() {
59 return new ArrayList<>();
60 }
61
62 @Override
63 public Collection<E> makeConfirmedFullCollection() {
64 return new ArrayList<>(Arrays.asList(getFullElements()));
65 }
66
67 @Override
68 public BoundedCollection<E> makeFullCollection() {
69 final E[] allElements = getFullElements();
70 final BoundedCollection<E> coll = FixedSizeList.<E>fixedSizeList(new ArrayList<>(Arrays.asList(allElements)));
71 return UnmodifiableBoundedCollection.unmodifiableBoundedCollection(coll);
72 }
73
74 @Override
75 public Collection<E> makeObject() {
76 final BoundedCollection<E> coll = FixedSizeList.<E>fixedSizeList(new ArrayList<>());
77 return UnmodifiableBoundedCollection.unmodifiableBoundedCollection(coll);
78 }
79
80 @Override
81 protected boolean skipSerializedCanonicalTests() {
82 return true;
83 }
84
85 @Test
86 public void testDecorateFactory() {
87 final BoundedCollection<E> coll = makeFullCollection();
88 assertSame(coll, UnmodifiableBoundedCollection.unmodifiableBoundedCollection(coll));
89
90 assertThrows(NullPointerException.class, () -> UnmodifiableBoundedCollection.unmodifiableBoundedCollection(null));
91 }
92
93 @Test
94 public void testUnmodifiable() {
95 assertTrue(makeObject() instanceof Unmodifiable);
96 assertTrue(makeFullCollection() instanceof Unmodifiable);
97 }
98
99 }