この掲示板で同様の質問を見てきましたが、どれも私の質問に答えていません。これは奇妙に聞こえますが、モックしているオブジェクトのコンストラクター呼び出しをモックアウトすることは可能ですか?
例:
class RealGuy {
....
public void someMethod(Customer customer) {
Customer customer = new Customer(145);
}
}
class MyUnitTest() {
public Customer customerMock = createMock(Customer.class)
public void test1() {
//i can inject the mock object, but it's still calling the constuctor
realGuyobj.someMethod(customerMock);
//the constructor call for constructor makes database connections, and such.
}
}
コンストラクター呼び出しを期待するにはどうすればよいですか? Customer コンストラクターの呼び出しを newInstance を使用するように変更できますが、それが役立つかどうかはわかりません。new Customer(145)
コンストラクターの本体が何をするかを制御することはできません。
これは可能ですか?