I'm working on some project and now I'm struggling with testing. I have the following class:
public interface Connector{ }
public class ConnectorFactory{
public Connector create(){
//Very complicated logic
}
}
It's absolutely necessary to test this class. But this method is too large to be easily tested. The solution I found is to split in into default-access methods like this:
public class ConnectorFactory{
public Connector create(){
initState();
checkIncomingParameters();
applyTemplates();
prepareResult();
InputStream is = openInputStream();
return createFromInputStream(is);
}
void initState(){
//...
}
void checkIncomingParameters(){
//...
}
String applyTemplates(){
//...
}
void prepareResult(){
//...
}
InputStream openInputStream(){
//...
}
Connector createFromInputStream(InputStream is){
//...
}
}
Each of these default-access methods are easily tested. By the only reason they are default-access ones is testing.
Is it common to do like that?