From 94c33936db6ae9ca52716cabb48361ad603e077e Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Wed, 27 Feb 2019 12:06:13 +0100 Subject: [PATCH] Add test for Iterator.remove() on KObjectHashMap.values().iterator() (#8891) Motivation: https://github.com/netty/netty/pull/8866 added support for calling Iterator.remove() but did not add a testcase. Modifications: Add testcase to ensure removal works. Result: Better test-coverage. --- .../collection/KObjectHashMapTest.template | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/common/src/test/templates/io/netty/util/collection/KObjectHashMapTest.template b/common/src/test/templates/io/netty/util/collection/KObjectHashMapTest.template index 2be12a9ea8..d4214f7fce 100644 --- a/common/src/test/templates/io/netty/util/collection/KObjectHashMapTest.template +++ b/common/src/test/templates/io/netty/util/collection/KObjectHashMapTest.template @@ -613,4 +613,34 @@ public class @K@ObjectHashMapTest { } assertTrue(map.isEmpty()); } + + @Test + public void valuesIteratorRemove() { + Value v1 = new Value("v1"); + Value v2 = new Value("v2"); + Value v3 = new Value("v3"); + map.put((@k@) 1, v1); + map.put((@k@) 2, v2); + map.put((@k@) 3, v3); + + Iterator it = map.values().iterator(); + + assertSame(v1, it.next()); + assertSame(v2, it.next()); + it.remove(); + + assertSame(v3, it.next()); + assertFalse(it.hasNext()); + + assertEquals(2, map.size()); + assertSame(v1, map.get((@k@) 1)); + assertNull(map.get((@k@) 2)); + assertSame(v3, map.get((@k@) 3)); + + it = map.values().iterator(); + + assertSame(v1, it.next()); + assertSame(v3, it.next()); + assertFalse(it.hasNext()); + } }