### Question:
RawToXs2aPaymentMapper { public SinglePayment mapToSinglePayment(byte[] paymentBody) { if (ArrayUtils.isEmpty(paymentBody)) { return null; } PaymentInitiationJson paymentInitiationJson = readBytes(paymentBody, PaymentInitiationJson.class); SinglePayment singlePayment = paymentModelMapper.mapToXs2aPayment(paymentInitiationJson); if (singlePayment != null) { singlePayment.setPaymentData(paymentBody); } return singlePayment; }  SinglePayment mapToSinglePayment(byte[] paymentBody); PeriodicPayment mapToPeriodicPayment(byte[] paymentBody); BulkPayment mapToBulkPayment(byte[] paymentBody);  }### Answer:
@Test void mapToSinglePayment() { PaymentInitiationJson paymentInitiationJson = jsonReader.getObjectFromFile(SINGLE_PAYMENT_PSD2_JSON_PATH, PaymentInitiationJson.class); SinglePayment xs2aSinglePayment = jsonReader.getObjectFromFile(SINGLE_PAYMENT_XS2A_JSON_PATH, SinglePayment.class); when(paymentModelMapper.mapToXs2aPayment(paymentInitiationJson)).thenReturn(xs2aSinglePayment); byte[] paymentBody = jsonReader.getBytesFromFile(SINGLE_PAYMENT_PSD2_JSON_PATH); SinglePayment expectedSinglePayment = jsonReader.getObjectFromFile(SINGLE_PAYMENT_XS2A_JSON_PATH, SinglePayment.class); expectedSinglePayment.setPaymentData(paymentBody); SinglePayment actual = rawToXs2aPaymentMapper.mapToSinglePayment(paymentBody); assertEquals(expectedSinglePayment, actual); }
@Test void mapToSinglePayment_null() { SinglePayment actual = rawToXs2aPaymentMapper.mapToSinglePayment(null); assertNull(actual); verify(paymentModelMapper, never()).mapToXs2aPayment(any(PaymentInitiationJson.class)); }
@Test void mapToSinglePayment_malformedBody() { SinglePayment actual = rawToXs2aPaymentMapper.mapToSinglePayment(MALFORMED_PAYMENT_BODY); assertNull(actual); verify(paymentModelMapper, never()).mapToXs2aPayment(any(PaymentInitiationJson.class)); }
@Test void mapToSinglePayment_nullSinglePayment() { PaymentInitiationJson paymentInitiationJson = jsonReader.getObjectFromFile(SINGLE_PAYMENT_PSD2_JSON_PATH, PaymentInitiationJson.class); when(paymentModelMapper.mapToXs2aPayment(paymentInitiationJson)).thenReturn(null); byte[] paymentBody = jsonReader.getBytesFromFile(SINGLE_PAYMENT_PSD2_JSON_PATH); SinglePayment actual = rawToXs2aPaymentMapper.mapToSinglePayment(paymentBody); assertNull(actual); }