BAEL-1983 Initialize hashmap (#4949)
* BAEL-1983 Initialize hashmap * BAEL-1983 Initialize hashmap
This commit is contained in:
parent
99676b1a9e
commit
534d5749cc
|
@ -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"));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue