package gumi.builders;

import gumi.builders.url.UrlParameterMultimap;
import org.junit.Test;

import java.util.AbstractMap;
import java.util.Arrays;
import java.util.Map;

import static org.junit.Assert.assertEquals;

/**
 * Ideally, these tests should provide 100% coverage for UrlParameterMultimap.
 */
public class MultimapTest {

    private static Map.Entry<String, String> newEntry(final String key, final String value) {
        return new AbstractMap.SimpleImmutableEntry<String, String>(key, value);
    }

    @Test
    public void createMultimap() {
        final UrlParameterMultimap m1 = UrlParameterMultimap.newMultimap();
    }

    @Test
    public void createImmutable() {
        final UrlParameterMultimap.Immutable m1 = UrlParameterMultimap.newMultimap().immutable();
    }

    @Test
    public void putArray() {
        final UrlParameterMultimap m1 = UrlParameterMultimap.newMultimap();
        m1.put("a", Arrays.asList("1", "2", "3"));
        m1.put("b", Arrays.asList("4", "5", "6"));
        m1.put("a", Arrays.asList("2", "3", "7"));
        assertEquals(Arrays.asList(newEntry("a", "2"), newEntry("a", "3"), newEntry("b", "4"),
                newEntry("b", "5"), newEntry("b", "6"), newEntry("a", "7")),
                m1.flatEntryList());
    }

    @Test
    public void addEntries() {
        final UrlParameterMultimap m1 = UrlParameterMultimap.newMultimap();
        m1.add("a", "1").add("b", "2").add("c", "3");
        assertEquals(m1.flatEntryList().get(0), newEntry("a", "1"));
        assertEquals(m1.flatEntryList().get(1), newEntry("b", "2"));
        assertEquals(m1.flatEntryList().get(2), newEntry("c", "3"));
    }

    @Test(expected = UnsupportedOperationException.class)
    public void mutateImmutableParameterMap() {
        final UrlParameterMultimap m1 = UrlParameterMultimap.newMultimap();
        m1.add("a", "1").add("b", "2").add("c", "3");
        final UrlParameterMultimap.Immutable i1 = m1.immutable();
        i1.add("d", "4");
    }
}

@@ -197,28 +197,17 @@
 .Assert.
-assertEquals
+*
 ;%0A%0A/**%0A 
@@ -1981,10 +1981,964 @@
 ;%0A    %7D%0A
+    %0A    @Test%0A    public void containsKey() %7B%0A        UrlParameterMultimap parameterMap = givenParameterMapWithKeyAndValue();%0A        assertTrue(parameterMap.containsKey(%22key1%22));%0A        assertFalse(parameterMap.containsKey(%22key2%22));%0A    %7D%0A%0A    @Test%0A    public void containsValue() %7B%0A        UrlParameterMultimap parameterMap = givenParameterMapWithKeyAndValue();%0A        assertTrue(parameterMap.containsValue(%22value1%22));%0A        assertFalse(parameterMap.containsValue(%22value2%22));%0A    %7D%0A%0A    @Test%0A    public void replaceValues() %7B%0A        UrlParameterMultimap parameterMap = givenParameterMapWithKeyAndValue();%0A        parameterMap.replaceValues(%22key1%22, %22value2%22);%0A        assertFalse(parameterMap.containsValue(%22value1%22));%0A        assertTrue(parameterMap.containsValue(%22value2%22));%0A    %7D%0A%0A    private static UrlParameterMultimap givenParameterMapWithKeyAndValue() %7B%0A        return UrlParameterMultimap.newMultimap().add(%22key1%22, %22value1%22);%0A    %7D%0A    %0A
 %7D%0A

Add new tests to MultimapTest