U2fB64Encoding { public static byte[] decode(String encoded) throws U2fBadInputException { try { return BASE64_DECODER.decode(encoded); } catch (IllegalArgumentException e) { throw new U2fBadInputException("Bad base64 encoding", e); } }  static String encode(byte[] decoded); static byte[] decode(String encoded);  }
@Test public void decodeTest() throws U2fBadInputException { String base64Data = "VGVzdA"; String base64DataWithPadding = "VGVzdA=="; String base64DataEmpty = ""; String out1 = new String(U2fB64Encoding.decode(base64Data)); String out2 = new String(U2fB64Encoding.decode(base64DataWithPadding)); String out3 = new String(U2fB64Encoding.decode(base64DataEmpty)); assertEquals(out1, out2); assertEquals(out1, "Test"); assertEquals(out3, ""); }
@Test(expected = U2fBadInputException.class) public void decodeBadAlphabetTest() throws U2fBadInputException { U2fB64Encoding.decode("****"); }
@Test(expected = U2fBadInputException.class) public void decodeBadPaddingTest() throws U2fBadInputException { U2fB64Encoding.decode("A==="); }