You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
And class C, contructor of which uses inctances of both A and B
public class C {
private final A a;
private final B b;
C(A a, B b) {
this.a = a;
this.b = b;
}
public void callFields() {
System.out.println("A " + a.call());
System.out.println("B " + b.call());
}
}
In that case following test does not behave consistently
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import static org.mockito.Mockito.when;
@ExtendWith(MockitoExtension.class)
class MockitoTest {
@Mock
A a;
@Mock
B b;
@InjectMocks
C c;
@Test
void test() {
when(a.call()).thenReturn("A");
when(b.call()).thenReturn("B");
c.callFields();
}
}
org.junit.jupiter:junit-jupiter:5.9.1
org.mockito:mockito-junit-jupiter:4.8.1
openjdk version "17.0.3" 2022-04-19 LTS
The text was updated successfully, but these errors were encountered:
This issue caused me at least 1-2 hours to figure out. There was no clear explanation or warning for the root cause. It was behaving differently on each context. I came here to post this issue, but looks like this has been ongoing for 1 year 😞
Consider classes A and B
And class C, contructor of which uses inctances of both A and B
In that case following test does not behave consistently
org.junit.jupiter:junit-jupiter:5.9.1
org.mockito:mockito-junit-jupiter:4.8.1
openjdk version "17.0.3" 2022-04-19 LTS
The text was updated successfully, but these errors were encountered: