BAEL-2800_Copying_a_HashMap_in_Java

This commit is contained in:
Anshul Bansal 2019-04-06 07:47:46 +03:00
parent b17c1c720f
commit 96903671b6
1 changed files with 7 additions and 6 deletions

View File

@ -76,15 +76,16 @@ public class CopyHashMapUnitTest {
@Test @Test
public void givenImmutableMap_whenCopyUsingGuava_thenCopyShouldNotChange() { public void givenImmutableMap_whenCopyUsingGuava_thenCopyShouldNotChange() {
Employee emp1 = new Employee("John");
Employee emp2 = new Employee("Norman");
Map<String, Integer> heightMap = ImmutableMap.<String, Integer> builder() Map<String, Employee> map = ImmutableMap.<String, Employee> builder()
.put("emp1", 160) .put("emp1",emp1)
.put("emp2", 165) .put("emp2",emp2)
.put("emp3", 163)
.build(); .build();
Map<String, Integer> heightMapCopy = ImmutableMap.copyOf(heightMap); Map<String, Employee> mapCopy = ImmutableMap.copyOf(map);
assertThat(heightMapCopy).isSameAs(heightMap); assertThat(mapCopy).isSameAs(map);
} }