-1

I am trying to learn junit testing and mockito. I would like to know how to write test cases if there are Maps and private method reference.

@Autowired
AppProps props;

public Foo checkStatus(){
     Foo foo = new Foo();
     foo.setStatus("Up");
     
     Map<String,List<String>> childStatusList = getChildStatus();
     foo.setChildStatus(childStatusList);

     return foo;
}

private Map<String,List<String>> getChildStatus(){
    Map<String,List<String>> healthMap = new LinkedHashMap<>(); 

    String url = "https://google.com";
    for(Entry<Integer,List<String>> entrySet: props.getMap().entrySet()){ 
        for(String str : entrySet.getValue()){
             healthMap.put("Up", Arrays.asList(url));
        }
    }
}
PDJ
  • 69
  • 8
  • Does this answer your question? [How do I test a private function or a class that has private methods, fields or inner classes?](https://stackoverflow.com/questions/34571/how-do-i-test-a-private-function-or-a-class-that-has-private-methods-fields-or) – Progman Jun 20 '21 at 13:36
  • Welcome to Stack Overflow! Please take the [tour](/tour), have a look around, and read through the [help center](/help), in particular How do [I ask a good question?](/help/how-to-ask) and [What topics can I ask about here?](/help/on-topic). I downvoted because [No research](http://idownvotedbecau.se/noresearch/) – Timothy Truckle Jun 20 '21 at 14:38

1 Answers1

1

The first and most important thing you have to learn about Unit Tests is:

Unit Test do not test code.
Unit Test verify public observable behavior which is return values and communication with dependencies.

Any attempt to use Jailbreak or PowerMock is just a surrender to bad design decisions.

Timothy Truckle
  • 15,071
  • 2
  • 27
  • 51