|
29 | 29 | import java.lang.invoke.MethodHandles;
|
30 | 30 | import java.lang.invoke.MethodType;
|
31 | 31 | import java.lang.invoke.VarHandle;
|
32 |
| -import java.lang.reflect.Field; |
33 | 32 | import java.util.AbstractMap;
|
34 | 33 | import java.util.AbstractSet;
|
35 | 34 | import java.util.ArrayList;
|
|
44 | 43 | import java.util.Set;
|
45 | 44 | import java.util.WeakHashMap;
|
46 | 45 | import java.util.function.Consumer;
|
| 46 | +import java.util.function.IntFunction; |
47 | 47 | import java.util.function.Supplier;
|
48 | 48 |
|
49 | 49 | import static org.testng.Assert.assertEquals;
|
50 | 50 | import static org.testng.Assert.assertNull;
|
| 51 | +import static org.testng.Assert.assertThrows; |
51 | 52 |
|
52 | 53 | /*
|
53 | 54 | * @test
|
@@ -426,4 +427,27 @@ public int capacity() {
|
426 | 427 | }
|
427 | 428 | }
|
428 | 429 |
|
| 430 | + @DataProvider(name = "negativeNumMappings") |
| 431 | + public Iterator<Object[]> negativeNumMappings() { |
| 432 | + final List<Object[]> methods = new ArrayList<>(); |
| 433 | + methods.add(new Object[] {(IntFunction<?>) HashMap::newHashMap, "HashMap::newHashMap"}); |
| 434 | + methods.add(new Object[] {(IntFunction<?>) LinkedHashMap::newLinkedHashMap, |
| 435 | + "LinkedHashMap::newLinkedHashMap"}); |
| 436 | + methods.add(new Object[] {(IntFunction<?>) WeakHashMap::newWeakHashMap, |
| 437 | + "WeakHashMap::newWeakHashMap"}); |
| 438 | + methods.add(new Object[] {(IntFunction<?>) HashSet::newHashSet, "HashSet::newHashSet"}); |
| 439 | + methods.add(new Object[] {(IntFunction<?>) LinkedHashSet::newLinkedHashSet, |
| 440 | + "LinkedHashSet::newLinkedHashSet"}); |
| 441 | + return methods.iterator(); |
| 442 | + } |
| 443 | + |
| 444 | + /** |
| 445 | + * Tests that the APIs that take {@code numMappings} or {@code numElements} as a parameter for |
| 446 | + * creating the collection instance (for example: {@link HashMap#newHashMap(int)}), throw |
| 447 | + * an {@code IllegalArgumentException} when a negative value is passed to them |
| 448 | + */ |
| 449 | + @Test(dataProvider = "negativeNumMappings") |
| 450 | + public void testNegativeNumMappings(final IntFunction<?> method, final String methodName) { |
| 451 | + assertThrows(IllegalArgumentException.class, () -> method.apply(-1)); |
| 452 | + } |
429 | 453 | }
|
0 commit comments