Tests: use Rule for ChaCha/Des3 availability instead of BeforeClass Assume

pull/209/head
Chris Conlon 2026-04-02 09:52:22 -06:00
parent e8c6eea43f
commit c67e53631a
2 changed files with 26 additions and 10 deletions

View File

@ -32,6 +32,7 @@ import org.junit.Rule;
import org.junit.rules.TestRule;
import org.junit.rules.TestWatcher;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
import com.wolfssl.wolfcrypt.Chacha;
import com.wolfssl.wolfcrypt.NativeStruct;
@ -73,16 +74,31 @@ public class ChachaTest {
@Rule(order = Integer.MIN_VALUE)
public TestRule testWatcher = TimedTestWatcher.create();
@BeforeClass
public static void checkAvailability() {
/* Rule to check if ChaCha is available, skips tests if not.
* Chacha() constructor does not allocate native memory, so no
* need to release if it throws. */
@Rule(order = Integer.MIN_VALUE + 1)
public TestRule chachaAvailable = new TestRule() {
@Override
public Statement apply(final Statement base, Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
try {
new Chacha();
System.out.println("JNI Chacha Class");
} catch (WolfCryptException e) {
if (e.getError() == WolfCryptError.NOT_COMPILED_IN)
System.out.println("Chacha test skipped: " + e.getError());
Assume.assumeNoException(e);
Assume.assumeTrue("ChaCha not compiled in: " +
e.getError(), false);
}
base.evaluate();
}
};
}
};
@BeforeClass
public static void testPrintClassName() {
System.out.println("JNI Chacha Class");
}
@Test

View File

@ -78,7 +78,7 @@ public class Des3Test {
};
@BeforeClass
public static void checkAvailability() {
public static void testPrintClassName() {
System.out.println("JNI Des3 Class");
}