Skip to content
This repository was archived by the owner on Nov 24, 2024. It is now read-only.

Commit 8017c9e

Browse files
committed
Move tests to JUnit 5
1 parent 0e6e693 commit 8017c9e

File tree

3 files changed

+48
-51
lines changed

3 files changed

+48
-51
lines changed

pom.xml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,8 @@
4747
<scope>provided</scope>
4848
</dependency>
4949
<dependency>
50-
<groupId>junit</groupId>
51-
<artifactId>junit</artifactId>
52-
<version>4.13.2</version>
50+
<groupId>org.junit.jupiter</groupId>
51+
<artifactId>junit-jupiter</artifactId>
5352
<scope>test</scope>
5453
</dependency>
5554
</dependencies>

src/test/java/org/sonatype/plexus/components/cipher/DefaultPlexusCipherTest.java

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -12,37 +12,35 @@
1212
*/
1313
package org.sonatype.plexus.components.cipher;
1414

15-
import org.junit.Before;
16-
import org.junit.Test;
15+
import org.junit.jupiter.api.BeforeEach;
16+
import org.junit.jupiter.api.Test;
1717

18-
import static org.junit.Assert.assertEquals;
19-
import static org.junit.Assert.assertFalse;
20-
import static org.junit.Assert.assertNotNull;
21-
import static org.junit.Assert.assertTrue;
22-
import static org.junit.Assert.fail;
18+
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
19+
import static org.junit.jupiter.api.Assertions.assertEquals;
20+
import static org.junit.jupiter.api.Assertions.assertFalse;
21+
import static org.junit.jupiter.api.Assertions.assertNotNull;
22+
import static org.junit.jupiter.api.Assertions.assertTrue;
2323

