Search in sources :

Example 1 with TestFailedException

use of com.sun.tck.lib.TestFailedException in project jtharness by openjdk.

the class DefaultExecutionResult method process.

/**
 * {@inheritDoc}
 */
@Override
public void process(TestCaseContext.TestCaseLifePhase lifePhase, TestCaseContext context) {
    TestResult result;
    Throwable t = AUTD2Utils.unwrapCoreExceptionFromITEs(context);
    if (t == null) {
        Object testCaseReturnedResult = context.getTestCaseResult().getResult();
        if (testCaseReturnedResult != null) {
            // setting tight policy for what a testcase method can return by default
            // to catch mistakes since a non-void return value is not processed
            // anyhow by this processor and would be basically lost
            // even if the returned result reflects a failure.
            String nonVoidResult = format("Testcase \"{0}\" returned unrecognized value {1}" + ", but it is expected to return void", context.getTestCaseName(), testCaseReturnedResult);
            result = TestResult.failure(nonVoidResult);
        } else {
            result = OK_RESULT;
        }
    } else {
        if (t instanceof ClassCastException || t instanceof IllegalArgumentException) {
            // todo share this with exp exceptions processor
            result = TestResult.failure(unmatchedArgsExceptionThrown(t.getClass().getSimpleName(), context, t, context.getTestCaseMethod(), context.getTestCaseInvocationArgValues()));
        } else if (t instanceof SomethingIsWrong) {
            // todo share this with exp exceptions processor
            context.printlnToLog(t.getMessage());
            result = TestResult.failure(t.getMessage());
        } else if (t instanceof NotApplicableException) {
            // todo share this with exp exceptions processor
            String message = t.getMessage();
            context.recordNotApplicable();
            result = new InapplicableTestResult("Not applicable." + (message != null ? " Reason: " + message : ""), message);
        } else if (t instanceof TestFailedException) {
            testFailed(context.getTestCaseNameWithIndex(), t, context);
            result = TestResult.failure(t.getMessage());
        } else {
            String unexpectedThrown = format("Testcase \"{0}\" has thrown an unexpected exception {1}", context.getTestCaseNameWithIndex(), t);
            context.getParentContext().printlnToLog(unexpectedThrown);
            context.getParentContext().printStackTraceToLog(t);
            result = TestResult.failure(unexpectedThrown);
        }
    }
    context.addExecutionResult(context.getTestCaseName(), result);
    context.clearTestCaseResult();
}
Also used : SomethingIsWrong(com.sun.tck.lib.tgf.SomethingIsWrong) TestFailedException(com.sun.tck.lib.TestFailedException) NotApplicableException(com.sun.tck.lib.NotApplicableException) TestResult(com.oracle.tck.lib.autd2.TestResult)

Aggregations

TestResult (com.oracle.tck.lib.autd2.TestResult)1 NotApplicableException (com.sun.tck.lib.NotApplicableException)1 TestFailedException (com.sun.tck.lib.TestFailedException)1 SomethingIsWrong (com.sun.tck.lib.tgf.SomethingIsWrong)1