package com.michaelthomas.map.linkedhashmap; /** * @author Michael Thomas (www.michael-thomas.com) michael@michael-thomas.com * */ import static org.junit.Assert.*; import org.junit.Before; import org.junit.Test; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; import com.michaelthomas.map.MyMapTraverse; import com.michaelthomas.map.hashmap.MyHashMap; public class MyLinkedHashMapTest { private MyLinkedHashMap myMapObj = new MyLinkedHashMap(); private MyMapTraverse myMapTraverseObj = new MyMapTraverse(); private LinkedHashMap mapWeekDays = new LinkedHashMap(); private LinkedHashMap mapAbbr = new LinkedHashMap(); private LinkedHashMap mapPlay = new LinkedHashMap(); @Before public void setUp() throws Exception { mapWeekDays = myMapObj.buildMapWeekDays(); mapAbbr = myMapObj.buildMapAbbreviations(); } @Test public void testLinkedHashMapNotes(){ //PLEASE READ THIS! //NOTE: Make sure that you look at the following JUnit test for a fairly complete // coverage of all the methods of the Map interface. // /collections/test/com/michaelthomas/map/MyMapTest.java } @Test public void testLinkedHashMapCommonUses(){ //Most common uses: Map mapPlay2 = new LinkedHashMap(); mapPlay2.put("NY", "New York"); mapPlay2.put("LA", "Louisiana"); mapPlay2.put("GA", "Georgia"); assertEquals("Georgia", mapPlay2.get("GA")); assertEquals(3, mapPlay2.size()); } @Test public void testLinkedHashMapCommonWeekDays(){ assertEquals("Monday", mapWeekDays.get("Mon")); assertEquals(7, mapWeekDays.size()); } @Test public void testLinkedHashMapCommonPutAll(){ mapPlay.clear(); assertEquals(0, mapPlay.size()); mapPlay.putAll(mapWeekDays); assertEquals(7, mapPlay.size()); mapPlay.putAll(mapAbbr); assertEquals(10, mapPlay.size()); assertEquals("Monday", mapPlay.get("Mon")); assertEquals("Element", mapPlay.get("E")); } @Test public void testLinkedHashMapTraverseForEachExample() { //Note: The order is order-entry. LinkedHashMap keeps order-entry vs no guarantee for HashMap. assertEquals("Sun = Sunday, Mon = Monday, Tue = Tuesday, Wed = Wednesday, Thu = Thursday, Fri = Friday, Sat = Saturday", myMapTraverseObj.forEachExampleEntrySet(mapWeekDays)); } }