0

I have a private generic method below

private Section convertFromJsonToJavaObj(JSONObject jsonObj, Class<Section> classObj) throws SNPSysException {
    // logic
    return section;    
}

how to mock above method

Nguyen Kien
  • 1,897
  • 2
  • 16
  • 22

1 Answers1

0

Testing private methods is generally a code smell. We generally only test public methods.

However if there is a quite complex logic in it and you really need to test it, you can remove the private modifier.

Section convertFromJsonToJavaObj(JSONObject jsonObj, Class<Section> classObj) throws SNPSysException {
     // logic
     return section;    
}

This way your test will be able to access this method if it's in the same package (except that it should be in the test folder instead of main folder)

Arnaud
  • 36
  • 5