|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2022 the original author or authors. |
| 2 | + * Copyright 2002-2023 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.
|
@@ -209,21 +209,23 @@ void createApproximateMapFromNonEmptyEnumMap() {
|
209 | 209 | @Test
|
210 | 210 | void createsCollectionsCorrectly() {
|
211 | 211 | // interfaces
|
212 |
| - assertThat(createCollection(List.class, 0)).isInstanceOf(ArrayList.class); |
213 |
| - assertThat(createCollection(Set.class, 0)).isInstanceOf(LinkedHashSet.class); |
214 |
| - assertThat(createCollection(Collection.class, 0)).isInstanceOf(LinkedHashSet.class); |
215 |
| - assertThat(createCollection(SortedSet.class, 0)).isInstanceOf(TreeSet.class); |
216 |
| - assertThat(createCollection(NavigableSet.class, 0)).isInstanceOf(TreeSet.class); |
217 |
| - |
218 |
| - assertThat(createCollection(List.class, String.class, 0)).isInstanceOf(ArrayList.class); |
219 |
| - assertThat(createCollection(Set.class, String.class, 0)).isInstanceOf(LinkedHashSet.class); |
220 |
| - assertThat(createCollection(Collection.class, String.class, 0)).isInstanceOf(LinkedHashSet.class); |
221 |
| - assertThat(createCollection(SortedSet.class, String.class, 0)).isInstanceOf(TreeSet.class); |
222 |
| - assertThat(createCollection(NavigableSet.class, String.class, 0)).isInstanceOf(TreeSet.class); |
| 212 | + testCollection(List.class, ArrayList.class); |
| 213 | + testCollection(Set.class, LinkedHashSet.class); |
| 214 | + testCollection(Collection.class, LinkedHashSet.class); |
| 215 | + testCollection(SortedSet.class, TreeSet.class); |
| 216 | + testCollection(NavigableSet.class, TreeSet.class); |
223 | 217 |
|
224 | 218 | // concrete types
|
225 |
| - assertThat(createCollection(HashSet.class, 0)).isInstanceOf(HashSet.class); |
226 |
| - assertThat(createCollection(HashSet.class, String.class, 0)).isInstanceOf(HashSet.class); |
| 219 | + testCollection(ArrayList.class, ArrayList.class); |
| 220 | + testCollection(HashSet.class, LinkedHashSet.class); |
| 221 | + testCollection(LinkedHashSet.class, LinkedHashSet.class); |
| 222 | + testCollection(TreeSet.class, TreeSet.class); |
| 223 | + } |
| 224 | + |
| 225 | + private void testCollection(Class<?> collectionType, Class<?> resultType) { |
| 226 | + assertThat(CollectionFactory.isApproximableCollectionType(collectionType)).isTrue(); |
| 227 | + assertThat(createCollection(collectionType, 0)).isInstanceOf(resultType); |
| 228 | + assertThat(createCollection(collectionType, String.class, 0)).isInstanceOf(resultType); |
227 | 229 | }
|
228 | 230 |
|
229 | 231 | @Test
|
@@ -258,20 +260,22 @@ void rejectsNullCollectionType() {
|
258 | 260 | @Test
|
259 | 261 | void createsMapsCorrectly() {
|
260 | 262 | // interfaces
|
261 |
| - assertThat(createMap(Map.class, 0)).isInstanceOf(LinkedHashMap.class); |
262 |
| - assertThat(createMap(SortedMap.class, 0)).isInstanceOf(TreeMap.class); |
263 |
| - assertThat(createMap(NavigableMap.class, 0)).isInstanceOf(TreeMap.class); |
264 |
| - assertThat(createMap(MultiValueMap.class, 0)).isInstanceOf(LinkedMultiValueMap.class); |
265 |
| - |
266 |
| - assertThat(createMap(Map.class, String.class, 0)).isInstanceOf(LinkedHashMap.class); |
267 |
| - assertThat(createMap(SortedMap.class, String.class, 0)).isInstanceOf(TreeMap.class); |
268 |
| - assertThat(createMap(NavigableMap.class, String.class, 0)).isInstanceOf(TreeMap.class); |
269 |
| - assertThat(createMap(MultiValueMap.class, String.class, 0)).isInstanceOf(LinkedMultiValueMap.class); |
| 263 | + testMap(Map.class, LinkedHashMap.class); |
| 264 | + testMap(SortedMap.class, TreeMap.class); |
| 265 | + testMap(NavigableMap.class, TreeMap.class); |
| 266 | + testMap(MultiValueMap.class, LinkedMultiValueMap.class); |
270 | 267 |
|
271 | 268 | // concrete types
|
272 |
| - assertThat(createMap(HashMap.class, 0)).isInstanceOf(HashMap.class); |
| 269 | + testMap(HashMap.class, LinkedHashMap.class); |
| 270 | + testMap(LinkedHashMap.class, LinkedHashMap.class); |
| 271 | + testMap(TreeMap.class, TreeMap.class); |
| 272 | + testMap(LinkedMultiValueMap.class, LinkedMultiValueMap.class); |
| 273 | + } |
273 | 274 |
|
274 |
| - assertThat(createMap(HashMap.class, String.class, 0)).isInstanceOf(HashMap.class); |
| 275 | + private void testMap(Class<?> mapType, Class<?> resultType) { |
| 276 | + assertThat(CollectionFactory.isApproximableMapType(mapType)).isTrue(); |
| 277 | + assertThat(createMap(mapType, 0)).isInstanceOf(resultType); |
| 278 | + assertThat(createMap(mapType, String.class, 0)).isInstanceOf(resultType); |
275 | 279 | }
|
276 | 280 |
|
277 | 281 | @Test
|
|
0 commit comments