|
5 | 5 | import com.uid2.shared.model.EncryptedPayload; |
6 | 6 | import com.uid2.shared.encryption.AesGcm; |
7 | 7 | import com.uid2.shared.model.KeysetKey; |
8 | | -import junit.framework.TestCase; |
9 | | -import org.junit.Assert; |
| 8 | +import org.junit.jupiter.api.Test; |
10 | 9 |
|
11 | 10 | import javax.crypto.SecretKey; |
12 | 11 | import javax.crypto.spec.SecretKeySpec; |
|
16 | 15 | import java.time.Instant; |
17 | 16 | import java.util.concurrent.ThreadLocalRandom; |
18 | 17 |
|
19 | | -public class EncryptionTest extends TestCase { |
| 18 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 19 | +import static org.junit.jupiter.api.Assertions.assertNotSame; |
20 | 20 |
|
| 21 | +class EncryptionTest { |
21 | 22 | private int count = 0; |
22 | 23 |
|
23 | | - public void testEncryption() throws Exception { |
24 | | - |
| 24 | + @Test |
| 25 | + void testEncryption() { |
25 | 26 | final KeysetKey key = new KeysetKey(1, Random.getRandomKeyBytes(), Instant.now(), Instant.now(), Instant.now(), 10); |
26 | 27 | final String testString = "[email protected]"; |
27 | 28 |
|
28 | 29 | final EncryptedPayload payload = AesCbc.encrypt(testString, key); |
29 | 30 | final byte[] decrypted = AesCbc.decrypt(payload.getPayload(), key); |
30 | 31 |
|
31 | 32 | final String decryptedString = new String(decrypted, StandardCharsets.UTF_8); |
32 | | - Assert.assertEquals(testString, decryptedString); |
| 33 | + assertEquals(testString, decryptedString); |
33 | 34 | } |
34 | 35 |
|
35 | | - public void testBenchmark() throws Exception { |
| 36 | + @Test |
| 37 | + void testBenchmark() { |
36 | 38 | if (System.getenv("SLOW_DEV_URANDOM") != null) { |
37 | 39 | System.err.println("ignore this test since environment variable SLOW_DEV_URANDOM is set"); |
38 | 40 | return; |
@@ -73,10 +75,14 @@ public void testBenchmark() throws Exception { |
73 | 75 | System.out.println("Decryption Overhead per Entry (ms) = " + overheadPerEntry / (1000000 * 1.0)); |
74 | 76 |
|
75 | 77 | // System.out.println("Entries = "+runs+", Base Operation Execution Time (ms) = " + baseTime/(1000000*1.0) + ", With Decryption(ms) = " + decryptTime/(1000000*1.0) + ", Overhead/Entry (ms) = " + ((decryptTime-baseTime)/(runs*1.0)/(1000000*1.0))); |
| 78 | + } |
76 | 79 |
|
| 80 | + private void doSomething(EncryptedPayload ep) { |
| 81 | + count++; |
77 | 82 | } |
78 | 83 |
|
79 | | - public void testSecureRandom() throws NoSuchAlgorithmException { |
| 84 | + @Test |
| 85 | + void testSecureRandom() { |
80 | 86 | if (System.getenv("SLOW_DEV_URANDOM") != null) { |
81 | 87 | System.err.println("ignore this test since environment variable SLOW_DEV_URANDOM is set"); |
82 | 88 | return; |
@@ -109,17 +115,15 @@ public void testSecureRandom() throws NoSuchAlgorithmException { |
109 | 115 | } |
110 | 116 | } |
111 | 117 |
|
112 | | - public void testNewInstancesReturned() throws NoSuchAlgorithmException { |
| 118 | + @Test |
| 119 | + void testNewInstancesReturned() throws NoSuchAlgorithmException { |
113 | 120 | SecureRandom r1 = SecureRandom.getInstance("SHA1PRNG"); |
114 | 121 | SecureRandom r2 = SecureRandom.getInstance("SHA1PRNG"); |
115 | 122 | assertNotSame(r1, r2); |
116 | 123 | } |
117 | 124 |
|
118 | | - public void doSomething(EncryptedPayload loag) { |
119 | | - count++; |
120 | | - } |
121 | | - |
122 | | - public void testGCMEncryptionDecryption() { |
| 125 | + @Test |
| 126 | + void testGCMEncryptionDecryption() { |
123 | 127 | final KeysetKey key = new KeysetKey(1, Random.getRandomKeyBytes(), Instant.now(), Instant.now(), Instant.now(), 10); |
124 | 128 | String plaintxt = "hello world"; |
125 | 129 | EncryptedPayload payload = AesGcm.encrypt(plaintxt.getBytes(StandardCharsets.UTF_8), key); |
|
0 commit comments