forked from TheAlgorithms/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBase64Test.java
More file actions
50 lines (40 loc) · 1.49 KB
/
Base64Test.java
File metadata and controls
50 lines (40 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package com.thealgorithms.conversions;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
public class Base64Test {
@Test
// Test encoding and decoding normal strings
public void testEncodeAndDecode() {
String original = "Hello, World!";
String encoded = Base64Util.encode(original);
String decoded = Base64Util.decode(encoded);
assertEquals(original, decoded);
}
@Test
// Test encoding and decoding empty string
public void testEmptyString() {
String encoded = Base64Util.encode("");
String decoded = Base64Util.decode(encoded);
assertEquals("", decoded);
}
@Test
// Test encoding null input
public void testNullInputEncode() {
assertThrows(IllegalArgumentException.class, () -> Base64Util.encode(null));
}
@Test
// Test decoding null input
public void testNullInputDecode() {
assertThrows(IllegalArgumentException.class, () -> Base64Util.decode(null));
}
@ParameterizedTest
@CsvSource({"invalid@@base64", "12345$%", "====", "abc?def"})
// Test decoding invalid Base64 strings
void testInvalidBase64Decode(String invalidBase64) {
assertThrows(IllegalArgumentException.class,
() -> Base64Util.decode(invalidBase64));
}
}