1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.collections4.bag;
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
25 import org.apache.commons.collections4.SortedBag;
26 import org.apache.commons.collections4.Unmodifiable;
27 import org.apache.commons.collections4.collection.AbstractCollectionTest;
28 import org.junit.jupiter.api.Test;
29
30
31
32
33
34 public class UnmodifiableSortedBagTest<E> extends AbstractSortedBagTest<E> {
35
36 @Override
37 public SortedBag<E> getCollection() {
38 return super.getCollection();
39 }
40
41 @Override
42 public String getCompatibilityVersion() {
43 return "4";
44 }
45
46 @Override
47 public boolean isAddSupported() {
48 return false;
49 }
50
51 @Override
52 public boolean isNullSupported() {
53 return false;
54 }
55
56 @Override
57 public boolean isRemoveSupported() {
58 return false;
59 }
60
61 @Override
62 public SortedBag<E> makeFullCollection() {
63 final SortedBag<E> bag = new TreeBag<>();
64 bag.addAll(Arrays.asList(getFullElements()));
65 return UnmodifiableSortedBag.unmodifiableSortedBag(bag);
66 }
67
68 @Override
69 public SortedBag<E> makeObject() {
70 return UnmodifiableSortedBag.unmodifiableSortedBag(new TreeBag<>());
71 }
72
73 @Test
74 public void testDecorateFactory() {
75 final SortedBag<E> queue = makeFullCollection();
76 assertSame(queue, UnmodifiableSortedBag.unmodifiableSortedBag(queue));
77
78 assertThrows(NullPointerException.class, () -> UnmodifiableSortedBag.unmodifiableSortedBag(null));
79 }
80
81 @Test
82 public void testUnmodifiable() {
83 assertTrue(makeObject() instanceof Unmodifiable);
84 assertTrue(makeFullCollection() instanceof Unmodifiable);
85 }
86
87
88
89
90
91
92
93
94 }