I m building a new hashmap ( < String , String[] > ) by combining three other hashmaps ( < String , String > ) and adding the filename. How do I assert the new hashmap is correct? The nested array is making the test fail.
This code is a simplified example of my failing test:
@Test public void injectArrayIntoHashMap() { HashMap map = new HashMap(); map.put("hi", new String[] { "hello", "howdy" }); HashMap newMap = new HashMap(); newMap.put("hi", new String[] { "hello", "howdy" }); assertEquals(map, newMap); }
UPDATE: Okay, based on Hna s advice, I got the test working with an ArrayList. However, I then realized I needed to instantiate an object inside of the ArrayList and now the test is failing. It seems to have to do with the fact that the objects inside the ArrayList have different memory addresses. I m new to Java and inserting the object in the ArrayList this was my attempt to avoid an "if" statement. Is there a better way? Or just an easy answer to making my test pass?
Here is the new code:
@Test public void sampleTest() throws IOException { HashMap expectedResult = new HashMap(); expectedResult.put("/images", new ArrayList(Arrays.asList("/images", new Public()))); expectedResult.put("/stylesheets", new ArrayList(Arrays.asList("/stylesheets", new Public()))); HashMap actualResult = test(); assertEquals(expectedResult, actualResult); } public HashMap test() { HashMap hashMap = new HashMap(); hashMap.put("/images", new ArrayList(Arrays.asList("/images", new Public()))); hashMap.put("/stylesheets", new ArrayList(Arrays.asList("/stylesheets", new Public()))); return hashMap; }