Complete the code to mock a void method using Mockito.
doNothing().when(mockedObject).[1]();The correct way to specify the method call in Mockito's doNothing().when() is with parentheses to indicate the method invocation. So, voidMethod() is correct.
Complete the code to verify that a void method was called exactly once.
verify(mockedObject, [1]()).voidMethod();times(0) or never() when expecting the method to be called once.To check that a method was called exactly once, use times(1) with verify().
Fix the error in the code to stub a void method to throw an exception.
doThrow(new RuntimeException()).when(mockedObject).[1]();when(), causing syntax errors.When stubbing void methods with doThrow(), the method call should include parentheses inside when().
Fill both blanks to stub a void method to do nothing and verify it was called twice.
do[1]().when(mockedObject).voidMethod(); verify(mockedObject, [2]()).voidMethod();
times(1) when expecting two calls.doThrow() instead of doNothing() when no exception is expected.doNothing() stubs the void method to do nothing, and times(2) verifies it was called twice.
Fill all three blanks to stub a void method to throw an exception, verify it was called once, and reset the mock.
do[1](new RuntimeException()).when(mockedObject).voidMethod(); verify(mockedObject, [2]()).voidMethod(); [3](mockedObject);
doNothing() instead of doThrow() when expecting an exception.doThrow() stubs the void method to throw an exception, times(1) verifies it was called once, and reset() clears the mock's interactions.