Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
44 lines (37 loc) · 1.69 KB

File metadata and controls

44 lines (37 loc) · 1.69 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
package com.crypto.codec;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
class Base64Test {
/*
* Test vectors are taken from:
* https://tools.ietf.org/html/rfc4648#section-10
*/
@Test
void TestBase64Encode() {
Assertions.assertEquals("", Base64.encode("".getBytes()));
Assertions.assertEquals("Zg==", Base64.encode("f".getBytes()));
Assertions.assertEquals("Zm8=", Base64.encode("fo".getBytes()));
Assertions.assertEquals("Zm9v", Base64.encode("foo".getBytes()));
Assertions.assertEquals("Zm9vYg==", Base64.encode("foob".getBytes()));
Assertions.assertEquals("Zm9vYmE=", Base64.encode("fooba".getBytes()));
Assertions.assertEquals("Zm9vYmFy", Base64.encode("foobar".getBytes()));
}
@Test
void TestBase64Decode() {
Assertions.assertArrayEquals("".getBytes(), Base64.decode(""));
Assertions.assertArrayEquals("f".getBytes(), Base64.decode("Zg=="));
Assertions.assertArrayEquals("fo".getBytes(), Base64.decode("Zm8="));
Assertions.assertArrayEquals("foo".getBytes(), Base64.decode("Zm9v"));
Assertions.assertArrayEquals("foob".getBytes(), Base64.decode("Zm9vYg=="));
Assertions.assertArrayEquals("fooba".getBytes(), Base64.decode("Zm9vYmE="));
Assertions.assertArrayEquals("foobar".getBytes(), Base64.decode("Zm9vYmFy"));
}
@Test
void testInvalidBase64String() {
Assertions.assertThrows(IllegalArgumentException.class, () -> Base64.decode("Z/+v&mF="));
}
@Test
void testInvalidLengthOfBase64String() {
Assertions.assertThrows(IllegalArgumentException.class, () -> Base64.decode("Zm9v" + "YmFy" + "d"));
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.