-
Notifications
You must be signed in to change notification settings - Fork 586
/
unmodifiableObjectPrimitiveMapTest.stg
314 lines (259 loc) · 10.8 KB
/
unmodifiableObjectPrimitiveMapTest.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
import "copyright.stg"
import "primitiveHashCode.stg"
import "primitiveLiteral.stg"
import "primitiveEquals.stg"
skipBoolean() ::= "true"
isTest() ::= "true"
targetPath() ::= "org/eclipse/collections/impl/map/mutable/primitive"
fileName(primitive) ::= "UnmodifiableObject<primitive.name>MapTest"
class(primitive) ::= <<
<body(primitive.type, primitive.name, primitive.wrapperName)>
>>
body(type, name, wrapperName) ::= <<
<copyright()>
package org.eclipse.collections.impl.map.mutable.primitive;
import org.eclipse.collections.api.block.function.primitive.<name>Function;
import org.eclipse.collections.api.block.function.primitive.<name>Function0;
import org.eclipse.collections.api.block.function.primitive.<name>To<name>Function;
import org.eclipse.collections.api.map.primitive.MutableObject<name>Map;
import org.eclipse.collections.impl.list.mutable.FastList;
import org.eclipse.collections.impl.test.Verify;
import org.junit.Assert;
import org.junit.Test;
/**
* JUnit test for {@link UnmodifiableObject<name>Map}.
* This file was automatically generated from template file unmodifiableObjectPrimitiveMapTest.stg.
*/
public class UnmodifiableObject<name>MapTest extends AbstractMutableObject<name>MapTestCase
{
private final UnmodifiableObject<name>Map\<String> map = this.classUnderTest();
@Override
protected UnmodifiableObject<name>Map\<String> classUnderTest()
{
return new UnmodifiableObject<name>Map\<>(Object<name>HashMap.newWithKeysValues("0", <(literal.(type))("0")>, "1", <(literal.(type))("1")>, "2", <(literal.(type))("2")>));
}
@Override
protected \<T> UnmodifiableObject<name>Map\<T> newWithKeysValues(T key1, <type> value1)
{
return new UnmodifiableObject<name>Map\<>(Object<name>HashMap.newWithKeysValues(key1, value1));
}
@Override
protected \<T> UnmodifiableObject<name>Map\<T> newWithKeysValues(T key1, <type> value1, T key2, <type> value2)
{
return new UnmodifiableObject<name>Map\<>(Object<name>HashMap.newWithKeysValues(key1, value1, key2, value2));
}
@Override
protected \<T> UnmodifiableObject<name>Map\<T> newWithKeysValues(T key1, <type> value1, T key2, <type> value2, T key3, <type> value3)
{
return new UnmodifiableObject<name>Map\<>(Object<name>HashMap.newWithKeysValues(key1, value1, key2, value2, key3, value3));
}
@Override
protected \<T> UnmodifiableObject<name>Map\<T> newWithKeysValues(T key1, <type> value1, T key2, <type> value2, T key3, <type> value3, T key4, <type> value4)
{
return new UnmodifiableObject<name>Map\<>(Object<name>HashMap.newWithKeysValues(key1, value1, key2, value2, key3, value3, key4, value4));
}
@Override
protected \<T> UnmodifiableObject<name>Map\<T> getEmptyMap()
{
return new UnmodifiableObject<name>Map\<>(new Object<name>HashMap\<>());
}
@Override
@Test
public void asUnmodifiable()
{
super.asUnmodifiable();
Assert.assertSame(this.map, this.map.asUnmodifiable());
}
@Override
@Test(expected = UnsupportedOperationException.class)
public void clear()
{
this.map.clear();
}
@Override
@Test(expected = UnsupportedOperationException.class)
public void removeKey()
{
this.map.removeKey("0");
}
@Override
@Test(expected = UnsupportedOperationException.class)
public void remove()
{
this.map.remove("0");
}
@Override
@Test(expected = UnsupportedOperationException.class)
public void put()
{
this.map.put("0", <(literal.(type))("1")>);
}
@Override
@Test(expected = UnsupportedOperationException.class)
public void withKeysValues()
{
this.map.withKeyValue("1", <(literal.(type))("0")>);
}
@Override
@Test(expected = UnsupportedOperationException.class)
public void withoutKey()
{
this.map.withoutKey("0");
}
@Override
@Test(expected = UnsupportedOperationException.class)
public void withoutAllKeys()
{
this.map.withoutAllKeys(FastList.newListWith("0", "1"));
}
@Override
@Test(expected = UnsupportedOperationException.class)
public void putDuplicateWithRemovedSlot()
{
String collision1 = AbstractMutableObject<name>MapTestCase.generateCollisions().getFirst();
this.getEmptyMap().put(collision1, <(literal.(type))("1")>);
}
@Override
@Test
public void get()
{
Assert.assertEquals(<(wideLiteral.(type))("0")>, this.map.get("0")<delta.(type)>);
Assert.assertEquals(<(wideLiteral.(type))("1")>, this.map.get("1")<delta.(type)>);
Assert.assertEquals(<(wideLiteral.(type))("2")>, this.map.get("2")<delta.(type)>);
Assert.assertEquals(<(wideLiteral.(type))("0")>, this.map.get("5")<delta.(type)>);
}
@Override
@Test
public void getIfAbsent()
{
Assert.assertEquals(<(wideLiteral.(type))("0")>, this.map.getIfAbsent("0", <(literal.(type))("1")>)<delta.(type)>);
Assert.assertEquals(<(wideLiteral.(type))("1")>, this.map.getIfAbsent("1", <(literal.(type))("2")>)<delta.(type)>);
Assert.assertEquals(<(wideLiteral.(type))("2")>, this.map.getIfAbsent("2", <(literal.(type))("3")>)<delta.(type)>);
Assert.assertEquals(<(wideLiteral.(type))("4")>, this.map.getIfAbsent("3", <(literal.(type))("4")>)<delta.(type)>);
}
@Override
@Test
public void getIfAbsentPut_Value()
{
Assert.assertEquals(<(wideLiteral.(type))("0")>, this.map.getIfAbsentPut("0", <(literal.(type))("100")>)<delta.(type)>);
}
@Test(expected = UnsupportedOperationException.class)
public void getIfAbsentPut_ValueThrowsException()
{
this.map.getIfAbsentPut("10", <(literal.(type))("100")>);
}
@Override
@Test
public void getIfAbsentPut_Function()
{
<name>Function0 factory = () -> <(literal.(type))("100")>;
Assert.assertEquals(<(wideLiteral.(type))("0")>, this.map.getIfAbsentPut("0", factory)<delta.(type)>);
}
@Test(expected = UnsupportedOperationException.class)
public void getIfAbsentPut_FunctionThrowsException()
{
<name>Function0 factory = () -> { throw new AssertionError(); };
this.map.getIfAbsentPut("10", factory);
}
@Override
@Test
public void getIfAbsentPutWith()
{
<name>Function\<String> functionLength = (String string) -> <(castIntToNarrowType.(type))("string.length()")>;
Assert.assertEquals(<(wideLiteral.(type))("0")>, this.map.getIfAbsentPutWith("0", functionLength, "123456789")<delta.(type)>);
}
@Test(expected = UnsupportedOperationException.class)
public void getIfAbsentPutWithThrowsException()
{
<name>Function\<String> functionLength = (String string) -> { throw new AssertionError(); };
this.map.getIfAbsentPutWith("10", functionLength, "123456789");
}
@Override
@Test
public void getIfAbsentPutWithKey()
{
<name>Function\<Integer> function = (Integer anObject) -> anObject == null ? <(literal.(type))("32")> : <(castIntToNarrowType.(type))("anObject.intValue()")>;
Assert.assertEquals(<(wideLiteral.(type))("0")>, this.newWithKeysValues(0, <(literal.(type))("0")>).getIfAbsentPutWithKey(0, function)<delta.(type)>);
}
@Test(expected = UnsupportedOperationException.class)
public void getIfAbsentPutWithKeyThrowsException()
{
<name>Function\<Integer> function = (Integer anObject) -> { throw new AssertionError(); };
this.\<Integer>getEmptyMap().getIfAbsentPutWithKey(10, function);
}
@Override
@Test(expected = UnsupportedOperationException.class)
public void addToValue()
{
this.\<Integer>getEmptyMap().addToValue(10, <(literal.(type))("2")>);
}
@Override
@Test(expected = UnsupportedOperationException.class)
public void updateValue()
{
<name>To<name>Function incrementFunction = (<type> value) -> { throw new AssertionError(); };
MutableObject<name>Map\<Integer> map1 = this.getEmptyMap();
map1.updateValue(0, <(literal.(type))("0")>, incrementFunction);
}
@Override
@Test
public void getOrThrow()
{
Assert.assertEquals(<(wideLiteral.(type))("0")>, this.map.getOrThrow("0")<delta.(type)>);
Assert.assertEquals(<(wideLiteral.(type))("1")>, this.map.getOrThrow("1")<delta.(type)>);
Assert.assertEquals(<(wideLiteral.(type))("2")>, this.map.getOrThrow("2")<delta.(type)>);
Verify.assertThrows(IllegalStateException.class, () -> this.map.getOrThrow("5"));
Verify.assertThrows(IllegalStateException.class, () -> this.map.getOrThrow(null));
}
@Override
@Test
public void contains()
{
Assert.assertTrue(this.map.contains(<(literal.(type))("0")>));
Assert.assertTrue(this.map.contains(<(literal.(type))("1")>));
Assert.assertTrue(this.map.contains(<(literal.(type))("2")>));
Assert.assertFalse(this.getEmptyMap().contains(<(literal.(type))("0")>));
Assert.assertFalse(this.newWithKeysValues("0", <(literal.(type))("0")>).contains(<(literal.(type))("1")>));
}
@Override
@Test
public void containsKey()
{
Assert.assertTrue(this.map.containsKey("0"));
Assert.assertTrue(this.map.containsKey("1"));
Assert.assertTrue(this.map.containsKey("2"));
Assert.assertFalse(this.map.containsKey("3"));
Assert.assertFalse(this.map.containsKey(null));
}
@Override
@Test
public void containsValue()
{
Assert.assertTrue(this.map.containsValue(<(literal.(type))("0")>));
Assert.assertTrue(this.map.containsValue(<(literal.(type))("1")>));
Assert.assertTrue(this.map.containsValue(<(literal.(type))("2")>));
Assert.assertFalse(this.getEmptyMap().contains(<(literal.(type))("2")>));
Assert.assertFalse(this.newWithKeysValues("0", <(literal.(type))("1")>).contains(<(literal.(type))("2")>));
}
@Override
@Test
public void size()
{
Verify.assertSize(0, this.getEmptyMap());
Verify.assertSize(1, this.newWithKeysValues(0, <(literal.(type))("0")>));
Verify.assertSize(1, this.newWithKeysValues(1, <(literal.(type))("1")>));
Verify.assertSize(1, this.newWithKeysValues(null, <(literal.(type))("2")>));
Verify.assertSize(2, this.newWithKeysValues(1, <(literal.(type))("1")>, 5, <(literal.(type))("5")>));
Verify.assertSize(2, this.newWithKeysValues(0, <(literal.(type))("0")>, 5, <(literal.(type))("5")>));
Verify.assertSize(3, this.newWithKeysValues(1, <(literal.(type))("1")>, 0, <(literal.(type))("0")>, 5, <(literal.(type))("5")>));
Verify.assertSize(2, this.newWithKeysValues(6, <(literal.(type))("6")>, 5, <(literal.(type))("5")>));
}
@Override
@Test
public void flipUniqueValues()
{
super.flipUniqueValues();
Verify.assertInstanceOf(Unmodifiable<name>ObjectMap.class, this.classUnderTest().flipUniqueValues());
}
}
>>