mardi 29 décembre 2015

TestNG test class for a well encapsulated class

I am unit testing a class with the following structure.

public class Experiment {

    private final Map<String,String> map = new HashMap<>();

    Experiment(Set<String> set){
        for(String str :set ){
            map.put(str,str);
        }
    }

    public String getVal(String str){
        return map.get(str);
    }

}

As seen my class has only one instance variable that is a HashMap. Now i want to make sure my map is correctly populated through my constructor which takes a HashSet. Since I can create a expected Map structure independently. But i am stuck now because my 'map' is "private" in my class. I dont want to expose my state variable to outside world by making it public. Please suggest a way to Unit test my map variable.

Aucun commentaire:

Enregistrer un commentaire