Skip to content

Commit 12004e6

Browse files
committed
Tests: use Rule for ChaCha/Des3 availability instead of BeforeClass Assume
1 parent 45939a9 commit 12004e6

2 files changed

Lines changed: 26 additions & 10 deletions

File tree

src/test/java/com/wolfssl/wolfcrypt/test/ChachaTest.java

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.junit.rules.TestRule;
3333
import org.junit.rules.TestWatcher;
3434
import org.junit.runner.Description;
35+
import org.junit.runners.model.Statement;
3536

3637
import com.wolfssl.wolfcrypt.Chacha;
3738
import com.wolfssl.wolfcrypt.NativeStruct;
@@ -73,16 +74,31 @@ public class ChachaTest {
7374
@Rule(order = Integer.MIN_VALUE)
7475
public TestRule testWatcher = TimedTestWatcher.create();
7576

76-
@BeforeClass
77-
public static void checkAvailability() {
78-
try {
79-
new Chacha();
80-
System.out.println("JNI Chacha Class");
81-
} catch (WolfCryptException e) {
82-
if (e.getError() == WolfCryptError.NOT_COMPILED_IN)
83-
System.out.println("Chacha test skipped: " + e.getError());
84-
Assume.assumeNoException(e);
77+
/* Rule to check if ChaCha is available, skips tests if not.
78+
* Chacha() constructor does not allocate native memory, so no
79+
* need to release if it throws. */
80+
@Rule(order = Integer.MIN_VALUE + 1)
81+
public TestRule chachaAvailable = new TestRule() {
82+
@Override
83+
public Statement apply(final Statement base, Description description) {
84+
return new Statement() {
85+
@Override
86+
public void evaluate() throws Throwable {
87+
try {
88+
new Chacha();
89+
} catch (WolfCryptException e) {
90+
Assume.assumeTrue("ChaCha not compiled in: " +
91+
e.getError(), false);
92+
}
93+
base.evaluate();
94+
}
95+
};
8596
}
97+
};
98+
99+
@BeforeClass
100+
public static void testPrintClassName() {
101+
System.out.println("JNI Chacha Class");
86102
}
87103

88104
@Test

src/test/java/com/wolfssl/wolfcrypt/test/Des3Test.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public void evaluate() throws Throwable {
7878
};
7979

8080
@BeforeClass
81-
public static void checkAvailability() {
81+
public static void testPrintClassName() {
8282
System.out.println("JNI Des3 Class");
8383
}
8484

0 commit comments

Comments
 (0)