### Question:
URLCodec implements BinaryEncoder, BinaryDecoder, StringEncoder, StringDecoder { @Override public byte[] decode(final byte[] bytes) throws DecoderException { return decodeUrl(bytes); } URLCodec();  URLCodec(final String charset); static final byte[] encodeUrl(BitSet urlsafe, final byte[] bytes); static final byte[] decodeUrl(final byte[] bytes); @Override byte[] encode(final byte[] bytes); @Override byte[] decode(final byte[] bytes); String encode(final String str, final String charset); @Override String encode(final String str); String decode(final String str, final String charset); @Override String decode(final String str); @Override Object encode(final Object obj); @Override Object decode(final Object obj); String getDefaultCharset(); @Deprecated String getEncoding();  }### Answer:
@Test public void testDecodeInvalid() throws Exception { final URLCodec urlCodec = new URLCodec(); try { urlCodec.decode("%"); fail("DecoderException should have been thrown"); } catch (final DecoderException e) { } try { urlCodec.decode("%A"); fail("DecoderException should have been thrown"); } catch (final DecoderException e) { } try { urlCodec.decode("%WW"); fail("DecoderException should have been thrown"); } catch (final DecoderException e) { } try { urlCodec.decode("%0W"); fail("DecoderException should have been thrown"); } catch (final DecoderException e) { } this.validateState(urlCodec); }
@Test public void testDecodeInvalidContent() throws UnsupportedEncodingException, DecoderException { final String ch_msg = constructString(SWISS_GERMAN_STUFF_UNICODE); final URLCodec urlCodec = new URLCodec(); final byte[] input = ch_msg.getBytes("ISO-8859-1"); final byte[] output = urlCodec.decode(input); assertEquals(input.length, output.length); for (int i = 0; i < input.length; i++) { assertEquals(input[i], output[i]); } this.validateState(urlCodec); }
@Test public void testDecodeStringWithNull() throws Exception { final URLCodec urlCodec = new URLCodec(); final String test = null; final String result = urlCodec.decode( test, "charset" ); assertEquals("Result should be null", null, result); }
@Test public void testDecodeObjects() throws Exception { final URLCodec urlCodec = new URLCodec(); final String plain = "Hello+there%21"; String decoded = (String) urlCodec.decode((Object) plain); assertEquals("Basic URL decoding test", "Hello there!", decoded); final byte[] plainBA = plain.getBytes(Charsets.UTF_8); final byte[] decodedBA = (byte[]) urlCodec.decode((Object) plainBA); decoded = new String(decodedBA); assertEquals("Basic URL decoding test", "Hello there!", decoded); final Object result = urlCodec.decode((Object) null); assertEquals( "Decoding a null Object should return null", null, result); try { final Object dObj = new Double(3.0); urlCodec.decode( dObj ); fail( "Trying to url encode a Double object should cause an exception."); } catch (final DecoderException ee) { } this.validateState(urlCodec); }