Source:
<code>public void shouldUpdateEmailToChargeTransaction() { service.create(CHARGE_REQUEST, GATEWAY_ACCOUNT_ID, mockedUriInfo); ArgumentCaptor<ChargeEntity> chargeEntityArgumentCaptor = forClass(ChargeEntity.class); <START> verify(mockedChargeDao).persist(chargeEntityArgumentCaptor.capture()); <END> ChargeEntity createdChargeEntity = chargeEntityArgumentCaptor.getValue(); final String chargeEntityExternalId = createdChargeEntity.getExternalId(); when(mockedChargeDao.findByExternalId(chargeEntityExternalId)) .thenReturn(Optional.of(createdChargeEntity)); final ChargeTransactionEntity chargeTransactionEntity = ChargeTransactionEntity.from(createdChargeEntity); final PaymentRequestEntity paymentRequestEntity = PaymentRequestEntity.from(createdChargeEntity, chargeTransactionEntity); when(mockedPaymentRequestDao.findByExternalId(chargeEntityExternalId)) .thenReturn(Optional.of(paymentRequestEntity)); final String expectedEmail = "test@examplecom"; PatchRequestBuilder.PatchRequest patchRequest = PatchRequestBuilder.aPatchRequestBuilder( ImmutableMap.of( "op", "replace", "path", "email", "value", expectedEmail)) .withValidOps(singletonList("replace")) .withValidPaths(singletonList("email")) .build(); assertThat(paymentRequestEntity.getChargeTransaction().getEmail(), is(nullValue())); service.updateCharge(chargeEntityExternalId, patchRequest); verify(mockedPaymentRequestDao).findByExternalId(chargeEntityExternalId); Optional<PaymentRequestEntity> maybePaymentRequest = mockedPaymentRequestDao.findByExternalId(chargeEntityExternalId); assertThat(maybePaymentRequest.isPresent(), is(true)); PaymentRequestEntity updatedPaymentRequest = maybePaymentRequest.get(); String emailFromTransaction = updatedPaymentRequest.getChargeTransaction().getEmail(); assertThat(emailFromTransaction, is(expectedEmail)); }</code><technical_language>Do need ArgumentCaptor here? service.create returns Optional<ChargeResponse> externalId it</technical_language>

Target:
public void shouldUpdateEmailToChargeTransaction() { ChargeEntity createdChargeEntity = ChargeEntityFixture.aValidChargeEntity().build(); final String chargeEntityExternalId = createdChargeEntity.getExternalId(); when(mockedChargeDao.findByExternalId(chargeEntityExternalId)) .thenReturn(Optional.of(createdChargeEntity)); final ChargeTransactionEntity chargeTransactionEntity = ChargeTransactionEntity.from(createdChargeEntity); final PaymentRequestEntity paymentRequestEntity = PaymentRequestEntity.from(createdChargeEntity, chargeTransactionEntity); when(mockedPaymentRequestDao.findByExternalId(chargeEntityExternalId)) .thenReturn(Optional.of(paymentRequestEntity)); final String expectedEmail = "test@examplecom"; PatchRequestBuilder.PatchRequest patchRequest = PatchRequestBuilder.aPatchRequestBuilder( ImmutableMap.of( "op", "replace", "path", "email", "value", expectedEmail)) .withValidOps(singletonList("replace")) .withValidPaths(singletonList("email")) .build(); assertThat(paymentRequestEntity.getChargeTransaction().getEmail(), is(nullValue())); service.updateCharge(chargeEntityExternalId, patchRequest); verify(mockedPaymentRequestDao).findByExternalId(chargeEntityExternalId); String emailFromTransaction = paymentRequestEntity.getChargeTransaction().getEmail(); assertThat(emailFromTransaction, is(expectedEmail)); }