### Question:
PeriodicPaymentJsonPartConverter implements Converter<String, PeriodicPaymentInitiationXmlPart2StandingorderTypeJson> { @Override public PeriodicPaymentInitiationXmlPart2StandingorderTypeJson convert(String source) { if (StringUtils.isEmpty(source)) { return null; } try { return xs2aObjectMapper.readValue(source, PeriodicPaymentInitiationXmlPart2StandingorderTypeJson.class); } catch (IOException e) { log.info("Can't convert json to object: {}", e.getMessage()); return null; } }  @Override PeriodicPaymentInitiationXmlPart2StandingorderTypeJson convert(String source);  }### Answer:
@Test void convert_withCorrectBody_shouldReturnObject() throws IOException { when(xs2aObjectMapper.readValue(SERIALISED_BODY, PeriodicPaymentInitiationXmlPart2StandingorderTypeJson.class)) .thenReturn(buildPeriodicPaymentJson()); PeriodicPaymentInitiationXmlPart2StandingorderTypeJson expected = buildPeriodicPaymentJson(); PeriodicPaymentInitiationXmlPart2StandingorderTypeJson actualResult = periodicPaymentJsonPartConverter.convert(SERIALISED_BODY); verify(xs2aObjectMapper).readValue(SERIALISED_BODY, PeriodicPaymentInitiationXmlPart2StandingorderTypeJson.class); assertEquals(expected, actualResult); }
@Test void convert_withMalformedBody_shouldReturnNull() throws JsonProcessingException { when(xs2aObjectMapper.readValue(MALFORMED_SERIALISED_BODY, PeriodicPaymentInitiationXmlPart2StandingorderTypeJson.class)) .thenReturn(null); PeriodicPaymentInitiationXmlPart2StandingorderTypeJson actualResult = periodicPaymentJsonPartConverter.convert(MALFORMED_SERIALISED_BODY); assertNull(actualResult); }
@Test void convert_withNullString_shouldReturnNull() { PeriodicPaymentInitiationXmlPart2StandingorderTypeJson actualResult = periodicPaymentJsonPartConverter.convert(null); assertNull(actualResult); }