示例#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);
    }
  }
示例#2
0
  @Test
  // See bug #157
  public void shouldMatchEasilyEmptyVararg() throws Exception {
    // when
    when(mock.foo(anyVararg())).thenReturn(-1);

    // then
    assertEquals(-1, mock.foo());
  }
示例#3
0
  @Test
  public void shouldVerifyObjectVarargs() {
    mock.withObjectVarargs(1);
    mock.withObjectVarargs(2, "1", new ArrayList<Object>(), new Integer(1));
    mock.withObjectVarargs(3, new Integer(1));

    verify(mock).withObjectVarargs(1);
    verify(mock).withObjectVarargs(2, "1", new ArrayList<Object>(), new Integer(1));
    try {
      verifyNoMoreInteractions(mock);
      fail();
    } catch (NoInteractionsWanted e) {
    }
  }
示例#4
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) {
    }
  }
示例#5
0
  @Test
  public void shouldVerifyBooleanVarargs() {
    mock.withBooleanVarargs(1);
    mock.withBooleanVarargs(2, true, false, true);
    mock.withBooleanVarargs(3, true, true, true);

    verify(mock).withBooleanVarargs(1);
    verify(mock).withBooleanVarargs(2, true, false, true);
    try {
      verify(mock).withBooleanVarargs(3, true, true, true, true);
      fail();
    } catch (ArgumentsAreDifferent e) {
    }
  }
示例#6
0
  @Test
  public void shouldStubBooleanVarargs() {
    when(mock.withBooleanVarargs(1)).thenReturn(true);
    when(mock.withBooleanVarargs(1, true, false)).thenReturn(true);

    assertEquals(true, mock.withBooleanVarargs(1));
    assertEquals(false, mock.withBooleanVarargs(9999));

    assertEquals(true, mock.withBooleanVarargs(1, true, false));
    assertEquals(false, mock.withBooleanVarargs(1, true, false, true));
    assertEquals(false, mock.withBooleanVarargs(2, true, false));
    assertEquals(false, mock.withBooleanVarargs(1, true));
    assertEquals(false, mock.withBooleanVarargs(1, false, false));
  }