Example #1
0
  @SuppressWarnings("deprecation")
  @Test
  public void shouldStubStringVarargs() {
    when(mock.withStringVarargsReturningString(1)).thenReturn("1");
    when(mock.withStringVarargsReturningString(2, "1", "2", "3")).thenReturn("2");

    RuntimeException expected = new RuntimeException();
    stubVoid(mock).toThrow(expected).on().withStringVarargs(3, "1", "2", "3", "4");

    assertEquals("1", mock.withStringVarargsReturningString(1));
    assertEquals(null, mock.withStringVarargsReturningString(2));

    assertEquals("2", mock.withStringVarargsReturningString(2, "1", "2", "3"));
    assertEquals(null, mock.withStringVarargsReturningString(2, "1", "2"));
    assertEquals(null, mock.withStringVarargsReturningString(2, "1", "2", "3", "4"));
    assertEquals(null, mock.withStringVarargsReturningString(2, "1", "2", "9999"));

    mock.withStringVarargs(3, "1", "2", "3", "9999");
    mock.withStringVarargs(9999, "1", "2", "3", "4");

    try {
      mock.withStringVarargs(3, "1", "2", "3", "4");
      fail();
    } catch (Exception e) {
      assertEquals(expected, e);
    }
  }
Example #2
0
  @Test
  public void shouldVerifyStringVarargs() {
    mock.withStringVarargs(1);
    mock.withStringVarargs(2, "1", "2", "3");
    mock.withStringVarargs(3, "1", "2", "3", "4");

    verify(mock).withStringVarargs(1);
    verify(mock).withStringVarargs(2, "1", "2", "3");
    try {
      verify(mock).withStringVarargs(2, "1", "2", "79", "4");
      fail();
    } catch (ArgumentsAreDifferent e) {
    }
  }