### Question:
RawToXs2aPaymentMapper { public PeriodicPayment mapToPeriodicPayment(byte[] paymentBody) { if (ArrayUtils.isEmpty(paymentBody)) { return null; } PeriodicPaymentInitiationJson paymentInitiationJson = readBytes(paymentBody, PeriodicPaymentInitiationJson.class); PeriodicPayment periodicPayment = paymentModelMapper.mapToXs2aPayment(paymentInitiationJson); if (periodicPayment != null) { periodicPayment.setPaymentData(paymentBody); } return periodicPayment; }  SinglePayment mapToSinglePayment(byte[] paymentBody); PeriodicPayment mapToPeriodicPayment(byte[] paymentBody); BulkPayment mapToBulkPayment(byte[] paymentBody);  }### Answer:
@Test void mapToPeriodicPayment() { PeriodicPaymentInitiationJson paymentInitiationJson = jsonReader.getObjectFromFile(PERIODIC_PAYMENT_PSD2_JSON_PATH, PeriodicPaymentInitiationJson.class); PeriodicPayment xs2aPeriodicPayment = jsonReader.getObjectFromFile(PERIODIC_PAYMENT_XS2A_JSON_PATH, PeriodicPayment.class); when(paymentModelMapper.mapToXs2aPayment(paymentInitiationJson)).thenReturn(xs2aPeriodicPayment); byte[] paymentBody = jsonReader.getBytesFromFile(PERIODIC_PAYMENT_PSD2_JSON_PATH); PeriodicPayment expectedPeriodicPayment = jsonReader.getObjectFromFile(PERIODIC_PAYMENT_XS2A_JSON_PATH, PeriodicPayment.class); expectedPeriodicPayment.setPaymentData(paymentBody); PeriodicPayment actual = rawToXs2aPaymentMapper.mapToPeriodicPayment(paymentBody); assertEquals(expectedPeriodicPayment, actual); }
@Test void mapToPeriodicPayment_null() { PeriodicPayment actual = rawToXs2aPaymentMapper.mapToPeriodicPayment(null); assertNull(actual); }
@Test void mapToPeriodicPayment_malformedBody() { SinglePayment actual = rawToXs2aPaymentMapper.mapToPeriodicPayment(MALFORMED_PAYMENT_BODY); assertNull(actual); verify(paymentModelMapper, never()).mapToXs2aPayment(any(PeriodicPaymentInitiationJson.class)); }
@Test void mapToPeriodicPayment_nullPeriodicPayment() { PeriodicPaymentInitiationJson paymentInitiationJson = jsonReader.getObjectFromFile(PERIODIC_PAYMENT_PSD2_JSON_PATH, PeriodicPaymentInitiationJson.class); when(paymentModelMapper.mapToXs2aPayment(paymentInitiationJson)).thenReturn(null); byte[] paymentBody = jsonReader.getBytesFromFile(PERIODIC_PAYMENT_PSD2_JSON_PATH); PeriodicPayment actual = rawToXs2aPaymentMapper.mapToPeriodicPayment(paymentBody); assertNull(actual); }