use of com.sun.tck.lib.ExecuteIfNot 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);
}
}
Aggregations