Example #1
0
 @Test
 public void shouldResetMultipleMocks() {
   mock.simpleMethod();
   mockTwo.simpleMethod();
   reset(mock, mockTwo);
   verifyNoMoreInteractions(mock, mockTwo);
 }
  @Test
  public void shouldGetAllInvocationsInOrder() throws Exception {
    mockOne.simpleMethod(100);
    mockTwo.simpleMethod(200);
    mockOne.simpleMethod(300);

    List<Invocation> invocations = finder.find(asList(mockOne, mockTwo));

    assertEquals(3, invocations.size());
    assertArgumentEquals(100, invocations.get(0));
    assertArgumentEquals(200, invocations.get(1));
    assertArgumentEquals(300, invocations.get(2));
  }
Example #3
0
 @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 shouldNotCountDuplicatedInteractions() throws Exception {
    mockOne.simpleMethod(100);

    List<Invocation> invocations = finder.find(asList(mockOne, mockOne, mockOne));

    assertEquals(1, invocations.size());
  }
Example #5
0
  @Test
  public void shouldCustomMatcherPrintDescriptionBasedOnName() {
    mock.simpleMethod("foo");

    try {
      verify(mock).simpleMethod(containsTest());
      fail();
    } catch (AssertionError e) {
      assertThat(e).hasMessageContaining("<String that contains xxx>");
    }
  }
  @Test
  public void shouldReadConfigurationClassFromClassPath() {
    ConfigurationAccess.getConfig()
        .overrideDefaultAnswer(
            new Answer<Object>() {
              public Object answer(InvocationOnMock invocation) {
                return "foo";
              }
            });

    IMethods mock = mock(IMethods.class);
    assertEquals("foo", mock.simpleMethod());
  }
Example #7
0
  @Test
  public void shouldAnonymousCustomMatcherPrintDefaultDescription() {
    mock.simpleMethod("foo");

    try {
      verify(mock)
          .simpleMethod(
              (String)
                  argThat(
                      new ArgumentMatcher<Object>() {
                        public boolean matches(Object argument) {
                          return false;
                        }
                      }));
      fail();
    } catch (AssertionError e) {
      assertThat(e).hasMessageContaining("<custom argument matcher>").hasMessageContaining("foo");
    }
  }
Example #8
0
 @Test
 public void testInjectMocks() throws Exception {
   when(mock.simpleMethod(1)).thenReturn("1");
   mock.simpleMethod(2);
 }
Example #9
0
 @Test
 public void shouldRemoveAllInteractions() throws Exception {
   mock.simpleMethod(1);
   reset(mock);
   verifyZeroInteractions(mock);
 }