2424
/**
2525
* Test the Plexus Cipher container
2626
*
2727
* @author Oleg Gusakov
2828
*/
29-
public class DefaultPlexusCipherTest {
29+
class DefaultPlexusCipherTest {
3030
private final String passPhrase = "testtest";
3131

3232
final String str = "my testing phrase";
3333

3434
final String encStr = "cYrPoOelYU0HGlsn3nERAIyiLVVgnsn/KC5ZqeAPG0beOZCYrFwWwBTp3uyxt/yx";
35+
PlexusCipher pc;
3536

36-
DefaultPlexusCipher pc;
37-
38-
// -------------------------------------------------------------
39-
@Before
40-
public void prepare() {
37+
@BeforeEach
38+
void prepare() {
4139
pc = new DefaultPlexusCipher();
4240
}
4341

4442
@Test
45-
public void testIsEncryptedString() {
43+
void testIsEncryptedString() {
4644
String noBraces = "This is a test";
4745
String normalBraces = "Comment {This is a test} other comment with a: }";
4846
String escapedBraces = "\\{This is a test\\}";
@@ -58,7 +56,7 @@ public void testIsEncryptedString() {
5856
}
5957

6058
@Test
61-
public void testUnDecorate_BracesPermutations() throws PlexusCipherException {
59+
void testUnDecorate_BracesPermutations() throws PlexusCipherException {
6260
String noBraces = "This is a test";
6361
String normalBraces = "Comment {This is a test} other comment with a: }";
6462
String mixedBraces = "Comment {foo\\{This is a test\\}} other comment with a: }";
@@ -71,9 +69,9 @@ public void testUnDecorate_BracesPermutations() throws PlexusCipherException {
7169
// -------------------------------------------------------------
7270

7371
@Test
74-
public void testDefaultAlgorithmExists() throws Exception {
72+
void testDefaultAlgorithmExists() throws Exception {
7573
String[] res = DefaultPlexusCipher.getCryptoImpls("Cipher");
76-
assertNotNull("No Cipher providers found in the current environment", res);
74+
assertNotNull(res, "No Cipher providers found in the current environment");
7775

7876
System.out.println("\n=== Available ciphers :");
7977
for (String re : res) {
@@ -91,12 +89,12 @@ public void testDefaultAlgorithmExists() throws Exception {
9189
// -------------------------------------------------------------
9290

9391
@Test
94-
public void stestFindDefaultAlgorithm() {
92+
void stestFindDefaultAlgorithm() {
9593
String[] res = DefaultPlexusCipher.getServiceTypes();
96-
assertNotNull("No service types found in the current environment", res);
94+
assertNotNull(res, "No service types found in the current environment");
9795

9896
String[] impls = DefaultPlexusCipher.getCryptoImpls("Cipher");
99-
assertNotNull("No Cipher providers found in the current environment", impls);
97+
assertNotNull(impls, "No Cipher providers found in the current environment");
10098

10199
for (String impl : impls)
102100
try {
@@ -110,20 +108,20 @@ public void stestFindDefaultAlgorithm() {
110108

111109
// -------------------------------------------------------------
112110
@Test
113-
public void testEncrypt() throws Exception {
111+
void testEncrypt() throws Exception {
114112
String xRes = pc.encrypt(str, passPhrase);
115113

116114
System.out.println(xRes);
117115

118116
String res = pc.decrypt(xRes, passPhrase);
119117

120-
assertEquals("Encryption/Decryption did not produce desired result", str, res);
118+
assertEquals(str, res, "Encryption/Decryption did not produce desired result");
121119
}
122120

123121
// -------------------------------------------------------------
124122

125123
@Test
126-
public void testEncryptVariableLengths() throws Exception {
124+
void testEncryptVariableLengths() throws Exception {
127125
String pass = "g";
128126

129127
for (int i = 0; i < 64; i++) {
@@ -135,44 +133,44 @@ public void testEncryptVariableLengths() throws Exception {
135133

136134
String res = pc.decrypt(xRes, pass);
137135

138-
assertEquals("Encryption/Decryption did not produce desired result", str, res);
136+
assertEquals(str, res, "Encryption/Decryption did not produce desired result");
139137
}
140138
}
141139

142140
@Test
143-
public void testDecrypt() {
144-
try {
145-
String res = pc.decrypt(encStr, passPhrase);
146-
assertEquals("Decryption did not produce desired result", str, res);
147-
} catch (Exception e) {
148-
fail("Decryption failed: " + e.getMessage());
149-
}
141+
void testDecrypt() {
142+
assertDoesNotThrow(
143+
() -> {
144+
String res = pc.decrypt(encStr, passPhrase);
145+
assertEquals(str, res, "Decryption did not produce desired result");
146+
},
147+
"Decryption failed: ");
150148
}
151149

152150
// -------------------------------------------------------------
153151

154152
@Test
155-
public void testDecorate() {
153+
void testDecorate() {
156154
String res = pc.decorate("aaa");
157155
assertEquals(
158-
"Decoration failed",
159156
PlexusCipher.ENCRYPTED_STRING_DECORATION_START + "aaa" + PlexusCipher.ENCRYPTED_STRING_DECORATION_STOP,
160-
res);
157+
res,
158+
"Decoration failed");
161159
}
162160

163161
// -------------------------------------------------------------
164162

165163
@Test
166-
public void testUnDecorate() throws Exception {
164+
void testUnDecorate() throws Exception {
167165
String res = pc.unDecorate(
168166
PlexusCipher.ENCRYPTED_STRING_DECORATION_START + "aaa" + PlexusCipher.ENCRYPTED_STRING_DECORATION_STOP);
169-
assertEquals("Decoration failed", "aaa", res);
167+
assertEquals("aaa", res, "Decoration failed");
170168
}
171169

172170
// -------------------------------------------------------------
173171

174172
@Test
175-
public void testEncryptAndDecorate() throws Exception {
173+
void testEncryptAndDecorate() throws Exception {
176174
String res = pc.encryptAndDecorate("my-password", "12345678");
177175

178176
assertEquals('{', res.charAt(0));

src/test/java/org/sonatype/plexus/components/cipher/PBECipherTest.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@ Licensed to the Apache Software Foundation (ASF) under one
1919

2020
package org.sonatype.plexus.components.cipher;
2121

22-
import org.junit.Before;
23-
import org.junit.Test;
22+
import org.junit.jupiter.api.BeforeEach;
23+
import org.junit.jupiter.api.Test;
2424

25-
import static org.junit.Assert.assertEquals;
26-
import static org.junit.Assert.assertNotEquals;
27-
import static org.junit.Assert.assertNotNull;
25+
import static org.junit.jupiter.api.Assertions.assertEquals;
26+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
27+
import static org.junit.jupiter.api.Assertions.assertNotNull;
2828

2929
/**
3030
* @author Oleg Gusakov
3131
*/
32-
public class PBECipherTest {
32+
class PBECipherTest {
3333
PBECipher pbeCipher;
3434

3535
final String clearText = "veryOpenText";
@@ -38,13 +38,13 @@ public class PBECipherTest {
3838

3939
final String password = "testtest";
4040

41-
@Before
42-
public void prepare() {
41+
@BeforeEach
42+
void prepare() {
4343
pbeCipher = new PBECipher();
4444
}
4545

4646
@Test
47-
public void testEncrypt() throws Exception {
47+
void testEncrypt() throws Exception {
4848
String enc = pbeCipher.encrypt64(clearText, password);
4949

5050
assertNotNull(enc);
@@ -61,14 +61,14 @@ public void testEncrypt() throws Exception {
6161
}
6262

6363
@Test
64-
public void testDecrypt() throws Exception {
64+
void testDecrypt() throws Exception {
6565
String clear = pbeCipher.decrypt64(encryptedText, password);
6666

6767
assertEquals(clearText, clear);
6868
}
6969

7070
@Test
71-
public void testEncoding() throws Exception {
71+
void testEncoding() throws Exception {
7272
System.out.println("file.encoding=" + System.getProperty("file.encoding"));
7373

7474
String pwd = "äüöÜÖÄß\"§$%&/()=?é";

0 commit comments

Comments
 (0)