1
1
/*
2
- * Copyright 2002-2014 the original author or authors.
2
+ * Copyright 2002-2018 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
35
35
import java .util .TreeSet ;
36
36
37
37
import org .junit .Test ;
38
+
38
39
import org .springframework .util .LinkedMultiValueMap ;
39
40
import org .springframework .util .MultiValueMap ;
40
41
41
- import static org .hamcrest .CoreMatchers .*;
42
+ import static org .hamcrest .Matchers .*;
42
43
import static org .junit .Assert .*;
43
44
import static org .springframework .core .CollectionFactory .*;
44
45
@@ -103,7 +104,7 @@ public void createCollectionIsNotTypeSafeForEnumSet() {
103
104
* {@link CollectionFactory#createApproximateMap(Object, int)}
104
105
* is not type-safe.
105
106
* <p>The reasoning is similar that described in
106
- * {@link #createApproximateCollectionIsNotTypeSafe() }.
107
+ * {@link #createApproximateCollectionIsNotTypeSafeForEnumSet }.
107
108
*/
108
109
@ Test
109
110
public void createApproximateMapIsNotTypeSafeForEnumMap () {
@@ -165,27 +166,27 @@ public void createMapIsNotTypeSafeForLinkedMultiValueMap() {
165
166
@ Test
166
167
public void createApproximateCollectionFromEmptyHashSet () {
167
168
Collection <String > set = createApproximateCollection (new HashSet <String >(), 2 );
168
- assertThat (set . size () , is (0 ));
169
+ assertThat (set , is (empty () ));
169
170
}
170
171
171
172
@ Test
172
173
public void createApproximateCollectionFromNonEmptyHashSet () {
173
- HashSet <String > hashSet = new HashSet <String >();
174
+ HashSet <String > hashSet = new HashSet <>();
174
175
hashSet .add ("foo" );
175
176
Collection <String > set = createApproximateCollection (hashSet , 2 );
176
- assertThat (set . size () , is (0 ));
177
+ assertThat (set , is (empty () ));
177
178
}
178
179
179
180
@ Test
180
181
public void createApproximateCollectionFromEmptyEnumSet () {
181
182
Collection <Color > colors = createApproximateCollection (EnumSet .noneOf (Color .class ), 2 );
182
- assertThat (colors . size () , is (0 ));
183
+ assertThat (colors , is (empty () ));
183
184
}
184
185
185
186
@ Test
186
187
public void createApproximateCollectionFromNonEmptyEnumSet () {
187
188
Collection <Color > colors = createApproximateCollection (EnumSet .of (Color .BLUE ), 2 );
188
- assertThat (colors . size () , is (0 ));
189
+ assertThat (colors , is (empty () ));
189
190
}
190
191
191
192
@ Test
@@ -196,7 +197,7 @@ public void createApproximateMapFromEmptyHashMap() {
196
197
197
198
@ Test
198
199
public void createApproximateMapFromNonEmptyHashMap () {
199
- Map <String , String > hashMap = new HashMap <String , String >();
200
+ Map <String , String > hashMap = new HashMap <>();
200
201
hashMap .put ("foo" , "bar" );
201
202
Map <String , String > map = createApproximateMap (hashMap , 2 );
202
203
assertThat (map .size (), is (0 ));
@@ -210,7 +211,7 @@ public void createApproximateMapFromEmptyEnumMap() {
210
211
211
212
@ Test
212
213
public void createApproximateMapFromNonEmptyEnumMap () {
213
- EnumMap <Color , String > enumMap = new EnumMap <Color , String >(Color .class );
214
+ EnumMap <Color , String > enumMap = new EnumMap <>(Color .class );
214
215
enumMap .put (Color .BLUE , "blue" );
215
216
Map <Color , String > colors = createApproximateMap (enumMap , 2 );
216
217
assertThat (colors .size (), is (0 ));
@@ -241,6 +242,12 @@ public void createsEnumSet() {
241
242
assertThat (createCollection (EnumSet .class , Color .class , 0 ), is (instanceOf (EnumSet .class )));
242
243
}
243
244
245
+ @ Test // SPR-17619
246
+ public void createsEnumSetSubclass () {
247
+ EnumSet <Color > enumSet = EnumSet .noneOf (Color .class );
248
+ assertThat (createCollection (enumSet .getClass (), Color .class , 0 ), is (instanceOf (enumSet .getClass ())));
249
+ }
250
+
244
251
@ Test (expected = IllegalArgumentException .class )
245
252
public void rejectsInvalidElementTypeForEnumSet () {
246
253
createCollection (EnumSet .class , Object .class , 0 );
@@ -296,7 +303,8 @@ public void rejectsNullMapType() {
296
303
}
297
304
298
305
299
- static enum Color {
306
+ enum Color {
300
307
RED , BLUE ;
301
308
}
309
+
302
310
}
0 commit comments