BAEL-1438: TreeMap vs HashMap (#3265)

* BAEL-1438: Final code.

* BAEL-1438: Temporary commit.

* BAEL-1438: New Changes.

* BAEL-1438: New test case to support Java 8 features.
This commit is contained in:
Shouvik Bhattacharya
2017-12-21 22:14:27 +05:30
committed by maibin
parent 2bff7a623e
commit d14cc42306
2 changed files with 75 additions and 0 deletions
@@ -3,7 +3,12 @@ package com.baeldung;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.ConcurrentModificationException;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;
public class ExceptionUnitTest {
@@ -22,4 +27,14 @@ public class ExceptionUnitTest {
Integer.valueOf(str);
});
}
@Test
public void whenModifyMapDuringIteration_thenThrowExecption() {
Map<Integer, String> hashmap = new HashMap<>();
hashmap.put(1, "One");
hashmap.put(2, "Two");
Executable executable = () -> hashmap.forEach((key, value) -> hashmap.remove(1));
assertThrows(ConcurrentModificationException.class, executable);
}
}