Created
October 22, 2014 09:11
-
-
Save micke/0c32417c550c9f3b6f63 to your computer and use it in GitHub Desktop.
Super simple scala wrapper around org.apache.commons.codec.binary.Base64
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
package utils | |
import org.apache.commons.codec.binary.{ Base64 => ApacheBase64 } | |
object Base64 { | |
def decode(encoded: String) = new String(ApacheBase64.decodeBase64(encoded.getBytes)) | |
def encode(decoded: String) = new String(ApacheBase64.encodeBase64(decoded.getBytes)) | |
} |
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
import play.api.test._ | |
import utils.Base64 | |
class Base64 extends PlaySpecification { | |
"Base64.decode" should { | |
"decode the base64 encoded string and return a string" in { | |
val decoded = "hello world" | |
val encoded = "aGVsbG8gd29ybGQ=" | |
Base64.decode(encoded) must equalTo(decoded) | |
} | |
} | |
"Base64.encode" should { | |
"encode the string and return a base64 encoded string" in { | |
val encoded = "aGVsbG8gd29ybGQ=" | |
val decoded = "hello world" | |
Base64.encode(decoded) must equalTo(encoded) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment