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
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
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)