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
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.when;
@ExtendWith(MockitoExtension.class)
class PersonTest {
@Mock
private Greeting greeting;
@Test
void greet() {
Person person = new Person();
when(person.sayHi(greeting)).thenReturn("Hello!"); // LINE2
String actual = person.greet(greeting);
assertThat(actual).isEqualTo("Hello!");
}
}
I was astonished to see that this test runs successfully, because I would have expected a MissingMethodInvocationException being thrown on LINE2 as I am trying to stub a method call on a non-mock object. If you change LINE1 to return "Hello!"; the expected MissingMethodInvocationException is thrown. Why is this exception not thrown in the SSCCE? 😕
The text was updated successfully, but these errors were encountered:
Given these two classes
And the following test class
I was astonished to see that this test runs successfully, because I would have expected a
MissingMethodInvocationException
being thrown onLINE2
as I am trying to stub a method call on a non-mock object. If you changeLINE1
toreturn "Hello!";
the expectedMissingMethodInvocationException
is thrown. Why is this exception not thrown in the SSCCE? 😕The text was updated successfully, but these errors were encountered: