package core;

import org.junit.Test;
import utils.Utils;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

public class MnemonicMapTest {

    @Test
    public void testAddToMap_SimpleCtor() {
        MnemonicMap mnemonicMap = new MnemonicMap();
        assertEquals(0, mnemonicMap.getMap().size());

        mnemonicMap.add(new MatchingMnemonic("bac", "banana apple cherry"));

        assertEquals(1, mnemonicMap.getMap().size());

        List<String> list = new ArrayList<String>();
        list.addAll(mnemonicMap.getMap().keySet());

        assertEquals("Should be upper case and ordered alphabetically", "ABC", list.get(0));

        Collection<List<MatchingMnemonic>> values = mnemonicMap.getMap().values();
        assertEquals(1, values.size());

        List<MatchingMnemonic> next = values.iterator().next();
        assertEquals(1, next.size());
        assertEquals("bac", next.get(0).getMnemonic());
        assertEquals("banana apple cherry", next.get(0).getDetail().getExpandedMnemonic());
        assertEquals(Utils.UNKNOWN_STRING, next.get(0).getDetail().getOrigin());
        assertEquals(Utils.UNKNOWN_STRING, next.get(0).getDetail().getCategory());
    }

    @Test
    public void testGetFromMap() {
        MnemonicMap mnemonicMap = new MnemonicMap();
        MatchingMnemonic originalInput = new MatchingMnemonic("bac", "banana apple cherry");
        mnemonicMap.add(originalInput);

        assertEquals(new ArrayList(), mnemonicMap.getValues("xyz"));
        assertNotNull(mnemonicMap.getValues("abc"));
        assertNotNull(mnemonicMap.getValues("bac"));
        assertNotNull(mnemonicMap.getValues("bca"));
        assertNotNull(mnemonicMap.getValues("acb"));
        assertNotNull(mnemonicMap.getValues("cba"));
        assertNotNull(mnemonicMap.getValues("cab"));

        List<MatchingMnemonic> cab = mnemonicMap.getValues("cab");
        assertEquals(1, cab.size());
        assertEquals(originalInput, cab.get(0));
        assertEquals(mnemonicMap.getValues("cba"), mnemonicMap.getValues("cab"));
        assertEquals(mnemonicMap.getValues("bac"), mnemonicMap.getValues("abc"));
    }
}
@@ -969,32 +969,90 @@
 1, next.size());
+%0A%0A        MatchingMnemonic matchingMnemonic = next.get(0);
 %0A        assertE
@@ -1064,27 +1064,32 @@
 (%22bac%22, 
-next.get(0)
+matchingMnemonic
 .getMnem
@@ -1141,27 +1141,32 @@
 herry%22, 
-next.get(0)
+matchingMnemonic
 .getDeta
@@ -1233,35 +1233,40 @@
 OWN_STRING, 
-next.get(0)
+matchingMnemonic
 .getDetail()
@@ -1323,27 +1323,1202 @@
 STRING, 
-next.get(0)
+matchingMnemonic.getDetail().getCategory());%0A    %7D%0A%0A    @Test%0A    public void testAddToMap_MatchingMnemonicDetailCtor() %7B%0A        MnemonicMap mnemonicMap = new MnemonicMap();%0A        assertEquals(0, mnemonicMap.getMap().size());%0A%0A        mnemonicMap.add(new MatchingMnemonic(%22bat%22, new MatchingMnemonicDetail(%22banana apple tomato%22, %22MyOrigin%22, %22MyCategory%22)));%0A%0A        assertEquals(1, mnemonicMap.getMap().size());%0A%0A        List%3CString%3E list = new ArrayList%3CString%3E();%0A        list.addAll(mnemonicMap.getMap().keySet());%0A%0A        assertEquals(%22Should be upper case and ordered alphabetically%22, %22ABT%22, list.get(0));%0A%0A        Collection%3CList%3CMatchingMnemonic%3E%3E values = mnemonicMap.getMap().values();%0A        assertEquals(1, values.size());%0A%0A        List%3CMatchingMnemonic%3E next = values.iterator().next();%0A        assertEquals(1, next.size());%0A%0A        MatchingMnemonic matchingMnemonic = next.get(0);%0A        assertEquals(%22bat%22, matchingMnemonic.getMnemonic());%0A        assertEquals(%22banana apple tomato%22, matchingMnemonic.getDetail().getExpandedMnemonic());%0A        assertEquals(%22MyOrigin%22, matchingMnemonic.getDetail().getOrigin());%0A        assertEquals(%22MyCategory%22, matchingMnemonic
 .getDeta

add additional test to cover second ctor