Debian Codegraph @

eclipse-collections-code-generator/src/main/resources/test/collection/mutable/abstractMutablePrimitiveCollectionTestCase.stg

raw
1 import "copyrightAndOthers.stg"
2 import "primitiveEquals.stg"
3 import "primitiveHashCode.stg"
4 import "primitiveLiteral.stg"
5
6 isTest() ::= "true"
7
8 targetPath() ::= "org/eclipse/collections/impl/collection/mutable/primitive"
9
10 fileName(primitive) ::= "AbstractMutable<primitive.name>CollectionTestCase"
11
12 class(primitive) ::= <<
13 <body(primitive.type, primitive.wrapperName, primitive.name)>
14 >>
15
16 body(type, wrapperName, name) ::= <<
17 <copyrightAndOthers()>
18
19 package org.eclipse.collections.impl.collection.mutable.primitive;
20
21 import java.util.NoSuchElementException;
22
23 import org.eclipse.collections.api.collection.primitive.Mutable<name>Collection;
24 import org.eclipse.collections.api.iterator.<name>Iterator;
25 import org.eclipse.collections.api.iterator.Mutable<name>Iterator;
26 import org.eclipse.collections.impl.bag.mutable.primitive.<name>HashBag;
27 import org.eclipse.collections.impl.block.factory.primitive.<name>Predicates;
28 import org.eclipse.collections.impl.list.mutable.primitive.<name>ArrayList;
29 import org.eclipse.collections.impl.test.Verify;
30 import org.junit.Assert;
31 import org.junit.Test;
32
33 /**
34 * Abstract JUnit test for {@link Mutable<name>Collection}s
35 * This file was automatically generated from template file abstractMutablePrimitiveCollectionTestCase.stg.
36 */
37 public abstract class AbstractMutable<name>CollectionTestCase extends Abstract<name>IterableTestCase
38 {
39 @Override
40 protected abstract Mutable<name>Collection classUnderTest();
41
42 @Override
43 protected abstract Mutable<name>Collection newWith(<type>... elements);
44
45 @Override
46 protected abstract Mutable<name>Collection newMutableCollectionWith(<type>... elements);
47
48 @Test
49 public void clear()
50 {
51 Mutable<name>Collection emptyCollection = this.newWith();
52 emptyCollection.clear();
53 Verify.assertSize(0, emptyCollection);
54
55 Mutable<name>Collection collection = this.classUnderTest();
56 collection.clear();
57 Verify.assertEmpty(collection);
58 Verify.assertSize(0, collection);
59 Assert.assertFalse(collection.contains(<(literal.(type))("0")>));
60 Assert.assertFalse(collection.contains(<(literal.(type))("1")>));
61 Assert.assertFalse(collection.contains(<(literal.(type))("2")>));
62 Assert.assertFalse(collection.contains(<(literal.(type))("3")>));
63
64 Mutable<name>Collection collection1 = this.newWith(<["0", "1", "31", "32"]:(literal.(type))(); separator=", ">);
65 collection1.clear();
66 Verify.assertEmpty(collection1);
67 Verify.assertSize(0, collection1);
68 Assert.assertFalse(collection1.contains(<(literal.(type))("0")>));
69 Assert.assertFalse(collection1.contains(<(literal.(type))("1")>));
70 Assert.assertFalse(collection1.contains(<(literal.(type))("31")>));
71 Assert.assertFalse(collection1.contains(<(literal.(type))("32")>));
72
73 Mutable<name>Collection collection2 = this.newWith(<["0", "1", "1", "2", "2", "2"]:(literal.(type))(); separator=", ">);
74 collection2.clear();
75 Verify.assertSize(0, collection2);
76 Assert.assertEquals(this.newMutableCollectionWith(), collection2);
77 }
78
79 @Override
80 @Test
81 public void testEquals()
82 {
83 super.testEquals();
84 Verify.assertPostSerializedEqualsAndHashCode(this.newWith());
85 }
86
87 @Override
88 @Test
89 public void contains()
90 {
91 super.contains();
92 Mutable<name>Collection collection = this.newWith(<["14", "2", "30", "31", "32", "35", "0", "1"]:(literal.(type))(); separator=", ">);
93 Assert.assertFalse(collection.contains(<(literal.(type))("29")>));
94 Assert.assertFalse(collection.contains(<(literal.(type))("49")>));
95
96 <type>[] numbers = {<["14", "2", "30", "31", "32", "35", "0", "1"]:(literal.(type))(); separator=", ">};
97 for (<type> number : numbers)
98 {
99 Assert.assertTrue(collection.contains(number));
100 Assert.assertTrue(collection.remove(number));
101 Assert.assertFalse(collection.contains(number));
102 }
103
104 Assert.assertFalse(collection.contains(<(literal.(type))("-1")>));
105 Assert.assertFalse(collection.contains(<(literal.(type))("29")>));
106 Assert.assertFalse(collection.contains(<(literal.(type))("49")>));
107 }
108
109 @Test
110 public void add()
111 {
112 Mutable<name>Collection emptyCollection = this.newWith();
113 Assert.assertTrue(emptyCollection.add(<(literal.(type))("1")>));
114 Assert.assertEquals(this.newMutableCollectionWith(<(literal.(type))("1")>), emptyCollection);
115 Mutable<name>Collection collection = this.classUnderTest();
116 Assert.assertTrue(collection.add(<(literal.(type))("4")>));
117 Assert.assertEquals(this.newMutableCollectionWith(<["1", "2", "3", "4"]:(literal.(type))(); separator=", ">), collection);
118 }
119
120 @Test
121 public void addAllArray()
122 {
123 Mutable<name>Collection collection = this.classUnderTest();
124 Assert.assertFalse(collection.addAll());
125 Assert.assertTrue(collection.addAll(<["4", "5", "6"]:(literal.(type))(); separator=", ">));
126 Assert.assertEquals(this.newMutableCollectionWith(<["1", "2", "3", "4", "5", "6"]:(literal.(type))(); separator=", ">), collection);
127 }
128
129 @Test
130 public void addAllIterable()
131 {
132 Mutable<name>Collection collection = this.classUnderTest();
133 Assert.assertFalse(collection.addAll(this.newMutableCollectionWith()));
134 Assert.assertTrue(collection.addAll(this.newMutableCollectionWith(<["4", "5", "6"]:(literal.(type))(); separator=", ">)));
135 Assert.assertEquals(this.newMutableCollectionWith(<["1", "2", "3", "4", "5", "6"]:(literal.(type))(); separator=", ">), collection);
136 }
137
138 @Test
139 public void remove()
140 {
141 Mutable<name>Collection collection = this.classUnderTest();
142 Assert.assertFalse(collection.remove(<(literal.(type))("-1")>));
143 Assert.assertEquals(this.newMutableCollectionWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">), collection);
144 Assert.assertTrue(collection.remove(<(literal.(type))("3")>));
145 Assert.assertEquals(this.newMutableCollectionWith(<["1", "2"]:(literal.(type))(); separator=", ">), collection);
146 }
147
148 @Test
149 public void removeIf()
150 {
151 Mutable<name>Collection collection = this.classUnderTest();
152 Assert.assertFalse(collection.removeIf(<name>Predicates.equal(<(literal.(type))("-1")>)));
153 Assert.assertEquals(this.newMutableCollectionWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">), collection);
154 Assert.assertTrue(collection.removeIf(<name>Predicates.equal(<(literal.(type))("2")>)));
155 Assert.assertEquals(this.newMutableCollectionWith(<["1", "3"]:(literal.(type))(); separator=", ">), collection);
156 Assert.assertTrue(collection.removeIf(<name>Predicates.greaterThan(<(literal.(type))("1")>)));
157 Assert.assertEquals(this.newMutableCollectionWith(<(literal.(type))("1")>), collection);
158 Assert.assertFalse(collection.removeIf(<name>Predicates.greaterThan(<(literal.(type))("1")>)));
159 Assert.assertEquals(this.newMutableCollectionWith(<(literal.(type))("1")>), collection);
160 Assert.assertTrue(collection.removeIf(<name>Predicates.alwaysTrue()));
161 Assert.assertTrue(collection.isEmpty());
162 Assert.assertFalse(collection.removeIf(<name>Predicates.alwaysTrue()));
163 Assert.assertTrue(collection.isEmpty());
164
165 collection = this.classUnderTest();
166 Assert.assertTrue(collection.removeIf(<name>Predicates.alwaysTrue()));
167 Assert.assertTrue(collection.isEmpty());
168
169 collection = this.classUnderTest();
170 Assert.assertFalse(collection.removeIf(<name>Predicates.alwaysFalse()));
171 Assert.assertEquals(this.newMutableCollectionWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">), collection);
172
173 collection = this.classUnderTest();
174 Assert.assertTrue(collection.removeIf(<name>Predicates.greaterThan(<(literal.(type))("1")>)));
175 Assert.assertEquals(this.newMutableCollectionWith(<["1"]:(literal.(type))(); separator=", ">), collection);
176
177 collection = this.classUnderTest();
178 Assert.assertTrue(collection.removeIf(<name>Predicates.lessThan(<(literal.(type))("3")>)));
179 Assert.assertEquals(this.newMutableCollectionWith(<["3"]:(literal.(type))(); separator=", ">), collection);
180
181 collection = this.classUnderTest();
182 Mutable<name>Collection remove = this.newMutableCollectionWith(<["1", "3"]:(literal.(type))(); separator=", ">);
183 Assert.assertTrue(collection.removeIf(remove::contains));
184 Assert.assertEquals(this.newMutableCollectionWith(<["2"]:(literal.(type))(); separator=", ">), collection);
185
186 collection = this.classUnderTest();
187 remove = this.newMutableCollectionWith(<["2"]:(literal.(type))(); separator=", ">);
188 Assert.assertTrue(collection.removeIf(remove::contains));
189 Assert.assertEquals(this.newMutableCollectionWith(<["1", "3"]:(literal.(type))(); separator=", ">), collection);
190
191 collection = this.newMutableCollectionWith(<["1", "3", "2", "5", "6", "4"]:(literal.(type))(); separator=", ">);
192 remove = this.newMutableCollectionWith(<["2", "4", "6"]:(literal.(type))(); separator=", ">);
193 Assert.assertTrue(collection.removeIf(remove::contains));
194 Assert.assertEquals(this.newMutableCollectionWith(<["1", "3", "5"]:(literal.(type))(); separator=", ">), collection);
195
196 collection = this.newMutableCollectionWith(<["1", "3", "2", "5", "6", "4"]:(literal.(type))(); separator=", ">);
197 remove = this.newMutableCollectionWith(<["1", "3", "5"]:(literal.(type))(); separator=", ">);
198 Assert.assertTrue(collection.removeIf(remove::contains));
199 Assert.assertEquals(this.newMutableCollectionWith(<["2", "6", "4"]:(literal.(type))(); separator=", ">), collection);
200 }
201
202 @Test
203 public void removeAll()
204 {
205 Assert.assertFalse(this.newWith().removeAll());
206 Assert.assertFalse(this.newWith().removeAll(<(literal.(type))("1")>));
207
208 Mutable<name>Collection collection = this.classUnderTest();
209 Assert.assertFalse(collection.removeAll());
210 Assert.assertFalse(collection.removeAll(<(literal.(type))("-1")>));
211 Assert.assertEquals(this.newMutableCollectionWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">), collection);
212 Assert.assertTrue(collection.removeAll(<["1", "5"]:(literal.(type))(); separator=", ">));
213 Assert.assertEquals(this.newMutableCollectionWith(<["2", "3"]:(literal.(type))(); separator=", ">), collection);
214 Assert.assertTrue(collection.removeAll(<["3", "2"]:(literal.(type))(); separator=", ">));
215 Assert.assertEquals(this.newMutableCollectionWith(), collection);
216
217 Mutable<name>Collection collection1 = this.newWith(<["0", "1", "1", "2", "2", "2"]:(literal.(type))(); separator=", ">);
218 Assert.assertFalse(collection1.removeAll());
219 Assert.assertTrue(collection1.removeAll(<["0", "1"]:(literal.(type))(); separator=", ">));
220 Assert.assertEquals(this.newMutableCollectionWith(<["2", "2", "2"]:(literal.(type))(); separator=", ">), collection1);
221 }
222
223 @Test
224 public void removeAll_iterable()
225 {
226 Mutable<name>Collection collection = this.classUnderTest();
227 Assert.assertFalse(collection.removeAll(this.newMutableCollectionWith()));
228 Assert.assertFalse(collection.removeAll(this.newMutableCollectionWith(<(literal.(type))("-1")>)));
229 Assert.assertEquals(this.newMutableCollectionWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">), collection);
230 Assert.assertTrue(collection.removeAll(this.newMutableCollectionWith(<["1", "5"]:(literal.(type))(); separator=", ">)));
231 Assert.assertEquals(this.newMutableCollectionWith(<["2", "3"]:(literal.(type))(); separator=", ">), collection);
232 Mutable<name>Collection collection1 = this.classUnderTest();
233 Assert.assertTrue(collection1.removeAll(this.newMutableCollectionWith(<["3", "2"]:(literal.(type))(); separator=", ">)));
234 Assert.assertEquals(this.newMutableCollectionWith(<["1"]:(literal.(type))(); separator=", ">), collection1);
235
236 Mutable<name>Collection collection2 = this.newWith(<["0", "1", "1", "2", "2", "2", "3"]:(literal.(type))(); separator=", ">);
237 Assert.assertFalse(collection2.removeAll(new <name>ArrayList()));
238 Assert.assertTrue(collection2.removeAll(<name>ArrayList.newListWith(<["0", "1"]:(literal.(type))(); separator=", ">)));
239 Assert.assertEquals(this.newMutableCollectionWith(<["2", "2", "2", "3"]:(literal.(type))(); separator=", ">), collection2);
240 Assert.assertFalse(collection2.removeAll(<name>ArrayList.newListWith(<(literal.(type))("0")>)));
241 Assert.assertTrue(collection2.removeAll(<name>ArrayList.newListWith(<(literal.(type))("2")>)));
242 Assert.assertEquals(this.newMutableCollectionWith(<["3"]:(literal.(type))(); separator=", ">), collection2);
243
244 Mutable<name>Collection collection3 = this.newWith(<["0", "1", "1", "2", "2", "2"]:(literal.(type))(); separator=", ">);
245 Assert.assertTrue(collection3.removeAll(<name>HashBag.newBagWith(<["0", "1", "1"]:(literal.(type))(); separator=", ">)));
246 Assert.assertEquals(this.newMutableCollectionWith(<["2", "2", "2"]:(literal.(type))(); separator=", ">), collection3);
247 }
248
249 @Test
250 public void retainAll()
251 {
252 Mutable<name>Collection collection = this.classUnderTest();
253 Assert.assertFalse(collection.retainAll(<["1", "2", "3"]:(literal.(type))(); separator=", ">));
254 Assert.assertEquals(this.newMutableCollectionWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">), collection);
255 Assert.assertTrue(collection.retainAll(<["1", "2", "5"]:(literal.(type))(); separator=", ">));
256 Assert.assertEquals(this.newMutableCollectionWith(<["1", "2"]:(literal.(type))(); separator=", ">), collection);
257
258 Mutable<name>Collection collection1 = this.classUnderTest();
259 Assert.assertTrue(collection1.retainAll(<["-3", "1"]:(literal.(type))(); separator=", ">));
260 Assert.assertEquals(this.newMutableCollectionWith(<["1"]:(literal.(type))(); separator=", ">), collection1);
261 Assert.assertTrue(collection1.retainAll(<(literal.(type))("-1")>));
262 Verify.assertEmpty(collection1);
263
264 Mutable<name>Collection collection2 = this.newWith(<["0", "1", "1", "2", "2", "2", "3", "3", "3"]:(literal.(type))(); separator=", ">);
265 Assert.assertFalse(collection2.retainAll(<["0", "1", "2", "3"]:(literal.(type))(); separator=", ">));
266 Assert.assertTrue(collection2.retainAll(<["0", "1", "3"]:(literal.(type))(); separator=", ">));
267 Assert.assertEquals(this.newMutableCollectionWith(<["0", "1", "1", "3", "3", "3"]:(literal.(type))(); separator=", ">), collection2);
268 Assert.assertFalse(collection2.retainAll(<["0", "1", "3"]:(literal.(type))(); separator=", ">));
269 Assert.assertTrue(collection2.retainAll(<["5", "3"]:(literal.(type))(); separator=", ">));
270 Assert.assertEquals(this.newMutableCollectionWith(<["3", "3", "3"]:(literal.(type))(); separator=", ">), collection2);
271
272 Mutable<name>Collection collection3 = this.newWith(<["0", "1", "1", "2", "2", "2"]:(literal.(type))(); separator=", ">);
273 Assert.assertTrue(collection3.retainAll(<["2", "8", "8", "2"]:(literal.(type))(); separator=", ">));
274 Assert.assertEquals(this.newMutableCollectionWith(<["2", "2", "2"]:(literal.(type))(); separator=", ">), collection3);
275
276 Mutable<name>Collection collection4 = this.classUnderTest();
277 Assert.assertTrue(collection4.retainAll());
278 Verify.assertEmpty(collection4);
279 }
280
281 @Test
282 public void retainAll_iterable()
283 {
284 Mutable<name>Collection collection = this.classUnderTest();
285 Assert.assertFalse(collection.retainAll(this.newMutableCollectionWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">)));
286 Assert.assertEquals(this.newMutableCollectionWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">), collection);
287 Assert.assertTrue(collection.retainAll(this.newMutableCollectionWith(<["1", "2", "5"]:(literal.(type))(); separator=", ">)));
288 Assert.assertEquals(this.newMutableCollectionWith(<["1", "2"]:(literal.(type))(); separator=", ">), collection);
289
290 Mutable<name>Collection collection1 = this.classUnderTest();
291 Assert.assertTrue(collection1.retainAll(this.newMutableCollectionWith(<["-3", "1"]:(literal.(type))(); separator=", ">)));
292 Assert.assertEquals(this.newMutableCollectionWith(<["1"]:(literal.(type))(); separator=", ">), collection1);
293 Assert.assertTrue(collection1.retainAll(this.newMutableCollectionWith(<(literal.(type))("-1")>)));
294 Verify.assertEmpty(collection1);
295
296 Mutable<name>Collection collection2 = this.newWith(<["0", "1", "1", "2", "2", "2", "3", "3", "3"]:(literal.(type))(); separator=", ">);
297 Assert.assertFalse(collection2.retainAll(this.newMutableCollectionWith(<["0", "1", "2", "3"]:(literal.(type))(); separator=", ">)));
298 Assert.assertTrue(collection2.retainAll(<name>ArrayList.newListWith(<["0", "1", "3"]:(literal.(type))(); separator=", ">)));
299 Assert.assertEquals(this.newMutableCollectionWith(<["0", "1", "1", "3", "3", "3"]:(literal.(type))(); separator=", ">), collection2);
300 Assert.assertFalse(collection2.retainAll(<name>ArrayList.newListWith(<["0", "1", "3"]:(literal.(type))(); separator=", ">)));
301 Assert.assertTrue(collection2.retainAll(<name>ArrayList.newListWith(<["5", "3"]:(literal.(type))(); separator=", ">)));
302 Assert.assertEquals(this.newMutableCollectionWith(<["3", "3", "3"]:(literal.(type))(); separator=", ">), collection2);
303
304 Mutable<name>Collection collection3 = this.newWith(<["0", "1", "1", "2", "2", "2"]:(literal.(type))(); separator=", ">);
305 Assert.assertTrue(collection3.retainAll(<name>HashBag.newBagWith(<["2", "8", "8", "2"]:(literal.(type))(); separator=", ">)));
306 Assert.assertEquals(this.newMutableCollectionWith(<["2", "2", "2"]:(literal.(type))(); separator=", ">), collection3);
307
308 Mutable<name>Collection collection4 = this.classUnderTest();
309 Assert.assertTrue(collection4.retainAll(new <name>ArrayList()));
310 Verify.assertEmpty(collection4);
311 }
312
313 @Test
314 public void with()
315 {
316 Mutable<name>Collection emptyCollection = this.newWith();
317 Mutable<name>Collection collection = emptyCollection.with(<["1"]:(literal.(type))(); separator=", ">);
318 Mutable<name>Collection collection0 = this.newWith().with(<(literal.(type))("1")>).with(<(literal.(type))("2")>);
319 Mutable<name>Collection collection1 = this.newWith().with(<(literal.(type))("1")>).with(<(literal.(type))("2")>).with(<(literal.(type))("3")>);
320 Mutable<name>Collection collection2 = this.newWith().with(<(literal.(type))("1")>).with(<(literal.(type))("2")>).with(<(literal.(type))("3")>).with(<(literal.(type))("4")>);
321 Mutable<name>Collection collection3 = this.newWith().with(<(literal.(type))("1")>).with(<(literal.(type))("2")>).with(<(literal.(type))("3")>).with(<(literal.(type))("4")>).with(<(literal.(type))("5")>);
322 Assert.assertSame(emptyCollection, collection);
323 Assert.assertEquals(this.newMutableCollectionWith(<(literal.(type))("1")>), collection);
324 Assert.assertEquals(this.newMutableCollectionWith(<["1", "2"]:(literal.(type))(); separator=", ">), collection0);
325 Assert.assertEquals(this.newMutableCollectionWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">), collection1);
326 Assert.assertEquals(this.newMutableCollectionWith(<["1", "2", "3", "4"]:(literal.(type))(); separator=", ">), collection2);
327 Assert.assertEquals(this.newMutableCollectionWith(<["1", "2", "3", "4", "5"]:(literal.(type))(); separator=", ">), collection3);
328 }
329
330 @Test
331 public void withAll()
332 {
333 Mutable<name>Collection emptyCollection = this.newWith();
334 Mutable<name>Collection collection = emptyCollection.withAll(this.newMutableCollectionWith(<(literal.(type))("1")>));
335 Mutable<name>Collection collection0 = this.newWith().withAll(this.newMutableCollectionWith(<["1", "2"]:(literal.(type))(); separator=", ">));
336 Mutable<name>Collection collection1 = this.newWith().withAll(this.newMutableCollectionWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">));
337 Mutable<name>Collection collection2 = this.newWith().withAll(this.newMutableCollectionWith(<["1", "2", "3", "4"]:(literal.(type))(); separator=", ">));
338 Mutable<name>Collection collection3 = this.newWith().withAll(this.newMutableCollectionWith(<["1", "2", "3", "4", "5"]:(literal.(type))(); separator=", ">));
339 Assert.assertSame(emptyCollection, collection);
340 Assert.assertEquals(this.newMutableCollectionWith(<(literal.(type))("1")>), collection);
341 Assert.assertEquals(this.newMutableCollectionWith(<["1", "2"]:(literal.(type))(); separator=", ">), collection0);
342 Assert.assertEquals(this.classUnderTest(), collection1);
343 Assert.assertEquals(this.newMutableCollectionWith(<["1", "2", "3", "4"]:(literal.(type))(); separator=", ">), collection2);
344 Assert.assertEquals(this.newMutableCollectionWith(<["1", "2", "3", "4", "5"]:(literal.(type))(); separator=", ">), collection3);
345 }
346
347 @Test
348 public void without()
349 {
350 Mutable<name>Collection collection = this.newWith(<["1", "2", "3", "4", "5"]:(literal.(type))(); separator=", ">);
351 Assert.assertSame(collection, collection.without(<(literal.(type))("9")>));
352 Assert.assertEquals(this.newMutableCollectionWith(<["1", "2", "3", "4", "5"]:(literal.(type))(); separator=", ">), collection.without(<(literal.(type))("9")>));
353 Assert.assertEquals(this.newMutableCollectionWith(<["2", "3", "4", "5"]:(literal.(type))(); separator=", ">), collection.without(<(literal.(type))("1")>));
354 Assert.assertEquals(this.newMutableCollectionWith(<["3", "4", "5"]:(literal.(type))(); separator=", ">), collection.without(<(literal.(type))("2")>));
355 Assert.assertEquals(this.newMutableCollectionWith(<["4", "5"]:(literal.(type))(); separator=", ">), collection.without(<(literal.(type))("3")>));
356 Assert.assertEquals(this.newMutableCollectionWith(<(literal.(type))("5")>), collection.without(<(literal.(type))("4")>));
357 Assert.assertEquals(this.newMutableCollectionWith(), collection.without(<(literal.(type))("5")>));
358 Assert.assertEquals(this.newMutableCollectionWith(), collection.without(<(literal.(type))("6")>));
359 }
360
361 @Test
362 public void withoutAll()
363 {
364 Mutable<name>Collection collection = this.newWith(<["1", "2", "3", "4", "5"]:(literal.(type))(); separator=", ">);
365 Assert.assertSame(collection, collection.withoutAll(this.newMutableCollectionWith(<["8", "9"]:(literal.(type))(); separator=", ">)));
366 Assert.assertEquals(this.newMutableCollectionWith(<["1", "2", "3", "4", "5"]:(literal.(type))(); separator=", ">), collection.withoutAll(this.newMutableCollectionWith(<["8", "9"]:(literal.(type))(); separator=", ">)));
367 Assert.assertEquals(this.newMutableCollectionWith(<["2", "3", "4"]:(literal.(type))(); separator=", ">), collection.withoutAll(this.newMutableCollectionWith(<["1", "5"]:(literal.(type))(); separator=", ">)));
368 Assert.assertEquals(this.newMutableCollectionWith(<["3", "4"]:(literal.(type))(); separator=", ">), collection.withoutAll(this.newMutableCollectionWith(<["2", "20"]:(literal.(type))(); separator=", ">)));
369 Assert.assertEquals(this.newMutableCollectionWith(), collection.withoutAll(this.newMutableCollectionWith(<["3", "4"]:(literal.(type))(); separator=", ">)));
370 Assert.assertEquals(this.newMutableCollectionWith(), collection.withoutAll(this.newMutableCollectionWith(<(literal.(type))("9")>)));
371
372 Mutable<name>Collection collection1 = this.newWith(<["0", "1", "1", "2", "2", "2"]:(literal.(type))(); separator=", ">);
373 Assert.assertEquals(this.newMutableCollectionWith(<["2", "2", "2"]:(literal.(type))(); separator=", ">), collection1.withoutAll(<name>HashBag.newBagWith(<["0", "1"]:(literal.(type))(); separator=", ">)));
374 }
375
376 @Test
377 public void asSynchronized()
378 {
379 Mutable<name>Collection collection = this.classUnderTest();
380 Assert.assertEquals(collection, collection.asSynchronized());
381 Verify.assertInstanceOf(this.newWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">).asSynchronized().getClass(), this.classUnderTest().asSynchronized());
382
383 Mutable<name>Collection collection1 = this.newWith(<["1", "2", "2", "3", "3", "3"]:(literal.(type))(); separator=", ">);
384 Mutable<name>Collection synchronizedCollection = this.newWith(<["1", "2", "2", "3", "3", "3"]:(literal.(type))(); separator=", ">).asSynchronized();
385 Verify.assertInstanceOf(synchronizedCollection.getClass(), collection1.asSynchronized());
386 Assert.assertEquals(synchronizedCollection, collection1.asSynchronized());
387 }
388
389 @Test
390 public void asUnmodifiable()
391 {
392 Verify.assertInstanceOf(this.newWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">).asUnmodifiable().getClass(), this.classUnderTest().asUnmodifiable());
393 Assert.assertEquals(this.newWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">).asUnmodifiable(), this.classUnderTest().asUnmodifiable());
394
395 Mutable<name>Collection collection = this.newWith(<["1", "2", "2", "3", "3", "3"]:(literal.(type))(); separator=", ">);
396 Mutable<name>Collection unmodifiableCollection = this.newWith(<["1", "2", "2", "3", "3", "3"]:(literal.(type))(); separator=", ">).asUnmodifiable();
397 Verify.assertInstanceOf(unmodifiableCollection.getClass(), collection.asUnmodifiable());
398 Assert.assertEquals(unmodifiableCollection, collection.asUnmodifiable());
399 }
400
401 @Override
402 @Test(expected = NoSuchElementException.class)
403 public void <type>Iterator_throws_non_empty_collection()
404 {
405 super.<type>Iterator_throws_non_empty_collection();
406 Mutable<name>Collection collection = this.newWith();
407 collection.add(<(literal.(type))("1")>);
408 collection.add(<(literal.(type))("2")>);
409 collection.add(<(literal.(type))("3")>);
410 <name>Iterator iterator = collection.<type>Iterator();
411 while (iterator.hasNext())
412 {
413 iterator.next();
414 }
415 iterator.next();
416 }
417
418 @Test
419 public void <type>Iterator_with_remove()
420 {
421 Mutable<name>Collection <type>Iterable = this.newWith(<["0", "1", "31", "32"]:(literal.(type))(); separator=", ">);
422 Mutable<name>Iterator iterator = <type>Iterable.<type>Iterator();
423 while (iterator.hasNext())
424 {
425 iterator.next();
426 iterator.remove();
427 }
428 Verify.assertEmpty(<type>Iterable);
429 Assert.assertThrows(NoSuchElementException.class, iterator::next);
430 }
431
432 @Test
433 public void <type>Iterator_throws_for_remove_before_next()
434 {
435 Mutable<name>Collection <type>Iterable = this.classUnderTest();
436 Mutable<name>Iterator iterator = <type>Iterable.<type>Iterator();
437 Assert.assertTrue(iterator.hasNext());
438 Assert.assertThrows(IllegalStateException.class, iterator::remove);
439 }
440
441 @Test
442 public void <type>Iterator_throws_for_consecutive_remove()
443 {
444 Mutable<name>Collection <type>Iterable = this.classUnderTest();
445 Mutable<name>Iterator iterator = <type>Iterable.<type>Iterator();
446 Assert.assertTrue(iterator.hasNext());
447 iterator.next();
448 iterator.remove();
449 Assert.assertThrows(IllegalStateException.class, iterator::remove);
450 }
451
452 /**
453 * @since 9.2.
454 */
455 @Test
456 public void newEmpty()
457 {
458 Assert.assertTrue(this.classUnderTest().newEmpty().isEmpty());
459 Assert.assertNotSame(this.classUnderTest(), this.classUnderTest().newEmpty());
460 }
461 }
462
463 >>