5
パラメーターを使用してコンストラクターをモックします
私は以下のようなクラスを持っています: public class A { public A(String test) { bla bla bla } public String check() { bla bla bla } } コンストラクターのロジックA(String test)とcheck()は、私がモックしようとしているものです。次のような呼び出しが必要です:new A($$$any string$$$).check()ダミー文字列を返します"test"。 私は試した: A a = mock(A.class); when(a.check()).thenReturn("test"); String test = a.check(); // to this point, everything works. test shows as "tests" whenNew(A.class).withArguments(Matchers.anyString()).thenReturn(rk); // also tried: …