-
Notifications
You must be signed in to change notification settings - Fork 587
/
unmodifiablePrimitiveBooleanMapValuesTest.stg
392 lines (340 loc) · 13.3 KB
/
unmodifiablePrimitiveBooleanMapValuesTest.stg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
import "copyright.stg"
import "primitiveEquals.stg"
import "primitiveHashCode.stg"
import "primitiveLiteral.stg"
skipBoolean() ::= "true"
isTest() ::= "true"
targetPath() ::= "org/eclipse/collections/impl/map/mutable/primitive"
fileName(primitive) ::= "Unmodifiable<primitive.name>BooleanMapValuesTest"
class(primitive) ::= <<
<body(primitive.type, primitive.name)>
>>
body(type, name) ::= <<
<copyright()>
package org.eclipse.collections.impl.map.mutable.primitive;
import java.util.NoSuchElementException;
import org.eclipse.collections.api.BooleanIterable;
import org.eclipse.collections.api.bag.MutableBag;
import org.eclipse.collections.api.block.function.primitive.BooleanToObjectFunction;
import org.eclipse.collections.api.collection.primitive.MutableBooleanCollection;
import org.eclipse.collections.api.iterator.BooleanIterator;
import org.eclipse.collections.api.iterator.MutableBooleanIterator;
import org.eclipse.collections.impl.bag.mutable.HashBag;
import org.eclipse.collections.impl.factory.Lists;
import org.eclipse.collections.impl.factory.primitive.BooleanBags;
import org.eclipse.collections.impl.block.factory.primitive.BooleanPredicates;
import org.eclipse.collections.impl.collection.mutable.primitive.AbstractMutableBooleanCollectionTestCase;
import org.eclipse.collections.impl.collection.mutable.primitive.SynchronizedBooleanCollection;
import org.eclipse.collections.impl.collection.mutable.primitive.UnmodifiableBooleanCollection;
import org.eclipse.collections.impl.list.mutable.primitive.BooleanArrayList;
import org.eclipse.collections.impl.test.Verify;
import org.junit.Assert;
import org.junit.Test;
/**
* JUnit test for {@link Unmodifiable<name>BooleanMap#values()}.
* This file was automatically generated from template file unmodifiablePrimitiveBooleanMapValuesTest.stg.
*/
public class Unmodifiable<name>BooleanMapValuesTest extends AbstractMutableBooleanCollectionTestCase
{
@Override
protected MutableBooleanCollection classUnderTest()
{
return new Unmodifiable<name>BooleanMap(<name>BooleanHashMap.newWithKeysValues(<(literal.(type))("1")>, true, <(literal.(type))("2")>, false, <(literal.(type))("3")>, true)).values();
}
@Override
protected MutableBooleanCollection newWith(boolean... elements)
{
<name>BooleanHashMap map = new <name>BooleanHashMap();
for (int i = 0; i \< elements.length; i++)
{
map.put(<(castIntToNarrowType.(type))("i")>, elements[i]);
}
return map.asUnmodifiable().values();
}
@Override
protected MutableBooleanCollection newMutableCollectionWith(boolean... elements)
{
return this.newWith(elements);
}
@Override
protected MutableBag\<Object> newObjectCollectionWith(Object... elements)
{
return HashBag.newBagWith(elements);
}
@Override
@Test
public void booleanIterator()
{
MutableBooleanCollection collection = this.newWith(true, false, false, true, true, true);
BooleanArrayList list = BooleanArrayList.newListWith(true, false, false, true, true, true);
BooleanIterator iterator = collection.booleanIterator();
for (int i = 0; i \< 6; i++)
{
Assert.assertTrue(iterator.hasNext());
Assert.assertTrue(list.remove(iterator.next()));
}
Verify.assertEmpty(list);
Assert.assertFalse(iterator.hasNext());
Verify.assertThrows(NoSuchElementException.class, iterator::next);
}
@Override
@Test(expected = UnsupportedOperationException.class)
public void addAllIterable()
{
this.classUnderTest().addAll(new BooleanArrayList());
}
@Override
@Test(expected = UnsupportedOperationException.class)
public void add()
{
this.classUnderTest().add(false);
}
@Override
@Test(expected = UnsupportedOperationException.class)
public void addAllArray()
{
this.classUnderTest().addAll(true, false);
}
@Override
@Test(expected = UnsupportedOperationException.class)
public void with()
{
this.classUnderTest().with(true);
}
@Override
@Test(expected = UnsupportedOperationException.class)
public void without()
{
this.classUnderTest().without(false);
}
@Override
@Test(expected = UnsupportedOperationException.class)
public void withAll()
{
this.classUnderTest().withAll(new BooleanArrayList());
}
@Override
@Test(expected = UnsupportedOperationException.class)
public void withoutAll()
{
this.classUnderTest().withoutAll(new BooleanArrayList());
}
@Override
@Test
public void remove()
{
<name>BooleanHashMap map = <name>BooleanHashMap.newWithKeysValues(<(literal.(type))("1")>, true, <(literal.(type))("2")>, false, <(literal.(type))("3")>, true);
MutableBooleanCollection collection = map.values();
Assert.assertTrue(collection.remove(false));
Assert.assertFalse(collection.contains(false));
Assert.assertTrue(collection.contains(true));
Assert.assertFalse(map.contains(false));
Assert.assertTrue(map.contains(true));
}
@Override
@Test
public void containsAllArray()
{
MutableBooleanCollection emptyCollection = this.newWith();
Assert.assertTrue(emptyCollection.containsAll());
Assert.assertFalse(emptyCollection.containsAll(true));
Assert.assertFalse(emptyCollection.containsAll(false));
MutableBooleanCollection classUnderTest = this.classUnderTest();
Assert.assertTrue(classUnderTest.containsAll());
Assert.assertTrue(classUnderTest.containsAll(true));
Assert.assertTrue(classUnderTest.containsAll(false));
Assert.assertTrue(classUnderTest.containsAll(false, true));
}
@Override
@Test
public void asUnmodifiable()
{
MutableBooleanCollection collection = this.classUnderTest();
Verify.assertInstanceOf(UnmodifiableBooleanCollection.class, collection.asUnmodifiable());
Assert.assertTrue(collection.asUnmodifiable().containsAll(this.classUnderTest()));
}
@Override
@Test
public void containsAllIterable()
{
MutableBooleanCollection emptyCollection = this.newWith();
Assert.assertTrue(emptyCollection.containsAll(new BooleanArrayList()));
Assert.assertFalse(emptyCollection.containsAll(BooleanArrayList.newListWith(true)));
Assert.assertFalse(emptyCollection.containsAll(BooleanArrayList.newListWith(false)));
MutableBooleanCollection classUnderTest = this.classUnderTest();
Assert.assertTrue(classUnderTest.containsAll(new BooleanArrayList()));
Assert.assertTrue(classUnderTest.containsAll(BooleanArrayList.newListWith(true)));
Assert.assertTrue(classUnderTest.containsAll(BooleanArrayList.newListWith(false)));
Assert.assertTrue(classUnderTest.containsAll(BooleanArrayList.newListWith(false, true)));
}
@Override
@Test (expected = UnsupportedOperationException.class)
public void removeAll()
{
this.newWith().removeAll();
}
@Override
@Test (expected = UnsupportedOperationException.class)
public void removeAll_iterable()
{
this.newWith().removeAll(BooleanArrayList.newListWith(false, true));
}
@Override
@Test (expected = UnsupportedOperationException.class)
public void retainAll()
{
this.newWith().retainAll();
}
@Override
@Test (expected = UnsupportedOperationException.class)
public void retainAll_iterable()
{
this.newWith().retainAll(BooleanArrayList.newListWith(false, true));
}
@Override
@Test (expected = UnsupportedOperationException.class)
public void clear()
{
MutableBooleanCollection emptyCollection = this.newWith();
emptyCollection.clear();
}
@Override
@Test
public void contains()
{
BooleanIterable emptyCollection = this.newWith();
Assert.assertFalse(emptyCollection.contains(true));
Assert.assertFalse(emptyCollection.contains(false));
BooleanIterable booleanIterable = this.classUnderTest();
int size = booleanIterable.size();
Assert.assertTrue(booleanIterable.contains(true));
Assert.assertTrue(booleanIterable.contains(false));
Assert.assertFalse(this.newWith(true, true, true).contains(false));
Assert.assertFalse(this.newWith(false, false, false).contains(true));
}
@Override
@Test
public void reject()
{
BooleanIterable iterable = this.classUnderTest();
Verify.assertSize(1, iterable.reject(BooleanPredicates.isTrue()));
Verify.assertSize(2, iterable.reject(BooleanPredicates.isFalse()));
}
@Override
@Test
public void select()
{
BooleanIterable iterable = this.classUnderTest();
Verify.assertSize(1, iterable.select(BooleanPredicates.isFalse()));
Verify.assertSize(2, iterable.select(BooleanPredicates.isTrue()));
}
@Override
@Test
public void collect()
{
BooleanToObjectFunction\<Integer> function = (boolean parameter) -> parameter ? 1 : 0;
Assert.assertEquals(this.newObjectCollectionWith(1, 0, 1).toBag(), this.newWith(true, false, true).collect(function).toBag());
Assert.assertEquals(this.newObjectCollectionWith(), this.newWith().collect(function));
}
@Override
@Test
public void appendString()
{
StringBuilder appendable = new StringBuilder();
this.newWith().appendString(appendable);
Assert.assertEquals("", appendable.toString());
this.newWith().appendString(appendable, "/");
Assert.assertEquals("", appendable.toString());
this.newWith().appendString(appendable, "[", "/", "]");
Assert.assertEquals("[]", appendable.toString());
StringBuilder appendable1 = new StringBuilder();
this.newWith(true).appendString(appendable1);
Assert.assertEquals("true", appendable1.toString());
StringBuilder appendable2 = new StringBuilder();
BooleanIterable iterable = this.newWith(true, false);
iterable.appendString(appendable2);
Assert.assertTrue("true, false".equals(appendable2.toString())
|| "false, true".equals(appendable2.toString()));
StringBuilder appendable3 = new StringBuilder();
iterable.appendString(appendable3, "/");
Assert.assertTrue("true/false".equals(appendable3.toString())
|| "false/true".equals(appendable3.toString()));
}
@Override
@Test
public void chunk()
{
BooleanIterable iterable1 = this.newWith(true);
Verify.assertIterablesEqual(
Lists.mutable.with(BooleanBags.mutable.with(true)).toSet(),
iterable1.chunk(1).toSet());
BooleanIterable iterable2 = this.newWith(false);
Verify.assertIterablesEqual(
Lists.mutable.with(BooleanBags.mutable.with(false)).toSet(),
iterable2.chunk(1).toSet());
BooleanIterable iterable3 = this.newWith(false, true);
Verify.assertIterablesEqual(
Lists.mutable.with(BooleanBags.mutable.with(false), BooleanBags.mutable.with(true)).toSet(),
iterable3.chunk(1).toSet());
Verify.assertIterablesEqual(
Lists.mutable.with(BooleanBags.mutable.with(false, true)),
iterable3.chunk(2));
Verify.assertIterablesEqual(
Lists.mutable.with(BooleanBags.mutable.with(false, true)),
iterable3.chunk(3));
Verify.assertThrows(IllegalArgumentException.class, () -> this.classUnderTest().chunk(0));
Verify.assertThrows(IllegalArgumentException.class, () -> this.classUnderTest().chunk(-1));
}
@Override
@Test
public void asSynchronized()
{
MutableBooleanCollection booleanCollection = this.classUnderTest().asSynchronized();
Verify.assertInstanceOf(SynchronizedBooleanCollection.class, booleanCollection);
}
@Override
@Test
public void testEquals()
{
//Testing equals() is not applicable for MutableBooleanCollection.
}
@Override
public void testToString()
{
//Testing toString() is not applicable for MutableBooleanCollection.
}
@Override
public void testHashCode()
{
//Testing hashCode() is not applicable for MutableBooleanCollection.
}
@Override
public void newCollection()
{
//Testing newCollection() is not applicable for MutableBooleanCollection.
}
@Override
@Test
public void booleanIterator_with_remove()
{
MutableBooleanIterator booleanIterator = this.classUnderTest().booleanIterator();
Assert.assertTrue(booleanIterator.hasNext());
booleanIterator.next();
Verify.assertThrows(UnsupportedOperationException.class, booleanIterator::remove);
}
@Override
@Test
public void iterator_throws_on_invocation_of_remove_before_next()
{
MutableBooleanIterator booleanIterator = this.classUnderTest().booleanIterator();
Assert.assertTrue(booleanIterator.hasNext());
Verify.assertThrows(UnsupportedOperationException.class, booleanIterator::remove);
}
@Override
@Test
public void iterator_throws_on_consecutive_invocation_of_remove()
{
// Not applicable for Unmodifiable*
}
}
>>