I have an old application with code fragments like these:
public class MyClass
{
public void executeSomeSqlStatement()
{
final Connection dbConn = ConnectionPool.getInstance().getConnection();
final PreparedStatement statement = dbConn.prepareStatement(); // NullPointerException, if ConnectionPool.getInstance().getConnection() returns null
}
}
I want to write a unit test, which verifies that MyClass.executeSomeSqlStatement doesn't throw a NullPointerException, when ConnectionPool.getInstance().getConnection() returns null.
How can I do it (mock ConnectionPool.getInstance().getConnection()) without changing the design of the class (without removing the singleton) ?