-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
87c578b
commit d762043
Showing
4 changed files
with
46 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/test/java/io/github/sashirestela/openai/support/Base64UtilTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package io.github.sashirestela.openai.support; | ||
|
||
import io.github.sashirestela.openai.support.Base64Util.MediaType; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
class Base64UtilTest { | ||
|
||
@Test | ||
void testEncodeDecode() { | ||
var filePath = "src/test/resources/audios_speak.mp3"; | ||
var base64StringWithMedia = Base64Util.encode(filePath, MediaType.AUDIO); | ||
assertTrue(base64StringWithMedia.startsWith("data:")); | ||
var base64String = Base64Util.encode(filePath, null); | ||
assertFalse(base64String.startsWith("data:")); | ||
assertDoesNotThrow(() -> Base64Util.decode(base64String, filePath)); | ||
} | ||
|
||
@Test | ||
void testEncodeException() { | ||
var filePath = "src/test/resources/image_not_found.png"; | ||
assertThrows(Exception.class, () -> Base64Util.encode(filePath, MediaType.IMAGE)); | ||
} | ||
|
||
@Test | ||
void testDecodeException() { | ||
var base64String = "ºªÇ"; | ||
var filePath = "src/test/resources/image_error.png"; | ||
assertThrows(Exception.class, () -> Base64Util.decode(base64String, filePath)); | ||
} | ||
|
||
} |