Example #1
0
 @Test
 public void shouldResetMultipleMocks() {
   mock.simpleMethod();
   mockTwo.simpleMethod();
   reset(mock, mockTwo);
   verifyNoMoreInteractions(mock, mockTwo);
 }
Example #2
0
 @Test
 public void shouldStubbingNotBeTreatedAsInteraction() {
   when(mock.simpleMethod("one")).thenThrow(new RuntimeException());
   doThrow(new RuntimeException()).when(mock).simpleMethod("two");
   reset(mock);
   verifyZeroInteractions(mock);
 }
Example #3
0
 @Test
 public void shouldRemoveStubbingToString() throws Exception {
   IMethods mockTwo = mock(IMethods.class);
   when(mockTwo.toString()).thenReturn("test");
   reset(mockTwo);
   assertContains("Mock for IMethods", mockTwo.toString());
 }
Example #4
0
 @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);
 }
Example #5
0
 @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"));
 }
Example #6
0
 @Test
 public void shouldMaintainPreviousDefaultAnswer() {
   // given
   mock = mock(IMethods.class, RETURNS_MOCKS);
   // when
   reset(mock);
   // then
   assertNotNull(mock.iMethodsReturningMethod());
 }
Example #7
0
  @Test
  public void shouldValidateStateWhenResetting() {
    // invalid verify:
    verify(mock);

    try {
      reset(mockTwo);
      fail();
    } catch (UnfinishedVerificationException e) {
    }
  }
Example #8
0
 @Test
 public void shouldResetOngoingStubbingSoThatMoreMeaningfulExceptionsAreRaised() {
   mock(IMethods.class);
   mock.booleanReturningMethod();
   reset(mock);
   try {
     when(null).thenReturn("anything");
     fail();
   } catch (MissingMethodInvocationException e) {
   }
 }
Example #9
0
 @Test
 public void shouldRemoveAllInteractions() throws Exception {
   mock.simpleMethod(1);
   reset(mock);
   verifyZeroInteractions(mock);
 }
Example #10
0
 @Test(expected = NotAMockException.class)
 public void resettingNullIsSafe() {
   reset(new Object[] {null});
 }
Example #11
0
 @Test(expected = NotAMockException.class)
 public void resettingNonMockIsSafe() {
   reset("");
 }