BAEL-1983 Initialize hashmap (#4949)

* BAEL-1983 Initialize hashmap

* BAEL-1983 Initialize hashmap
This commit is contained in:
Dhrubajyoti Bhattacharjee 2018-08-12 10:49:43 +05:30 committed by maibin
parent 99676b1a9e
commit 534d5749cc
1 changed files with 30 additions and 0 deletions

View File

@ -0,0 +1,30 @@
package org.baeldung.guava;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.*;
import java.util.Map;
import org.junit.Test;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
public class GuavaMapInitializeUnitTest {
@Test
public void givenKeyValuesShoudInitializeMap() {
Map<String, String> articles = ImmutableMap.of("Title", "My New Article", "Title2", "Second Article");
assertThat(articles.get("Title"), equalTo("My New Article"));
assertThat(articles.get("Title2"), equalTo("Second Article"));
}
@Test
public void givenKeyValuesShouldCreateMutableMap() {
Map<String, String> articles = Maps.newHashMap(ImmutableMap.of("Title", "My New Article", "Title2", "Second Article"));
assertThat(articles.get("Title"), equalTo("My New Article"));
assertThat(articles.get("Title2"), equalTo("Second Article"));
}
}