Package org.mockito.invocation

Examples of org.mockito.invocation.Invocation


    @Test
    public void shouldMatchAnyVarargEvenIfOneOfTheArgsIsNull() {
        //given
        mock.mixedVarargs(null, null, "2");
        Invocation invocation = getLastInvocation();
        InvocationMatcher invocationMatcher = new InvocationMatcher(invocation, (List) asList(new Equals(null), AnyVararg.ANY_VARARG));

        //when
        boolean match = comparator.argumentsMatch(invocationMatcher, invocation);
View Full Code Here


    @Test
    public void shouldMatchAnyVarargEvenIfMatcherIsDecorated() {
        //given
        mock.varargs("1", "2");
        Invocation invocation = getLastInvocation();
        InvocationMatcher invocationMatcher = new InvocationMatcher(invocation, (List) asList(new LocalizedMatcher(AnyVararg.ANY_VARARG)));

        //when
        boolean match = comparator.argumentsMatch(invocationMatcher, invocation);
View Full Code Here

public class MethodInfoTest {

    @Test
    public void shouldKnowValidThrowables() throws Exception {
        //when
        Invocation invocation = new InvocationBuilder().method("canThrowException").toInvocation();
        MethodInfo info = new MethodInfo(invocation);

        //then
        assertFalse(info.isValidException(new Exception()));
        assertTrue(info.isValidException(new CharacterCodingException()));
View Full Code Here

        invocation = new InvocationBuilder().args(" ").mock("mock").toInvocation();
    }

    @Test
    public void shouldKnowIfIsEqualTo() {
        Invocation equal =                  new InvocationBuilder().args(" ").mock("mock").toInvocation();
        Invocation nonEqual =               new InvocationBuilder().args("X").mock("mock").toInvocation();
        Invocation withNewStringInstance =  new InvocationBuilder().args(new String(" ")).mock("mock").toInvocation();

        assertFalse(invocation.equals(null));
        assertFalse(invocation.equals(""));
        assertTrue(invocation.equals(equal));
        assertFalse(invocation.equals(nonEqual));
View Full Code Here

        assertTrue(invocation.equals(withNewStringInstance));
    }
   
    @Test
    public void shouldEqualToNotConsiderSequenceNumber() {
        Invocation equal = new InvocationBuilder().args(" ").mock("mock").seq(2).toInvocation();
       
        assertTrue(invocation.equals(equal));
        assertTrue(invocation.getSequenceNumber() != equal.getSequenceNumber());
    }
View Full Code Here

                        ");"));
    }
   
    @Test
    public void shouldTransformArgumentsToMatchers() throws Exception {
        Invocation i = new InvocationBuilder().args("foo", new String[]{"bar"}).toInvocation();
        List matchers = ArgumentsProcessor.argumentsToMatchers(i.getArguments());

        assertEquals(2, matchers.size());
        assertEquals(Equals.class, matchers.get(0).getClass());
        assertEquals(ArrayEquals.class, matchers.get(1).getClass());
    }
View Full Code Here

    }
   
    @Test
    public void shouldBeAbleToCallRealMethod() throws Throwable {
        //when
        Invocation invocation = invocationOf(Foo.class, "bark", new RealMethod() {
            public Object invoke(Object target, Object[] arguments) throws Throwable {
                return new Foo().bark();
            }});
        //then
        assertEquals("woof", invocation.callRealMethod());
    }
View Full Code Here

    }
   
    @Test
    public void shouldScreamWhenCallingRealMethodOnInterface() throws Throwable {
        //given
        Invocation invocationOnInterface = new InvocationBuilder().toInvocation();

        try {
            //when
            invocationOnInterface.callRealMethod();
            //then
            fail();
        } catch(MockitoException e) {}
    }
View Full Code Here

   
    @Test
    public void shouldReturnCastedArgumentAt(){
        //given
        int argument = 42;
        Invocation invocationOnInterface = new InvocationBuilder().method("twoArgumentMethod").
            argTypes(int.class, int.class).args(1, argument).toInvocation();

        //when
        int secondArgument = invocationOnInterface.getArgumentAt(1, int.class);

        //then
        assertTrue(secondArgument == argument);
    }
View Full Code Here

   
    @Test
    public void shouldVerifyInOrder() {
        //given
        NoMoreInteractions n = new NoMoreInteractions();
        Invocation i = new InvocationBuilder().toInvocation();
        assertFalse(context.isVerified(i));
       
        try {
            //when
            n.verifyInOrder(new VerificationDataInOrderImpl(context, asList(i), null));
View Full Code Here

TOP

Related Classes of org.mockito.invocation.Invocation

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.