Search in sources :

Example 1 with ExecuteIf

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

the class TestDataCollector method checkIfTestCaseShouldBeExecuted.

/**
 * Checking for @ExecuteIf(Not) annotations.
 * May throw <code>SomethingIsWrong</code> exception or <code>NotApplicableException</code>
 */
public static void checkIfTestCaseShouldBeExecuted(Method method, Object testInstance, Class<?> testClass, PrintWriter log) {
    ExecuteIf executeIf = method.getAnnotation(ExecuteIf.class);
    ExecuteIfNot executeIfNot = method.getAnnotation(ExecuteIfNot.class);
    if (executeIf == null && executeIfNot == null) {
        return;
    }
    if (executeIf != null && executeIfNot != null) {
        throw new SomethingIsWrong("@ExecuteIf and @ExecuteIfNot could not be used together for one testcase");
    }
    String fieldOrMethodName;
    String reason;
    if (executeIf != null) {
        fieldOrMethodName = executeIf.value();
        reason = executeIf.reason();
    } else {
        fieldOrMethodName = executeIfNot.value();
        reason = executeIfNot.reason();
    }
    Boolean booleanResult;
    try {
        booleanResult = (Boolean) TGFUtils.getRawDataFromTextReference(testInstance, testClass, log, fieldOrMethodName, executeIf != null ? "@ExecuteIf" : "@ExecuteIfNot");
    } catch (ClassCastException e) {
        throw new SomethingIsWrong("\"" + fieldOrMethodName + "\" should be of boolean type");
    }
    if (booleanResult == null) {
        throw new SomethingIsWrong("\"" + fieldOrMethodName + "\" has null value or returned null");
    }
    if (executeIf != null && !booleanResult || executeIfNot != null && booleanResult) {
        throw new NotApplicableException(reason);
    }
}
Also used : ExecuteIfNot(com.sun.tck.lib.ExecuteIfNot) NotApplicableException(com.sun.tck.lib.NotApplicableException) ExecuteIf(com.sun.tck.lib.ExecuteIf)

Aggregations

ExecuteIf (com.sun.tck.lib.ExecuteIf)1 ExecuteIfNot (com.sun.tck.lib.ExecuteIfNot)1 NotApplicableException (com.sun.tck.lib.NotApplicableException)1