### Question:
CheckFundsGtZeroHandler { @EventListener public void handleRefund(final RefundProcessedEvent refundProcessedEvent) { final Long requestId = refundProcessedEvent.getRefund().getRequestId(); if (!hasTokenValueGtZero(fundService.getTotalFundsForRequest(requestId)) && hasRequestStatus(requestId, FUNDED)) { requestService.update(new UpdateRequestStatusCommand(requestId, OPEN)); } } CheckFundsGtZeroHandler(final FundService fundService, final RequestService requestService); @EventListener void handleFund(final RequestFundedEvent requestFundedEvent); @EventListener void handleRefund(final RefundProcessedEvent refundProcessedEvent);  }### Answer:
@Test void onRefund_fundsPresent() { final long requestId = 254L; when(fundService.getTotalFundsForRequest(requestId)).thenReturn(Arrays.asList(TokenValueDtoMother.FND().totalAmount(new BigDecimal("45")).build(), TokenValueDtoMother.ZRX().totalAmount(new BigDecimal("23")).build())); handler.handleRefund(new RefundProcessedEvent(Refund.builder().requestId(requestId).build())); verifyZeroInteractions(requestService); }
@Test void onRefund_noMoreFundsPresent() { final long requestId = 32L; final RequestDto requestDto = RequestDtoMother.fundRequestArea51(); requestDto.setStatus(FUNDED); when(fundService.getTotalFundsForRequest(requestId)).thenReturn(Arrays.asList(TokenValueDtoMother.FND().totalAmount(new BigDecimal("0")).build(), TokenValueDtoMother.ZRX().totalAmount(new BigDecimal("0")).build())); when(requestService.findRequest(requestId)).thenReturn(requestDto); handler.handleRefund(new RefundProcessedEvent(Refund.builder().requestId(requestId).build())); verify(requestService).update(new UpdateRequestStatusCommand(requestId, OPEN)); }
@Test void onRefund_nothingPresent() { final long requestId = 87L; final RequestDto requestDto = RequestDtoMother.fundRequestArea51(); requestDto.setStatus(FUNDED); when(fundService.getTotalFundsForRequest(requestId)).thenReturn(new ArrayList<>()); when(requestService.findRequest(requestId)).thenReturn(requestDto); handler.handleRefund(new RefundProcessedEvent(Refund.builder().requestId(requestId).build())); verify(requestService).update(new UpdateRequestStatusCommand(requestId, OPEN)); }
@Test void onRefund_statusNotFUNDED() { final long requestId = 254L; final RequestDto requestDto = RequestDtoMother.fundRequestArea51(); requestDto.setStatus(OPEN); when(fundService.getTotalFundsForRequest(requestId)).thenReturn(Arrays.asList(TokenValueDtoMother.FND().totalAmount(new BigDecimal("0")).build(), TokenValueDtoMother.ZRX().totalAmount(new BigDecimal("0")).build())); when(requestService.findRequest(requestId)).thenReturn(requestDto); handler.handleRefund(new RefundProcessedEvent(Refund.builder().requestId(requestId).build())); verify(requestService).findRequest(requestId); verifyNoMoreInteractions(requestService); }