@Test public void shouldResetMultipleMocks() { mock.simpleMethod(); mockTwo.simpleMethod(); reset(mock, mockTwo); verifyNoMoreInteractions(mock, mockTwo); }
@Test public void shouldStubbingNotBeTreatedAsInteraction() { when(mock.simpleMethod("one")).thenThrow(new RuntimeException()); doThrow(new RuntimeException()).when(mock).simpleMethod("two"); reset(mock); verifyZeroInteractions(mock); }
@Test public void shouldRemoveStubbingToString() throws Exception { IMethods mockTwo = mock(IMethods.class); when(mockTwo.toString()).thenReturn("test"); reset(mockTwo); assertContains("Mock for IMethods", mockTwo.toString()); }
@Test public void shouldNotAffectMockName() { IMethods mock = mock(IMethods.class, "mockie"); IMethods mockTwo = mock(IMethods.class); reset(mock); assertContains("Mock for IMethods", "" + mockTwo); assertEquals("mockie", "" + mock); }
@Test public void shouldRemoveAllStubbing() throws Exception { when(mock.objectReturningMethod(isA(Integer.class))).thenReturn(100); when(mock.objectReturningMethod(200)).thenReturn(200); reset(mock); assertNull(mock.objectReturningMethod(200)); assertEquals("default behavior should return null", null, mock.objectReturningMethod("blah")); }
@Test public void shouldMaintainPreviousDefaultAnswer() { // given mock = mock(IMethods.class, RETURNS_MOCKS); // when reset(mock); // then assertNotNull(mock.iMethodsReturningMethod()); }
@Test public void shouldValidateStateWhenResetting() { // invalid verify: verify(mock); try { reset(mockTwo); fail(); } catch (UnfinishedVerificationException e) { } }
@Test public void shouldResetOngoingStubbingSoThatMoreMeaningfulExceptionsAreRaised() { mock(IMethods.class); mock.booleanReturningMethod(); reset(mock); try { when(null).thenReturn("anything"); fail(); } catch (MissingMethodInvocationException e) { } }
@Test public void shouldRemoveAllInteractions() throws Exception { mock.simpleMethod(1); reset(mock); verifyZeroInteractions(mock); }
@Test(expected = NotAMockException.class) public void resettingNullIsSafe() { reset(new Object[] {null}); }
@Test(expected = NotAMockException.class) public void resettingNonMockIsSafe() { reset(""); }