Skip to content

Commit 0d33041

Browse files
committed
Add jUnit Test
1 parent 70db7ea commit 0d33041

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package io.kubernetes.client;
2+
3+
import okio.ByteString;
4+
import org.junit.Test;
5+
6+
import static org.hamcrest.CoreMatchers.is;
7+
import static org.junit.Assert.*;
8+
9+
public class JSONTest {
10+
11+
@Test
12+
public void testSerializeByteArray() {
13+
final JSON json = new JSON();
14+
final String plainText = "string that contains '=' when encoded";
15+
final String base64String = json.serialize(plainText.getBytes());
16+
//serialize returns string surrounded by quotes: "\"[base64]\""
17+
final String pureString = base64String.replaceAll("^\"|\"$", "");
18+
final ByteString byteStr = ByteString.decodeBase64(pureString);
19+
20+
//Check encoded to valid base64
21+
assertNotNull(byteStr);
22+
23+
//Check encoded string correctly
24+
final String decodedText =new String(byteStr.toByteArray());
25+
assertThat(decodedText, is(plainText));
26+
}
27+
}

0 commit comments

Comments
 (0)