### Question:
QualityThresholdTransformer { public Map<String, QualityThreshold> toMap(String jsonQualityThreshold) { final Map<String, QualityThreshold> result = new HashMap<>(); if (!StringUtils.isEmpty(jsonQualityThreshold)) { try { return objectMapper.readValue(jsonQualityThreshold, TYPE_REFERENCE); } catch (IOException e) { log.error("Cannot parse qualityThresholds: {} - Cause : {}", jsonQualityThreshold, e.getMessage()); log.debug("Full error is {}", e); return new HashMap<>(); } } return result; }  Map<String, QualityThreshold> toMap(String jsonQualityThreshold);  }### Answer:
@Test public void toMap_should_transform_the_json() throws IOException { String value = "{'key' : 'value'}"; Map<String, QualityThreshold> result = new HashMap<>(); result.put("present", new QualityThreshold()); Mockito.doReturn(result).when(objectMapper).readValue(value, QualityThresholdTransformer.TYPE_REFERENCE); Map<String, QualityThreshold> qualityThresholdDTOS = this.cut.toMap(value); Assertions.assertThat(qualityThresholdDTOS).isNotNull(); Assertions.assertThat(qualityThresholdDTOS).hasSize(1); Assertions.assertThat(qualityThresholdDTOS).containsKey("present"); }
@Test public void toDtos_should_send_empty_list_on_exception() throws IOException { String value = "{'key' : 'value'}"; Mockito.doThrow(new JsonProcessingException("expected -- test purpose") {}) .when(objectMapper).readValue(value, QualityThresholdTransformer.TYPE_REFERENCE); Map<String, QualityThreshold> qualityThresholdDTOS = this.cut.toMap(value); Assertions.assertThat(qualityThresholdDTOS).isNotNull(); Assertions.assertThat(qualityThresholdDTOS).isEmpty(); }