Ejemplo n.º 1
0
  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");
  }
Ejemplo n.º 2
0
 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);
 }
Ejemplo n.º 3
0
  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");
  }
Ejemplo n.º 4
0
 private Invocation invocationReturning(Class resultType) {
   return new Invocation(
       "INVOKED-OBJECT", METHOD_FACTORY.newMethodReturning(resultType), NO_ARG_VALUES);
 }