On Thu, 7 Mar 2024 04:13:17 GMT, Korov <d...@openjdk.org> wrote:

>> When the specified key did not associated with a value, should check the 
>> `key` and `value` type.
>
> Korov has updated the pull request incrementally with one additional commit 
> since the last revision:
> 
>   modify the code based on the review

test/jdk/java/util/Collections/CheckedMapBash.java line 193:

> 191:             m.merge("key", "value", (v1, v2) -> null);
> 192:             fail("Should throw ClassCastException");
> 193:         } catch (ClassCastException ignore) {

Since this test is already running with testNG, we should just use its builtin 
functionalities:

    @Test(groups = "type_check")
    public static void testTypeCheck() {
        Map m = Collections.checkedMap(new HashMap<>(), Integer.class, 
Integer.class);
        Assert.assertThrows(ClassCastException.class, () -> m.merge("key", 
"value", (v1, v2) -> null));
        Assert.assertThrows(ClassCastException.class, () -> m.merge("key", 3, 
(v1, v2) -> v2));
    }


In addition, the checked map tests are in general, only checking the map 
functionality works without checking if the type checking functionality works. 
But adding a comprehensive test for checking functionalites would be much more 
work and is out of this patch's scope, so you don't need to worry about it.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/18141#discussion_r1515507158

Reply via email to