1212 */
1313package 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 ));
0 commit comments