-
Notifications
You must be signed in to change notification settings - Fork 1
feat: add pluggable Base64Codec interface for Android compatibility #223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
80d9336
67876be
1428354
f3cd362
d4161e9
9808cd7
29cbce5
74ff8fc
cfe4eda
99d57e2
2a86c3d
3db6b18
2637c4e
8ce04fb
faed7dc
e29f0cd
b700ec4
260081c
79705cb
50fbae3
bd9ca53
350c636
3b117fb
ebffdb7
969ecaa
1aff347
ef91b6a
e8c5521
779ce0a
434ad38
a0cf975
ab43c3b
be2b1c3
e32689b
04e319a
83e6b81
6b0d94d
a360488
8c41131
cd8e79e
7825bbf
9c0bc75
0b8c5fe
9e4d6e0
54cfb3c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,9 +10,16 @@ | |
| import java.util.concurrent.TimeUnit; | ||
| import java.util.concurrent.atomic.AtomicBoolean; | ||
| import java.util.concurrent.atomic.AtomicInteger; | ||
| import org.junit.jupiter.api.AfterEach; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| public class UtilsTest { | ||
|
|
||
| @AfterEach | ||
| void resetCodec() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. any reason these are package level instead of class? (e.g., why no
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. package-private is enough for JUnit to find them (uses reflection/annotation to find the methods) |
||
| Utils.resetBase64Codec(); | ||
| } | ||
|
|
||
| @Test | ||
| public void testGetMd5Hash() { | ||
| // empty string | ||
|
|
@@ -149,4 +156,57 @@ public void testDateFormattingThreadSafety() throws InterruptedException { | |
| assertFalse(collisionDetected.get(), failureMessage); | ||
| assertEquals(0, unexpectedExceptions.get(), failureMessage); | ||
| } | ||
|
|
||
| @Test | ||
| void testCustomBase64Codec() { | ||
| AtomicBoolean encodeCalled = new AtomicBoolean(false); | ||
| AtomicBoolean decodeCalled = new AtomicBoolean(false); | ||
|
|
||
| Utils.Base64Codec customCodec = | ||
| new Utils.Base64Codec() { | ||
| @Override | ||
| public String base64Encode(String input) { | ||
| encodeCalled.set(true); | ||
| return "encoded:" + input; | ||
| } | ||
|
|
||
| @Override | ||
| public String base64Decode(String input) { | ||
| decodeCalled.set(true); | ||
| return "decoded:" + input; | ||
| } | ||
| }; | ||
|
|
||
| Utils.setBase64Codec(customCodec); | ||
|
|
||
| assertEquals("encoded:test", Utils.base64Encode("test")); | ||
| assertTrue(encodeCalled.get()); | ||
|
|
||
| assertEquals("decoded:test", Utils.base64Decode("test")); | ||
| assertTrue(decodeCalled.get()); | ||
|
Comment on lines
+182
to
+186
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice |
||
| } | ||
|
|
||
| @Test | ||
| void testBase64EncodeDecodeDefault() { | ||
| // Test null handling | ||
| assertNull(Utils.base64Encode(null)); | ||
| assertNull(Utils.base64Decode(null)); | ||
|
|
||
| // Test encoding | ||
| String original = "Hello, World!"; | ||
| String encoded = Utils.base64Encode(original); | ||
| assertEquals("SGVsbG8sIFdvcmxkIQ==", encoded); | ||
|
|
||
| // Test decoding | ||
| String decoded = Utils.base64Decode(encoded); | ||
| assertEquals(original, decoded); | ||
|
|
||
| // Test round-trip | ||
| assertEquals(original, Utils.base64Decode(Utils.base64Encode(original))); | ||
| } | ||
|
|
||
| @Test | ||
| void testSetBase64CodecWithNullThrowsException() { | ||
| assertThrows(IllegalArgumentException.class, () -> Utils.setBase64Codec(null)); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we need something similar for
base64EncodeThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 Looking a little wider at it, we're only actually using the encode method in tests. I'd prefer to keep the Codec here just in case prod code needs to encode in the future we don't have to make a breaking change to add it.