mardi 29 septembre 2015

Test - How to check if something was added to the HashMap

I have a method that simply just add something to the hashmap. Code looks like this:

public void map(@Nonnull String string, @Nonnull Collection<SomeCOllection> collection) {
    hashmap.put(string, collecction);
}

hashmap is initialised on top off the class. I want to test if this works. I just simply do not know how to check if that list contains expected elements. It would be simple to check if that method would return something.

For now my test looks like this:

@Test
public void testMap() {
    //given
    Collection<SomeCollection> collection = setUpElementsOfCollection();
    String group = "a";
    String group2 = "b";

    //when
    parser.map(group,users);

    //then
    verify(parser).map(group, users);
}   

I would like to make some sort of assertion to check if map cworks correctly. Any ideas, code snippets would be nice.

Aucun commentaire:

Enregistrer un commentaire