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 @Override
39 public String getCompatibilityVersion() {
40 return "4";
41 }
42
43 @Override
44 public boolean isAddSupported() {
45 return false;
46 }
47
48 @Override
49 public boolean isRemoveSupported() {
50 return false;
51 }
52
53 @Override
54 public Collection<E> makeConfirmedCollection() {
55 return new ArrayList<>();
56 }
57
58 @Override
59 public Collection<E> makeConfirmedFullCollection() {
60 return new ArrayList<>(Arrays.asList(getFullElements()));
61 }
62
63 @Override
64 public BoundedCollection<E> makeFullCollection() {
65 final E[] allElements = getFullElements();
66 final BoundedCollection<E> coll = FixedSizeList.<E>fixedSizeList(new ArrayList<>(Arrays.asList(allElements)));
67 return UnmodifiableBoundedCollection.unmodifiableBoundedCollection(coll);
68 }
69
70 @Override
71 public Collection<E> makeObject() {
72 final BoundedCollection<E> coll = FixedSizeList.<E>fixedSizeList(new ArrayList<>());
73 return UnmodifiableBoundedCollection.unmodifiableBoundedCollection(coll);
74 }
75
76 @Override
77 protected boolean skipSerializedCanonicalTests() {
78 return true;
79 }
80
81 @Test
82 public void testDecorateFactory() {
83 final BoundedCollection<E> coll = makeFullCollection();
84 assertSame(coll, UnmodifiableBoundedCollection.unmodifiableBoundedCollection(coll));
85
86 assertThrows(NullPointerException.class, () -> UnmodifiableBoundedCollection.unmodifiableBoundedCollection(null));
87 }
88
89 @Test
90 public void testUnmodifiable() {
91 assertTrue(makeObject() instanceof Unmodifiable);
92 assertTrue(makeFullCollection() instanceof Unmodifiable);
93 }
94
95 }