ContentTypeBasedRespConverter extends AbstractSmartResponseConverter<T> { public ContentTypeBasedRespConverter<T> add(MediaType mediaType, Converter<NetworkResponse, T> converter) { converters.put(mediaType, converter); return this; }  ContentTypeBasedRespConverter<T> add(MediaType mediaType, Converter<NetworkResponse, T>
            converter);  }
@Test public void cannotFindConverter() throws IOException { ContentTypeBasedRespConverter<String> converter = new ContentTypeBasedRespConverter<>(); converter.add(MediaType.parse("text/plain"), new Converters.StringResponseConverter()); converter.add(MediaType.parse("applicaton/xml"), new Converters.StringResponseConverter()); try { converter.convert(networkResponse); fail(); } catch (RuntimeException e) { assertThat(e).hasMessageStartingWith("Cannot find converter for " + ":NetworkResponse{contentType=application/json, statusCode=200, data={\"key\"" + " " + ": \"value\"}, headers=Content-Type: application/json\n" + ", networkTimeNs=0}, tried:"); } }
@Test public void goodConverter() throws IOException { ContentTypeBasedRespConverter<String> converter = new ContentTypeBasedRespConverter<>(); converter.add(MediaType.parse("text/plain"), new Converters.StringResponseConverter()); converter.add(MediaType.parse("application/xml"), new Converters.StringResponseConverter()); converter.add(MediaType.parse("application/json"), new Converters.StringResponseConverter ()); String s = converter.convert(networkResponse); assertThat(s).isEqualTo("{\"key\" : \"value\"}"); }