public Object invoke(Object receiver, Method method, Object[] args) throws Throwable { return mockObject.invoke(new Invocation(receiver, method, args)); } },
@Override public Object invoke(Object self, Method thisMethod, Method proceed, Object[] args) throws Throwable { return mockObject.invoke(new Invocation(self, thisMethod, args)); } });
public Object invoke(Invocation invocation) throws Throwable { Invocation buildingInvocation = new Invocation(ExpectationMode.BUILDING,invocation); capture.createExpectationFrom(buildingInvocation); return defaultAction.invoke(buildingInvocation); } }
public static Invocation invocationReturning(Class<?> resultType) { return new Invocation("INVOKED-OBJECT", METHOD_FACTORY.newMethodReturning(resultType), NO_ARG_VALUES); }
public void testPerformsObjectMethodsEvenWhenTheyAreOverridden() throws Throwable { Method overriddenToString = ClassOverridingToString.class.getMethod("toString"); assertEquals("an Invocation of overridden toString", next.toStringResult, id.invoke(new Invocation(invokedObject, overriddenToString))); } }
public void testReturnTypeCheckAllowsReturningBoxedTypeFromMethodWithPrimitiveReturnType() { Invocation invocation = new Invocation(INVOKED, methodFactory.newMethodReturning(int.class)); invocation.checkReturnTypeCompatibility(new Integer(0)); }
public void testReturnTypeCheckAllowsReturningNullFromVoidMethod() { Invocation invocation = new Invocation(INVOKED, methodFactory.newMethodReturning(void.class)); invocation.checkReturnTypeCompatibility(null); }
public void testMatchesAnythingByDefault() { assertTrue("should match", expectation.matches( new Invocation(new Object(), methodFactory.newMethod("method"), Invocation.NO_PARAMETERS))); assertTrue("should match", expectation.matches( new Invocation(new Object(), methodFactory.newMethod("anotherMethod"), new Object[]{1,2,3,4}))); }
public void testReturnTypeCheckAllowsReturningNullFromMethodWithNonPrimitiveReturnType() { Invocation invocation = new Invocation(INVOKED, methodFactory.newMethodReturning(String.class)); invocation.checkReturnTypeCompatibility(null); }
public void testReturnsNullIfHasNoActionsWhenInvoked() throws Throwable { Invocation invocation = new Invocation(targetObject, method, Invocation.NO_PARAMETERS); Object actualResult = expectation.invoke(invocation); assertNull("should have returned null", actualResult); }
public void testAppliesInvocationToGivenObjectIfInvokedMethodDeclaredInGivenClass() throws Throwable { Invocation invocation = new Invocation("invokedObject", TargetInterface.class.getMethod("doSomething"), Invocation.NO_PARAMETERS); diverter.invoke(invocation); assertTrue("target should have been invoked", target.wasInvoked); assertTrue("next should not have been invoked", !next.wasInvoked); }
public void testReturnsValuePassedToConstructor() throws Throwable { invocation = new Invocation(invokedObject, methodFactory.newMethodReturning(RESULT.getClass())); assertSame("Should be the same result object", RESULT, returnValueAction .invoke(invocation)); }
@RuntimeType static public Object intercept( @This Object receiver, @Origin Method method, @FieldValue(value=JMOCK_KEY) Invokable invokable, @AllArguments Object[] args ) throws Throwable { return invokable.invoke(new Invocation(receiver, method, args)); } }
@RuntimeType static public Object intercept( @This Object receiver, @Origin Method method, @FieldValue(value=JMOCK_KEY) Invokable invokable, @AllArguments Object[] args ) throws Throwable { return invokable.invoke(new Invocation(receiver, method, args)); } }
public void testDelegatesToStringToNextInvokable() throws Throwable { Method toString = Object.class.getMethod("toString"); assertEquals("an Invocation of toString", next.toStringResult, id.invoke(new Invocation(invokedObject, toString))); assertEquals("directly invoked toString", next.toStringResult, id.toString()); }
public void testCanApplyInvocationToAnotherObject() throws Throwable { Target target = new Target(); target.result = "result"; Invocation invocation = new Invocation("receiver", TargetInterface.class.getMethod("doSomething", String.class), new Object[]{"arg"}); String actualResult = (String)invocation.applyTo(target); assertEquals("received argument", "arg", target.receivedArg); assertEquals("result returned from apply", target.result, actualResult); }
public void testMethodToStringWithNullArg() throws Exception { Invocation invocation = new Invocation(INVOKED, methodFactory.newMethod(METHOD_NAME, new Class[]{String.class}, void.class, EXCEPTION_TYPES), new Object[]{null}); String result = invocation.toString(); AssertThat.stringIncludes("Should contain invokedMethod name", METHOD_NAME, result); AssertThat.stringIncludes("Should contain firstArg", "null", result); }
public void testCanReturnNullReference() throws Throwable { invocation = new Invocation(invokedObject, methodFactory.newMethodReturning(String.class)); returnValueAction = new ReturnValueAction(null); assertNull("should return null", returnValueAction.invoke(invocation)); } }
public void testToStringWithStringArray() throws Exception { Invocation invocation = new Invocation(INVOKED, methodFactory.newMethod(METHOD_NAME, new Class[]{String[].class}, void.class, EXCEPTION_TYPES), new Object[]{new String[]{"arg1", "arg2"}}); String result = invocation.toString(); AssertThat.stringIncludes("Should contain method name", METHOD_NAME, result); AssertThat.stringIncludes("Should contain args as an array", "[\"arg1\", \"arg2\"]", result); }
public void testToStringWithTwoArguments() throws Exception { Invocation invocation = new Invocation(INVOKED, methodFactory.newMethod(METHOD_NAME, new Class[]{String.class, String.class}, void.class, EXCEPTION_TYPES), new Object[]{"arg1", "arg2"}); String result = invocation.toString(); AssertThat.stringIncludes("Should contain object name", INVOKED.toString(), result); AssertThat.stringIncludes("Should contain method name", METHOD_NAME, result); AssertThat.stringIncludes("Should contain firstArg", "arg1", result); AssertThat.stringIncludes("Should contain second Arg", "arg2", result); }