Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit5a0df76

Browse files
committed
add base64 en/de-coding unit tests
1 parentcd5e3af commit5a0df76

File tree

2 files changed

+88
-1
lines changed
  • scribejava-core/src

2 files changed

+88
-1
lines changed

‎scribejava-core/src/main/java/com/github/scribejava/core/base64/Base64.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ private static Base64 createInstance() {
2323
returnnewJava8Base64();
2424
}
2525
thrownewIllegalStateException(
26-
"No Base64 implementation was provided. Java 8 Base64, Apachecommons codec or JAXB is needed");
26+
"No Base64 implementation was provided. Java 8 Base64, ApacheCommons Codec or JAXB is needed");
2727
}
2828

2929
publicstaticvoidinit(Base64base64) {
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
packagecom.github.scribejava.core.base64;
2+
3+
importjava.io.UnsupportedEncodingException;
4+
importorg.junit.Before;
5+
importorg.junit.Test;
6+
importstaticorg.junit.Assert.assertTrue;
7+
importstaticorg.junit.Assert.assertEquals;
8+
importstaticorg.junit.Assert.assertArrayEquals;
9+
10+
publicclassBase64Test {
11+
12+
privateBase64java8Base64;
13+
privatebyte[]helloWorldBytes;
14+
privatebyte[]helloWorldTwoLinesBytes;
15+
privatebyte[]helloWorldTwoLinesAndNewLineBytes;
16+
privatebyte[]helloWorldDifferentCharsBytes;
17+
18+
@Before
19+
publicvoidsetUp()throwsUnsupportedEncodingException {
20+
helloWorldBytes ="Hello World".getBytes("UTF-8");
21+
helloWorldTwoLinesBytes ="Hello World\r\nNew Line2".getBytes("UTF-8");
22+
helloWorldTwoLinesAndNewLineBytes ="Hello World\r\nSecond Line\r\n".getBytes("UTF-8");
23+
helloWorldDifferentCharsBytes = ("`1234567890-=~!@#$%^&*()_+ёЁ\"№;:?qwertyuiop[]asdfghjkl;'zxcvbnm,./QWERTYUIOP"
24+
+"{}|ASDFGHJKL:ZXCVBNM<>?йфяцычувскамепинртгоьшлбщдюзж.хэъ\\ЙФЯЦЫЧУВСКАМЕПИНРТГОЬШЛБЩДЮЗЖ,ХЭЪ/\r\t\f\'"
25+
+"\b\n").getBytes("UTF-8");
26+
java8Base64 =newJava8Base64();
27+
}
28+
29+
@Test
30+
publicvoidallImplementationsAreAvailable() {
31+
assertTrue(Java8Base64.isAvailable());
32+
}
33+
34+
@Test
35+
publicvoidtestEncode() {
36+
finalStringhelloWorldEncoded ="SGVsbG8gV29ybGQ=";
37+
finalStringhelloWorldTwoLinesEncoded ="SGVsbG8gV29ybGQNCk5ldyBMaW5lMg==";
38+
finalStringhelloWorldTwoLinesAndNewLineEncoded ="SGVsbG8gV29ybGQNClNlY29uZCBMaW5lDQo=";
39+
finalStringhelloWorldDifferentCharsEncoded ="YDEyMzQ1Njc4OTAtPX4hQCMkJV4mKigpXyvRkdCBIuKEljs6P3F3ZXJ0eXVpb3B"
40+
+"bXWFzZGZnaGprbDsnenhjdmJubSwuL1FXRVJUWVVJT1B7fXxBU0RGR0hKS0w6WlhDVkJOTTw+P9C50YTRj9GG0YvRh9GD0LLRgdC"
41+
+"60LDQvNC10L/QuNC90YDRgtCz0L7RjNGI0LvQsdGJ0LTRjtC30LYu0YXRjdGKXNCZ0KTQr9Cm0KvQp9Cj0JLQodCa0JDQnNCV0J/"
42+
+"QmNCd0KDQotCT0J7QrNCo0JvQkdCp0JTQrtCX0JYs0KXQrdCqLw0JDCcICg==";
43+
44+
assertEquals(helloWorldEncoded,java8Base64.internalEncode(helloWorldBytes));
45+
assertEquals(helloWorldTwoLinesEncoded,java8Base64.internalEncode(helloWorldTwoLinesBytes));
46+
assertEquals(helloWorldTwoLinesAndNewLineEncoded,
47+
java8Base64.internalEncode(helloWorldTwoLinesAndNewLineBytes));
48+
assertEquals(helloWorldDifferentCharsEncoded,java8Base64.internalEncode(helloWorldDifferentCharsBytes));
49+
}
50+
51+
@Test
52+
publicvoidtestEncodeUrlWithoutPadding() {
53+
finalStringhelloWorldEncoded ="SGVsbG8gV29ybGQ";
54+
finalStringhelloWorldTwoLinesEncoded ="SGVsbG8gV29ybGQNCk5ldyBMaW5lMg";
55+
finalStringhelloWorldTwoLinesAndNewLineEncoded ="SGVsbG8gV29ybGQNClNlY29uZCBMaW5lDQo";
56+
finalStringhelloWorldDifferentCharsEncoded ="YDEyMzQ1Njc4OTAtPX4hQCMkJV4mKigpXyvRkdCBIuKEljs6P3F3ZXJ0eXVpb3B"
57+
+"bXWFzZGZnaGprbDsnenhjdmJubSwuL1FXRVJUWVVJT1B7fXxBU0RGR0hKS0w6WlhDVkJOTTw-P9C50YTRj9GG0YvRh9GD0LLRgdC"
58+
+"60LDQvNC10L_QuNC90YDRgtCz0L7RjNGI0LvQsdGJ0LTRjtC30LYu0YXRjdGKXNCZ0KTQr9Cm0KvQp9Cj0JLQodCa0JDQnNCV0J_"
59+
+"QmNCd0KDQotCT0J7QrNCo0JvQkdCp0JTQrtCX0JYs0KXQrdCqLw0JDCcICg";
60+
61+
assertEquals(helloWorldEncoded,java8Base64.internalEncodeUrlWithoutPadding(helloWorldBytes));
62+
assertEquals(helloWorldTwoLinesEncoded,java8Base64.internalEncodeUrlWithoutPadding(helloWorldTwoLinesBytes));
63+
assertEquals(helloWorldTwoLinesAndNewLineEncoded,
64+
java8Base64.internalEncodeUrlWithoutPadding(helloWorldTwoLinesAndNewLineBytes));
65+
assertEquals(helloWorldDifferentCharsEncoded,
66+
java8Base64.internalEncodeUrlWithoutPadding(helloWorldDifferentCharsBytes));
67+
}
68+
69+
@Test
70+
publicvoidtestDecodeMime() {
71+
finalStringhelloWorldEncoded ="SGVsbG8gV29ybGQ=";
72+
finalStringhelloWorldTwoLinesEncoded ="SGVsbG8gV29ybGQNCk5ldyBMaW5lMg==";
73+
finalStringhelloWorldTwoLinesAndNewLineEncoded ="SGVsbG8gV29ybGQNClNlY29uZCBMaW5lDQo=";
74+
finalStringhelloWorldDifferentCharsEncoded ="YDEyMzQ1Njc4OTAtPX4hQCMkJV4mKigpXyvRkdCBIuKEljs6P3F3ZXJ0eXVpb3B"
75+
+"bXWFzZGZnaGprbDsnenhjdmJubSwuL1FXRVJUWVVJT1B7fXxBU0RGR0hKS0w6WlhDVkJOTTw+P9C50YTRj9GG0YvRh9GD0LLRgdC"
76+
+"60LDQvNC10L/QuNC90YDRgtCz0L7RjNGI0LvQsdGJ0LTRjtC30LYu0YXRjdGKXNCZ0KTQr9Cm0KvQp9Cj0JLQodCa0JDQnNCV0J/"
77+
+"QmNCd0KDQotCT0J7QrNCo0JvQkdCp0JTQrtCX0JYs0KXQrdCqLw0JDCcICg==";
78+
79+
assertArrayEquals(helloWorldBytes,java8Base64.internalDecodeMime(helloWorldEncoded));
80+
assertArrayEquals(helloWorldTwoLinesBytes,java8Base64.internalDecodeMime(helloWorldTwoLinesEncoded));
81+
assertArrayEquals(helloWorldTwoLinesAndNewLineBytes,
82+
java8Base64.internalDecodeMime(helloWorldTwoLinesAndNewLineEncoded));
83+
assertArrayEquals(helloWorldDifferentCharsBytes,
84+
java8Base64.internalDecodeMime(helloWorldDifferentCharsEncoded));
85+
}
86+
87+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp