### Question:
QualitySeverityTransformer { public List<QualitySeverityDTO> toDtos(String jsonQualitySeverities) { if (StringUtils.isEmpty(jsonQualitySeverities)) { return new ArrayList<>(); } try { return objectMapper.readValue(jsonQualitySeverities, TYPE_REFERENCE); } catch (IOException e) { log.error("Cannot parse qualitySeverities: {} - Cause : {}", jsonQualitySeverities, e.getMessage()); log.debug("Full error : {}", e); return new ArrayList<>(); } }  List<QualitySeverityDTO> toDtos(String jsonQualitySeverities);  }### Answer:
@Test public void toDtos_should_call_object_mapper() throws IOException { String value = "{'key' : 'value'}"; QualitySeverityDTO result = new QualitySeverityDTO(); result.setPercent(98); List<QualitySeverityDTO> mapperList = new ArrayList<>(); mapperList.add(result); Mockito.doReturn(mapperList).when(objectMapper).readValue(value, QualitySeverityTransformer.TYPE_REFERENCE); List<QualitySeverityDTO> qualitySeverityDTOS = this.cut.toDtos(value); Assertions.assertThat(qualitySeverityDTOS).isNotNull(); Assertions.assertThat(qualitySeverityDTOS).hasSize(1); Assertions.assertThat(qualitySeverityDTOS.get(0)).isNotNull(); Assertions.assertThat(qualitySeverityDTOS.get(0).getPercent()).isEqualTo(98); }
@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, QualitySeverityTransformer.TYPE_REFERENCE); List<QualitySeverityDTO> qualitySeverityDTOS = this.cut.toDtos(value); Assertions.assertThat(qualitySeverityDTOS).isNotNull(); Assertions.assertThat(qualitySeverityDTOS).isEmpty(); }