Skip to content

Commit 9664d34

Browse files
author
zihluwang
committed
test: unit test for Base64Util
1 parent 74a4df5 commit 9664d34

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright (C) 2024-2024 OnixByte.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
*
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package com.onixbyte.devkit.utils;
19+
20+
import lombok.extern.slf4j.Slf4j;
21+
import org.junit.jupiter.api.Assertions;
22+
import org.junit.jupiter.api.Test;
23+
24+
@Slf4j
25+
public class TestBase64Util {
26+
27+
@Test
28+
public void testEncode() {
29+
Assertions.assertEquals("SGVsbG8gV29ybGQ=", Base64Util.encode("Hello World"));
30+
Assertions.assertEquals("MTI3LjAuMC4x", Base64Util.encode("127.0.0.1"));
31+
Assertions.assertEquals("cm9vdA==", Base64Util.encode("root"));
32+
}
33+
34+
@Test
35+
public void testDecode() {
36+
Assertions.assertEquals("Hello World", Base64Util.decode("SGVsbG8gV29ybGQ="));
37+
Assertions.assertEquals("127.0.0.1", Base64Util.decode("MTI3LjAuMC4x"));
38+
Assertions.assertEquals("root", Base64Util.decode("cm9vdA=="));
39+
}
40+
41+
@Test
42+
public void testEncodeUriComponent() {
43+
Assertions.assertEquals("aHR0cHM6Ly9nb29nbGUuY29t", Base64Util.encodeUrlComponents("https://google.com"));
44+
Assertions.assertEquals("aHR0cDovLzEyNy4wLjAuMTo4MDgwL2FwaS91c2VyLzEyMzQ1", Base64Util.encodeUrlComponents("http://127.0.0.1:8080/api/user/12345"));
45+
}
46+
47+
@Test
48+
public void testDecodeUriComponent() {
49+
Assertions.assertEquals("https://google.com", Base64Util.decodeUrlComponents("aHR0cHM6Ly9nb29nbGUuY29t"));
50+
Assertions.assertEquals("http://127.0.0.1:8080/api/user/12345", Base64Util.decodeUrlComponents("aHR0cDovLzEyNy4wLjAuMTo4MDgwL2FwaS91c2VyLzEyMzQ1"));
51+
}
52+
53+
}

0 commit comments

Comments
 (0)