コード例 #1
0
ファイル: CustomMatchersTest.java プロジェクト: bric3/mockito
  @Test
  public void shouldUseCustomObjectMatcher() {
    when(mock.oneArg(argThat(new ContainsFoo()))).thenReturn("foo");

    assertEquals("foo", mock.oneArg("foo"));
    assertEquals(null, mock.oneArg("bar"));
  }
コード例 #2
0
ファイル: CustomMatchersTest.java プロジェクト: bric3/mockito
  @Test
  public void shouldUseCustomCharMatcher() {
    when(mock.oneArg(charThat(new IsSorZ()))).thenReturn("foo");

    assertEquals("foo", mock.oneArg('s'));
    assertEquals("foo", mock.oneArg('z'));
    assertEquals(null, mock.oneArg('x'));
  }
コード例 #3
0
ファイル: CustomMatchersTest.java プロジェクト: bric3/mockito
  @Test
  public void shouldUseCustomBooleanMatcher() {
    when(mock.oneArg(booleanThat(new IsAnyBoolean()))).thenReturn("foo");

    assertEquals("foo", mock.oneArg(true));
    assertEquals("foo", mock.oneArg(false));

    assertEquals(null, mock.oneArg("x"));
  }
コード例 #4
0
ファイル: CustomMatchersTest.java プロジェクト: bric3/mockito
  @Test
  public void shouldUseCustomPrimitiveNumberMatchers() {
    when(mock.oneArg(byteThat(new IsZeroOrOne<Byte>()))).thenReturn("byte");
    when(mock.oneArg(shortThat(new IsZeroOrOne<Short>()))).thenReturn("short");
    when(mock.oneArg(intThat(new IsZeroOrOne<Integer>()))).thenReturn("int");
    when(mock.oneArg(longThat(new IsZeroOrOne<Long>()))).thenReturn("long");
    when(mock.oneArg(floatThat(new IsZeroOrOne<Float>()))).thenReturn("float");
    when(mock.oneArg(doubleThat(new IsZeroOrOne<Double>()))).thenReturn("double");

    assertEquals("byte", mock.oneArg((byte) 0));
    assertEquals("short", mock.oneArg((short) 1));
    assertEquals("int", mock.oneArg(0));
    assertEquals("long", mock.oneArg(1L));
    assertEquals("float", mock.oneArg(0F));
    assertEquals("double", mock.oneArg(1.0));

    assertEquals(null, mock.oneArg(2));
    assertEquals(null, mock.oneArg("foo"));
  }