diff --git a/guava/src/test/java/org/baeldung/guava/GuavaMapInitializeUnitTest.java b/guava/src/test/java/org/baeldung/guava/GuavaMapInitializeUnitTest.java new file mode 100644 index 0000000000..69a7505316 --- /dev/null +++ b/guava/src/test/java/org/baeldung/guava/GuavaMapInitializeUnitTest.java @@ -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 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 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")); + } +}