Пример #1
0
 @Test
 public void shouldResetMultipleMocks() {
   mock.simpleMethod();
   mockTwo.simpleMethod();
   reset(mock, mockTwo);
   verifyNoMoreInteractions(mock, mockTwo);
 }
Пример #2
0
  @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));
  }
Пример #3
0
 @Test
 public void shouldStubbingNotBeTreatedAsInteraction() {
   when(mock.simpleMethod("one")).thenThrow(new RuntimeException());
   doThrow(new RuntimeException()).when(mock).simpleMethod("two");
   reset(mock);
   verifyZeroInteractions(mock);
 }
Пример #4
0
  @Test
  public void shouldNotCountDuplicatedInteractions() throws Exception {
    mockOne.simpleMethod(100);

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

    assertEquals(1, invocations.size());
  }
Пример #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());
  }
Пример #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");
    }
  }
Пример #8
0
 @Test
 public void testInjectMocks() throws Exception {
   when(mock.simpleMethod(1)).thenReturn("1");
   mock.simpleMethod(2);
 }
Пример #9
0
 @Test
 public void shouldRemoveAllInteractions() throws Exception {
   mock.simpleMethod(1);
   reset(mock);
   verifyZeroInteractions(mock);
 }