|
32 | 32 | import org.junit.rules.TestRule; |
33 | 33 | import org.junit.rules.TestWatcher; |
34 | 34 | import org.junit.runner.Description; |
| 35 | +import org.junit.runners.model.Statement; |
35 | 36 |
|
36 | 37 | import com.wolfssl.wolfcrypt.Chacha; |
37 | 38 | import com.wolfssl.wolfcrypt.NativeStruct; |
@@ -73,16 +74,31 @@ public class ChachaTest { |
73 | 74 | @Rule(order = Integer.MIN_VALUE) |
74 | 75 | public TestRule testWatcher = TimedTestWatcher.create(); |
75 | 76 |
|
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 | + }; |
85 | 96 | } |
| 97 | + }; |
| 98 | + |
| 99 | + @BeforeClass |
| 100 | + public static void testPrintClassName() { |
| 101 | + System.out.println("JNI Chacha Class"); |
86 | 102 | } |
87 | 103 |
|
88 | 104 | @Test |
|
0 commit comments