12
12
*/
13
13
package org .sonatype .plexus .components .cipher ;
14
14
15
- import org .junit .Before ;
16
- import org .junit .Test ;
15
+ import org .junit .jupiter . api . BeforeEach ;
16
+ import org .junit .jupiter . api . Test ;
17
17
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 ;
23
23
24
24
/**
25
25
* Test the Plexus Cipher container
26
26
*
27
27
* @author Oleg Gusakov
28
28
*/
29
- public class DefaultPlexusCipherTest {
29
+ class DefaultPlexusCipherTest {
30
30
private final String passPhrase = "testtest" ;
31
31
32
32
final String str = "my testing phrase" ;
33
33
34
34
final String encStr = "cYrPoOelYU0HGlsn3nERAIyiLVVgnsn/KC5ZqeAPG0beOZCYrFwWwBTp3uyxt/yx" ;
35
+ PlexusCipher pc ;
35
36
36
- DefaultPlexusCipher pc ;
37
-
38
- // -------------------------------------------------------------
39
- @ Before
40
- public void prepare () {
37
+ @ BeforeEach
38
+ void prepare () {
41
39
pc = new DefaultPlexusCipher ();
42
40
}
43
41
44
42
@ Test
45
- public void testIsEncryptedString () {
43
+ void testIsEncryptedString () {
46
44
String noBraces = "This is a test" ;
47
45
String normalBraces = "Comment {This is a test} other comment with a: }" ;
48
46
String escapedBraces = "\\ {This is a test\\ }" ;
@@ -58,7 +56,7 @@ public void testIsEncryptedString() {
58
56
}
59
57
60
58
@ Test
61
- public void testUnDecorate_BracesPermutations () throws PlexusCipherException {
59
+ void testUnDecorate_BracesPermutations () throws PlexusCipherException {
62
60
String noBraces = "This is a test" ;
63
61
String normalBraces = "Comment {This is a test} other comment with a: }" ;
64
62
String mixedBraces = "Comment {foo\\ {This is a test\\ }} other comment with a: }" ;
@@ -71,9 +69,9 @@ public void testUnDecorate_BracesPermutations() throws PlexusCipherException {
71
69
// -------------------------------------------------------------
72
70
73
71
@ Test
74
- public void testDefaultAlgorithmExists () throws Exception {
72
+ void testDefaultAlgorithmExists () throws Exception {
75
73
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" );
77
75
78
76
System .out .println ("\n === Available ciphers :" );
79
77
for (String re : res ) {
@@ -91,12 +89,12 @@ public void testDefaultAlgorithmExists() throws Exception {
91
89
// -------------------------------------------------------------
92
90
93
91
@ Test
94
- public void stestFindDefaultAlgorithm () {
92
+ void stestFindDefaultAlgorithm () {
95
93
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" );
97
95
98
96
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" );
100
98
101
99
for (String impl : impls )
102
100
try {
@@ -110,20 +108,20 @@ public void stestFindDefaultAlgorithm() {
110
108
111
109
// -------------------------------------------------------------
112
110
@ Test
113
- public void testEncrypt () throws Exception {
111
+ void testEncrypt () throws Exception {
114
112
String xRes = pc .encrypt (str , passPhrase );
115
113
116
114
System .out .println (xRes );
117
115
118
116
String res = pc .decrypt (xRes , passPhrase );
119
117
120
- assertEquals ("Encryption/Decryption did not produce desired result" , str , res );
118
+ assertEquals (str , res , "Encryption/Decryption did not produce desired result" );
121
119
}
122
120
123
121
// -------------------------------------------------------------
124
122
125
123
@ Test
126
- public void testEncryptVariableLengths () throws Exception {
124
+ void testEncryptVariableLengths () throws Exception {
127
125
String pass = "g" ;
128
126
129
127
for (int i = 0 ; i < 64 ; i ++) {
@@ -135,44 +133,44 @@ public void testEncryptVariableLengths() throws Exception {
135
133
136
134
String res = pc .decrypt (xRes , pass );
137
135
138
- assertEquals ("Encryption/Decryption did not produce desired result" , str , res );
136
+ assertEquals (str , res , "Encryption/Decryption did not produce desired result" );
139
137
}
140
138
}
141
139
142
140
@ 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: " );
150
148
}
151
149
152
150
// -------------------------------------------------------------
153
151
154
152
@ Test
155
- public void testDecorate () {
153
+ void testDecorate () {
156
154
String res = pc .decorate ("aaa" );
157
155
assertEquals (
158
- "Decoration failed" ,
159
156
PlexusCipher .ENCRYPTED_STRING_DECORATION_START + "aaa" + PlexusCipher .ENCRYPTED_STRING_DECORATION_STOP ,
160
- res );
157
+ res ,
158
+ "Decoration failed" );
161
159
}
162
160
163
161
// -------------------------------------------------------------
164
162
165
163
@ Test
166
- public void testUnDecorate () throws Exception {
164
+ void testUnDecorate () throws Exception {
167
165
String res = pc .unDecorate (
168
166
PlexusCipher .ENCRYPTED_STRING_DECORATION_START + "aaa" + PlexusCipher .ENCRYPTED_STRING_DECORATION_STOP );
169
- assertEquals ("Decoration failed" , " aaa" , res );
167
+ assertEquals ("aaa" , res , "Decoration failed" );
170
168
}
171
169
172
170
// -------------------------------------------------------------
173
171
174
172
@ Test
175
- public void testEncryptAndDecorate () throws Exception {
173
+ void testEncryptAndDecorate () throws Exception {
176
174
String res = pc .encryptAndDecorate ("my-password" , "12345678" );
177
175
178
176
assertEquals ('{' , res .charAt (0 ));
0 commit comments