### Question:
ContentManager { public static <T> T contentToValue(Content content, DataSchema<T> schema) throws ContentCodecException { if (content == null || content.getBody().length == 0) { return null; } if (schema == null) { log.warn("No DataSchema provided. Return null"); return null; } String contentType = content.getType(); if (contentType == null) { contentType = DEFAULT; log.warn("No content type given. Use default one: {}", DEFAULT); } String mediaType = getMediaType(contentType); Map<String, String> parameters = getMediaTypeParameters(contentType); ContentCodec codec = CODECS.get(mediaType); if (codec != null) { log.debug("Content deserializing from '{}'", mediaType); return codec.bytesToValue(content.getBody(), schema, parameters); } else { log.warn("Content passthrough due to unsupported media type '{}'", mediaType); return fallbackBytesToValue(content, schema); } } private  ContentManager(); static void addCodec(ContentCodec codec); static void removeCodec(String mediaType); static Set<String> getOfferedMediaTypes(); static T contentToValue(Content content,
                                       DataSchema<T> schema); static Content valueToContent(Object value); static Content valueToContent(Object value,
                                         String contentType); static boolean isSupportedMediaType(String contentType); static Set<String> getSupportedMediaTypes(); static final String DEFAULT; }### Answer:
@Test public void contentToValueShouldUseFallbackDeserializerForUnsupportedFormats() throws ContentCodecException, IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(bos); oos.writeObject(42); oos.flush(); byte[] body = bos.toByteArray(); Content content = new Content("none/none", body); Object value = ContentManager.contentToValue(content, new NumberSchema()); assertEquals(42, value); }
@Test public void contentToValueObject() throws ContentCodecException { Content content = new Content("application/json", "{\"foo\":\"bar\"}".getBytes()); Map value = ContentManager.contentToValue(content, new ObjectSchema()); assertEquals("bar", value.get("foo")); }
@Test public void contentToValueWithMediaTypeParameters() throws ContentCodecException { Content content = new Content("text/plain; charset=utf-8", "Hello World".getBytes()); String value = ContentManager.contentToValue(content, new StringSchema()); assertEquals("Hello World", value); }
@Test(expected = ContentCodecException.class) public void contentToValueBrokenByteArray() throws ContentCodecException { Content content = new Content("application/xml", new byte[]{ 0x4f }); ContentManager.contentToValue(content, new StringSchema()); }