任何人都可以提出任何有关如何最好地使用EasyMock预期来电的建议Runtime.getRuntime().exec(xxx)吗?
我可以将调用移动到另一个实现接口的类中的方法,但不希望在理想的世界中.
interface RuntimeWrapper {
ProcessWrapper execute(String command) throws IOException;
}
interface ProcessWrapper {
int waitFor() throws InterruptedException;
}
Run Code Online (Sandbox Code Playgroud)
我想知道是否有人有任何其他建议?
我有一个旧的应用程序,其代码片段如下:
public class MyClass
{
public void executeSomeSqlStatement()
{
final Connection dbConn = ConnectionPool.getInstance().getConnection();
final PreparedStatement statement = dbConn.prepareStatement(); // NullPointerException, if ConnectionPool.getInstance().getConnection() returns null
}
}
Run Code Online (Sandbox Code Playgroud)
我想编写一个单元测试,当ConnectionPool.getInstance().getConnection()返回null 时,它会验证MyClass.executeSomeSqlStatement不会抛出NullPointerException.
我怎么能这样做(模拟ConnectionPool.getInstance().getConnection())而不改变类的设计(不删除单例)?