Source:
<code>public void doCapture_shouldCaptureAChargeForASandboxAccount() throws Exception { String gatewayTxId = "theTxId"; ChargeEntity charge = createNewChargeWith("sandbox",1L, CAPTURE_APPROVED, gatewayTxId); ChargeEntity chargeSpy = spy(charge); mockChargeDaoOperations(chargeSpy); worldpayWillRespondWithSuccess(gatewayTxId, null); when(mockedProviders.byName(charge.getPaymentGatewayName())).thenReturn(mockedPaymentProvider); GatewayResponse response = cardCaptureService.doCapture(charge.getExternalId()); assertThat(response.isSuccessful(), is(true)); InOrder inOrder = Mockito.inOrder(chargeSpy); inOrder.verify(chargeSpy).setStatus(CAPTURE_READY); inOrder.verify(chargeSpy).setStatus(CAPTURE_SUBMITTED); inOrder.verify(chargeSpy).setStatus(CAPTURED); ArgumentCaptor<ChargeEntity> chargeEntityCaptor = ArgumentCaptor.forClass(ChargeEntity.class); ArgumentCaptor<Optional> bookingDateCaptor = ArgumentCaptor.forClass(Optional.class); verify(mockedChargeEventDao, times(2)).persistChargeEventOf(chargeEntityCaptor.capture(), bookingDateCaptor.capture()); assertThat(chargeEntityCaptor.getValue().getStatus(), is(CAPTURED.getValue())); <START> verify(mockStatusUpdater).updateChargeTransactionStatus(charge.getExternalId(), CAPTURE_READY); <END> verify(mockStatusUpdater).updateChargeTransactionStatus(charge.getExternalId(), CAPTURE_SUBMITTED); verify(mockStatusUpdater).updateChargeTransactionStatus(charge.getExternalId(), CAPTURED); assertFalse(bookingDateCaptor.getAllValues().get(0).isPresent()); assertTrue(bookingDateCaptor.getAllValues().get(1).isPresent()); ArgumentCaptor<CaptureGatewayRequest> request = ArgumentCaptor.forClass(CaptureGatewayRequest.class); verify(mockedPaymentProvider, times(1)).capture(request.capture()); assertThat(request.getValue().getTransactionId(), is(gatewayTxId)); verify(mockUserNotificationService).notifyPaymentSuccessEmail(chargeSpy); }</code><technical_language>More in-order verification opportunities</technical_language>

Target:
public void doCapture_shouldCaptureAChargeForASandboxAccount() throws Exception { String gatewayTxId = "theTxId"; ChargeEntity charge = createNewChargeWith("sandbox",1L, CAPTURE_APPROVED, gatewayTxId); ChargeEntity chargeSpy = spy(charge); mockChargeDaoOperations(chargeSpy); worldpayWillRespondWithSuccess(gatewayTxId, null); when(mockedProviders.byName(charge.getPaymentGatewayName())).thenReturn(mockedPaymentProvider); GatewayResponse response = cardCaptureService.doCapture(charge.getExternalId()); assertThat(response.isSuccessful(), is(true)); InOrder inOrder = Mockito.inOrder(chargeSpy); inOrder.verify(chargeSpy).setStatus(CAPTURE_READY); inOrder.verify(chargeSpy).setStatus(CAPTURE_SUBMITTED); inOrder.verify(chargeSpy).setStatus(CAPTURED); ArgumentCaptor<ChargeEntity> chargeEntityCaptor = ArgumentCaptor.forClass(ChargeEntity.class); ArgumentCaptor<Optional> bookingDateCaptor = ArgumentCaptor.forClass(Optional.class); verify(mockedChargeEventDao, times(2)).persistChargeEventOf(chargeEntityCaptor.capture(), bookingDateCaptor.capture()); assertThat(chargeEntityCaptor.getValue().getStatus(), is(CAPTURED.getValue())); InOrder inOrderVerifier = inOrder(mockStatusUpdater); inOrderVerifier.verify(mockStatusUpdater).updateChargeTransactionStatus(charge.getExternalId(), CAPTURE_READY); inOrderVerifier.verify(mockStatusUpdater).updateChargeTransactionStatus(charge.getExternalId(), CAPTURE_SUBMITTED); inOrderVerifier.verify(mockStatusUpdater).updateChargeTransactionStatus(charge.getExternalId(), CAPTURED); assertFalse(bookingDateCaptor.getAllValues().get(0).isPresent()); assertTrue(bookingDateCaptor.getAllValues().get(1).isPresent()); ArgumentCaptor<CaptureGatewayRequest> request = ArgumentCaptor.forClass(CaptureGatewayRequest.class); verify(mockedPaymentProvider, times(1)).capture(request.capture()); assertThat(request.getValue().getTransactionId(), is(gatewayTxId)); verify(mockUserNotificationService).notifyPaymentSuccessEmail(chargeSpy); }