### Question:
TextCodec implements ContentCodec { @Override public <T> T bytesToValue(byte[] body, DataSchema<T> schema, Map<String, String> parameters) { String charset = parameters.get("charset"); String parsed; if (charset != null) { parsed = new String(body, Charset.forName(charset)); } else { parsed = new String(body); } String type = schema.getType(); switch (type) { case BooleanSchema .TYPE: return (T) Boolean.valueOf(parsed); case IntegerSchema .TYPE: return (T) Integer.valueOf(parsed); case NumberSchema .TYPE: if (parsed.contains(".")) { return (T) Double.valueOf(parsed); } else { return (T) Long.valueOf(parsed); } case StringSchema .TYPE: return (T) parsed; default: return null; } }  @Override String getMediaType(); @Override T bytesToValue(byte[] body, DataSchema<T> schema, Map<String, String> parameters); @Override byte[] valueToBytes(Object value, Map<String, String> parameters);  }### Answer:
@Test public void bytesToBooleanValue() throws ContentCodecException { byte[] bytes = "true".getBytes(); Object value = codec.bytesToValue(bytes, new BooleanSchema()); boolean bool = (boolean) value; assertTrue(bool); }
@Test public void bytesToIntegerValue() throws ContentCodecException { byte[] bytes = "1337".getBytes(); Object value = codec.bytesToValue(bytes, new IntegerSchema()); int integer = (int) value; assertEquals(1337, integer); }
@Test public void bytesToNullValue() throws ContentCodecException { byte[] bytes = "null".getBytes(); Object value = codec.bytesToValue(bytes, new NullSchema()); assertNull(value); }
@Test public void bytesToNumberFloatValue() throws ContentCodecException { byte[] bytes = "13.37".getBytes(); Number value = codec.bytesToValue(bytes, new NumberSchema()); assertNotNull("Should be instance of Number", value); assertEquals(13.37, value); }
@Test public void bytesToNumberLongValue() throws ContentCodecException { byte[] bytes = "1337".getBytes(); Number value = codec.bytesToValue(bytes, new NumberSchema()); assertNotNull("Should be instance of Number", value); assertEquals(1337L, value); }
@Test public void bytesToStringValue() throws ContentCodecException { byte[] bytes = "Hallo Welt".getBytes(); String value = codec.bytesToValue(bytes, new StringSchema()); assertNotNull("Should be instance of String", value); assertEquals("Hallo Welt", value); }