Testowanie jednostkowe z mockito dla konstruktorów
Mam jedną klasę.
Class First {
private Second second;
public First(int num, String str) {
second = new Second(str);
this.num = num;
}
... // some other methods
}
Chcę napisać testy jednostkowe dla publicznych metod klasy First. Chcę uniknąć wykonania konstruktora klasy Drugiej.
Ja to zrobiłem:
Second second = Mockito.mock(Second.class);
Mockito.when(new Second(any(String.class))).thenReturn(null);
First first = new First(null, null);
Nadal nazywa się konstruktorem klasy Second. Jak mogę tego uniknąć?