Search in sources :

Example 1 with CapturingMatcher

use of org.mockito.internal.matchers.CapturingMatcher in project mockito by mockito.

the class InvocationMatcherTest method should_capture_varargs_as_vararg.

@Test
public void should_capture_varargs_as_vararg() throws Exception {
    //given
    mock.mixedVarargs(1, "a", "b");
    Invocation invocation = getLastInvocation();
    CapturingMatcher m = new CapturingMatcher();
    InvocationMatcher invocationMatcher = new InvocationMatcher(invocation, Arrays.<ArgumentMatcher>asList(new Equals(1), m));
    //when
    invocationMatcher.captureArgumentsFrom(invocation);
    //then
    Assertions.assertThat(m.getAllValues()).containsExactly("a", "b");
}
Also used : Equals(org.mockito.internal.matchers.Equals) TestCase.assertEquals(junit.framework.TestCase.assertEquals) Invocation(org.mockito.invocation.Invocation) CapturingMatcher(org.mockito.internal.matchers.CapturingMatcher) Test(org.junit.Test)

Example 2 with CapturingMatcher

use of org.mockito.internal.matchers.CapturingMatcher in project mockito by mockito.

the class InvocationMatcherTest method should_capture_arguments_from_invocation.

@Test
public void should_capture_arguments_from_invocation() throws Exception {
    //given
    Invocation invocation = new InvocationBuilder().args("1", 100).toInvocation();
    CapturingMatcher capturingMatcher = new CapturingMatcher();
    InvocationMatcher invocationMatcher = new InvocationMatcher(invocation, (List) asList(new Equals("1"), capturingMatcher));
    //when
    invocationMatcher.captureArgumentsFrom(invocation);
    //then
    assertEquals(1, capturingMatcher.getAllValues().size());
    assertEquals(100, capturingMatcher.getLastValue());
}
Also used : Equals(org.mockito.internal.matchers.Equals) TestCase.assertEquals(junit.framework.TestCase.assertEquals) Invocation(org.mockito.invocation.Invocation) CapturingMatcher(org.mockito.internal.matchers.CapturingMatcher) Test(org.junit.Test)

Aggregations

TestCase.assertEquals (junit.framework.TestCase.assertEquals)2 Test (org.junit.Test)2 CapturingMatcher (org.mockito.internal.matchers.CapturingMatcher)2 Equals (org.mockito.internal.matchers.Equals)2 Invocation (org.mockito.invocation.Invocation)2