public void testThrowsAssertionFailedErrorIfTriesToThrowIncompatibleCheckedException() throws Throwable { Class[] expectedExceptionTypes = {ExpectedExceptionType1.class, ExpectedExceptionType2.class}; Invocation incompatibleInvocation = new Invocation( "INVOKED-OBJECT", methodFactory.newMethod( "methodName", MethodFactory.NO_ARGUMENTS, void.class, expectedExceptionTypes), null); try { throwStub.invoke(incompatibleInvocation); } catch (AssertionFailedError ex) { String message = ex.getMessage(); for (int i = 0; i < expectedExceptionTypes.length; i++) { AssertMo.assertIncludes( "should include name of expected exception types", expectedExceptionTypes[i].getName(), message); } AssertMo.assertIncludes( "should include name of thrown exception type", THROWABLE.getClass().getName(), message); return; } fail("should have failed"); }
public void setUp() { methodFactory = new MethodFactory(); invocation = new Invocation( "INVOKED-OBJECT", methodFactory.newMethod( "methodName", MethodFactory.NO_ARGUMENTS, void.class, EXCEPTION_TYPES), null); throwStub = new ThrowStub(THROWABLE); }
public void testGivesInformativeErrorMessageIfAttemptToThrowCheckedExceptionFromMethodWithNoExceptions() throws Throwable { Invocation incompatibleInvocation = new Invocation( "INVOKED-OBJECT", methodFactory.newMethod( "methodName", MethodFactory.NO_ARGUMENTS, void.class, MethodFactory.NO_EXCEPTIONS), null); try { throwStub.invoke(incompatibleInvocation); } catch (AssertionFailedError ex) { String message = ex.getMessage(); AssertMo.assertIncludes( "should include name of thrown exception type", THROWABLE.getClass().getName(), message); AssertMo.assertIncludes( "should describe that the method doesn't allow any exceptions", "no exceptions", message); return; } fail("should have failed"); }
private Invocation invocationReturning(Class resultType) { return new Invocation( "INVOKED-OBJECT", METHOD_FACTORY.newMethodReturning(resultType), NO_ARG_VALUES); }