BAEL-5351: Added unit tests for empty map methods

This commit is contained in:
Mayank Agarwal 2022-02-05 11:53:37 +05:30
parent d2332a5c10
commit 2e8381fbd7
1 changed files with 30 additions and 0 deletions

View File

@ -0,0 +1,30 @@
package com.baeldung.map.initialize;
import java.util.Map;
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class EmptyMapInitializerTest {
@Test(expected=UnsupportedOperationException.class)
public void givenEmptyMap_whenAddingEntries_throwsException() {
Map<String, String> map = EmptyMapInitializer.createEmptyMap();
map.put("key", "value");
}
@Test
public void checkStaticMap_isEmpty() {
assertTrue(EmptyMapInitializer.articleMap.isEmpty());
}
@Test
public void emptyMapCreated_usingGuava() {
Map<String, String> emptyMapUsingGuava = EmptyMapInitializer.createMapUsingGuava();
assertTrue(emptyMapUsingGuava.isEmpty());
emptyMapUsingGuava.put("key", "value");
assertFalse(emptyMapUsingGuava.isEmpty());
}
}