public Object invoke(Invocation invocation) throws Throwable { invocationCount++; performSideEffects(); final Object result = action.invoke(new Invocation(ExpectationMode.ASSERTING, invocation)); invocation.checkReturnTypeCompatibility(result); return result; }
public void testReturnTypeCheckAllowsReturningBoxedTypeFromMethodWithPrimitiveReturnType() { Invocation invocation = new Invocation(INVOKED, methodFactory.newMethodReturning(int.class)); invocation.checkReturnTypeCompatibility(new Integer(0)); }
public void testReturnTypeCheckAllowsReturningNullFromMethodWithNonPrimitiveReturnType() { Invocation invocation = new Invocation(INVOKED, methodFactory.newMethodReturning(String.class)); invocation.checkReturnTypeCompatibility(null); }
public void testReturnTypeCheckAllowsReturningNullFromVoidMethod() { Invocation invocation = new Invocation(INVOKED, methodFactory.newMethodReturning(void.class)); invocation.checkReturnTypeCompatibility(null); }
public void testReturnTypeCheckFailsIfReturnedValueIsIncompatible() { Invocation invocation = new Invocation(INVOKED, methodFactory.newMethodReturning(int.class)); try { invocation.checkReturnTypeCompatibility("string result"); } catch (IllegalStateException ex) { AssertThat.stringIncludes("expected return type", int.class.toString(), ex.getMessage()); AssertThat.stringIncludes("returned value type", String.class.getName(), ex.getMessage()); return; } fail("should have failed"); }
public void testReturnTypeCheckFailsWhenReturningNullFromMethodWithPrimitiveReturnType() { Invocation invocation = new Invocation(INVOKED, methodFactory.newMethodReturning(int.class)); try { invocation.checkReturnTypeCompatibility(null); } catch (IllegalStateException ex) { AssertThat.stringIncludes("expected return type", int.class.toString(), ex.getMessage()); AssertThat.stringIncludes("null", String.valueOf((Object)null), ex.getMessage()); return; } fail("should have failed"); }
public void testReturnTypeCheckFailsIfReturningValueFromVoidMethod() { Invocation invocation = new Invocation(INVOKED, methodFactory.newMethodReturning(void.class)); try { invocation.checkReturnTypeCompatibility("string result"); } catch (IllegalStateException ex) { AssertThat.stringIncludes("should describe error", "tried to return a value from a void method", ex.getMessage()); return; } fail("should have failed"); }