|
1 | 1 | /*
|
| 2 | + * Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved. |
2 | 3 | * Copyright (c) 2018 Google Inc. All rights reserved.
|
3 | 4 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
4 | 5 | *
|
@@ -195,4 +196,29 @@ private static Map<String, Object> map() {
|
195 | 196 | Class clazz = entrySet.iterator().next().getClass();
|
196 | 197 | assertThrowingIterator(Collections.checkedSet(entrySet, clazz).iterator());
|
197 | 198 | }
|
| 199 | + |
| 200 | + /** |
| 201 | + * Calls Collections.unmodifiableMap().entrySet().iterator().forEachRemaining() by passing |
| 202 | + * that method a {@code null} action and expects that call to fail with a |
| 203 | + * {@code NullPointerException}. |
| 204 | + */ |
| 205 | + @Test |
| 206 | + public void testUnmodifiableForEachRemainingNPE() { |
| 207 | + final Iterator<?> it = Collections.unmodifiableMap(Map.of()).entrySet().iterator(); |
| 208 | + // pass null action and expect a NPE |
| 209 | + Assert.assertThrows(NullPointerException.class, () -> it.forEachRemaining(null)); |
| 210 | + } |
| 211 | + |
| 212 | + /** |
| 213 | + * Calls Collections.checkedMap().entrySet().iterator().forEachRemaining() by passing |
| 214 | + * that method a {@code null} action and expects that call to fail with a |
| 215 | + * {@code NullPointerException}. |
| 216 | + */ |
| 217 | + @Test |
| 218 | + public void testCheckedMapForEachRemainingNPE() { |
| 219 | + final Iterator<?> it = Collections.checkedMap(Map.of(), String.class, |
| 220 | + String.class).entrySet().iterator(); |
| 221 | + // pass null "action" and expect it to fail with NPE |
| 222 | + Assert.assertThrows(NullPointerException.class, () -> it.forEachRemaining(null)); |
| 223 | + } |
198 | 224 | }
|
0 commit comments