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 java.io.IOException;
20 import java.io.Serializable;
21 import java.util.ArrayList;
22 import java.util.Arrays;
23 import java.util.Collection;
24
25 import org.apache.commons.collections4.Bag;
26 import org.apache.commons.collections4.SortedBag;
27 import org.apache.commons.collections4.collection.AbstractCollectionTest;
28
29
30
31
32
33
34
35
36
37 public class CollectionSortedBagTest<T> extends AbstractCollectionTest<T> {
38
39
40
41
42
43
44 public CollectionSortedBagTest(final String testName) {
45 super(testName);
46 }
47
48
49
50
51
52
53
54 @Override
55 public boolean isNullSupported() {
56 return false;
57 }
58
59 @Override
60 public Bag<T> makeObject() {
61 return CollectionSortedBag.collectionSortedBag(new TreeBag<T>());
62 }
63
64
65
66
67
68
69 @Override
70 public Collection<T> makeConfirmedCollection() {
71 return new ArrayList<>();
72 }
73
74
75
76
77
78
79 @Override
80 public Collection<T> makeConfirmedFullCollection() {
81 final Collection<T> set = makeConfirmedCollection();
82 set.addAll(Arrays.asList(getFullElements()));
83 return set;
84 }
85
86
87
88
89
90 @Override
91 @SuppressWarnings("unchecked")
92 public T[] getFullNonNullElements() {
93 final Object[] elements = new Object[30];
94
95 for (int i = 0; i < 30; i++) {
96 elements[i] = Integer.valueOf(i + i + 1);
97 }
98 return (T[]) elements;
99 }
100
101
102
103
104 @Override
105 @SuppressWarnings("unchecked")
106 public T[] getOtherNonNullElements() {
107 final Object[] elements = new Object[30];
108 for (int i = 0; i < 30; i++) {
109 elements[i] = Integer.valueOf(i + i + 2);
110 }
111 return (T[]) elements;
112 }
113
114
115
116 @Override
117 public String getCompatibilityVersion() {
118 return "4";
119 }
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134 public void testEmptyBagCompatibility() throws IOException, ClassNotFoundException {
135
136 final Bag<T> bag = makeObject();
137 if (bag instanceof Serializable && !skipSerializedCanonicalTests() && isTestSerialization()) {
138 final Bag<?> bag2 = (Bag<?>) readExternalFormFromDisk(getCanonicalEmptyCollectionName(bag));
139 assertTrue("Bag is empty",bag2.size() == 0);
140 assertEquals(bag, bag2);
141 }
142 }
143
144
145
146
147
148 public void testFullBagCompatibility() throws IOException, ClassNotFoundException {
149
150 final SortedBag<T> bag = (SortedBag<T>) makeFullCollection();
151 if (bag instanceof Serializable && !skipSerializedCanonicalTests() && isTestSerialization()) {
152 final SortedBag<?> bag2 = (SortedBag<?>) readExternalFormFromDisk(getCanonicalFullCollectionName(bag));
153 assertEquals("Bag is the right size", bag.size(), bag2.size());
154 assertEquals(bag, bag2);
155 }
156 }
157
158 }