33import static org .junit .jupiter .api .Assertions .assertArrayEquals ;
44import static org .junit .jupiter .api .Assertions .assertEquals ;
55import static org .junit .jupiter .api .Assertions .assertThrows ;
6+
67import org .junit .jupiter .api .Test ;
78import org .junit .jupiter .params .ParameterizedTest ;
89import org .junit .jupiter .params .provider .CsvSource ;
@@ -28,14 +29,16 @@ void testBase64Alphabet() {
2829 @ ParameterizedTest
2930 @ CsvSource ({"'', ''" , "A, QQ==" , "AB, QUI=" , "ABC, QUJD" , "ABCD, QUJDRA==" , "Hello, SGVsbG8=" , "'Hello World', SGVsbG8gV29ybGQ=" , "'Hello, World!', 'SGVsbG8sIFdvcmxkIQ=='" , "'The quick brown fox jumps over the lazy dog', 'VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZw=='" ,
3031 "123456789, MTIzNDU2Nzg5" , "'Base64 encoding test', 'QmFzZTY0IGVuY29kaW5nIHRlc3Q='" })
31- void testStringEncoding (String input , String expected ) {
32+ void
33+ testStringEncoding (String input , String expected ) {
3234 assertEquals (expected , Base64 .encode (input ));
3335 }
3436
3537 @ ParameterizedTest
3638 @ CsvSource ({"'', ''" , "QQ==, A" , "QUI=, AB" , "QUJD, ABC" , "QUJDRA==, ABCD" , "SGVsbG8=, Hello" , "'SGVsbG8gV29ybGQ=', 'Hello World'" , "'SGVsbG8sIFdvcmxkIQ==', 'Hello, World!'" , "'VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZw==', 'The quick brown fox jumps over the lazy dog'" ,
3739 "MTIzNDU2Nzg5, 123456789" , "'QmFzZTY0IGVuY29kaW5nIHRlc3Q=', 'Base64 encoding test'" })
38- void testStringDecoding (String input , String expected ) {
40+ void
41+ testStringDecoding (String input , String expected ) {
3942 assertEquals (expected , Base64 .decodeToString (input ));
4043 }
4144
@@ -58,7 +61,7 @@ void testRoundTripEncoding() {
5861 String [] testStrings = {"" , "A" , "AB" , "ABC" , "Hello, World!" , "The quick brown fox jumps over the lazy dog" , "1234567890" , "Special chars: !@#$%^&*()_+-=[]{}|;:,.<>?" ,
5962 "Unicode: வணக்கம்" , // Tamil for "Hello"
6063 "Multi-line\n string\r with\t different\n whitespace" };
61-
64+
6265 for (String original : testStrings ) {
6366 String encoded = Base64 .encode (original );
6467 String decoded = Base64 .decodeToString (encoded );
@@ -68,14 +71,7 @@ void testRoundTripEncoding() {
6871
6972 @ Test
7073 void testRoundTripByteArrayEncoding () {
71- byte [][] testArrays = {
72- {},
73- {0 },
74- {-1 },
75- {0 , 1 , 2 , 3 , 4 , 5 },
76- {-128 , -1 , 0 , 1 , 127 },
77- {72 , 101 , 108 , 108 , 111 , 44 , 32 , 87 , 111 , 114 , 108 , 100 , 33 }
78- };
74+ byte [][] testArrays = {{}, {0 }, {-1 }, {0 , 1 , 2 , 3 , 4 , 5 }, {-128 , -1 , 0 , 1 , 127 }, {72 , 101 , 108 , 108 , 111 , 44 , 32 , 87 , 111 , 114 , 108 , 100 , 33 }};
7975
8076 for (byte [] original : testArrays ) {
8177 String encoded = Base64 .encode (original );
@@ -91,7 +87,7 @@ void testBinaryData() {
9187 for (int i = 0 ; i < 256 ; i ++) {
9288 binaryData [i ] = (byte ) i ;
9389 }
94-
90+
9591 String encoded = Base64 .encode (binaryData );
9692 byte [] decoded = Base64 .decode (encoded );
9793 assertArrayEquals (binaryData , decoded );
@@ -129,12 +125,12 @@ void testPaddingVariations() {
129125 void testPaddingConsistency () {
130126 // Ensure that strings requiring different amounts of padding encode/decode correctly
131127 String [] testCases = {"A" , "AB" , "ABC" , "ABCD" , "ABCDE" , "ABCDEF" };
132-
128+
133129 for (String test : testCases ) {
134130 String encoded = Base64 .encode (test );
135131 String decoded = Base64 .decodeToString (encoded );
136132 assertEquals (test , decoded );
137-
133+
138134 // Verify padding is correct
139135 int expectedPadding = (3 - (test .length () % 3 )) % 3 ;
140136 int actualPadding = 0 ;
@@ -152,7 +148,7 @@ void testLargeData() {
152148 for (int i = 0 ; i < 1000 ; i ++) {
153149 largeString .append ("This is a test string for Base64 encoding. " );
154150 }
155-
151+
156152 String original = largeString .toString ();
157153 String encoded = Base64 .encode (original );
158154 String decoded = Base64 .decodeToString (encoded );
@@ -164,9 +160,8 @@ void testEmptyAndSingleCharacter() {
164160 // Test edge cases
165161 assertEquals ("" , Base64 .encode ("" ));
166162 assertEquals ("" , Base64 .decodeToString ("" ));
167-
163+
168164 assertEquals ("QQ==" , Base64 .encode ("A" ));
169165 assertEquals ("A" , Base64 .decodeToString ("QQ==" ));
170166 }
171-
172167}
0 commit comments