### Question:
ResetRequestHandler implements OcppRequestHandler<ResetRequest> { @Override public void handle(String callId, ResetRequest request) { sendResponse(callId, new ResetResponse().withStatus(ResetResponse.Status.ACCEPTED)); resetStation(); }  @Override void handle(String callId, ResetRequest request);  }### Answer:
@Test void verifyMessageOnImmediateResetRequestType() throws JsonProcessingException { ResetRequest request = OcppMessageFactory.createResetRequest() .withType(ResetRequest.Type.IMMEDIATE) .build(); resetRequestHandler.handle(DEFAULT_MESSAGE_ID, request); ResetResponse payload = new ResetResponse().withStatus(ResetResponse.Status.ACCEPTED); ArgumentCaptor<AbstractWebSocketClientInboxMessage> messageCaptor = ArgumentCaptor.forClass(AbstractWebSocketClientInboxMessage.class); verify(stationMessageSender).sendMessage(messageCaptor.capture()); String expectedCallResult = JsonMessageTypeFactory.createCallResult() .withMessageId(DEFAULT_MESSAGE_ID) .withPayload(payload) .toJson(); assertThat(messageCaptor.getValue().getData().get()).isEqualTo(expectedCallResult); }
@Test void verifyEventSending() { Evse evse = mock(Evse.class); ResetRequest request = OcppMessageFactory.createResetRequest() .withType(ResetRequest.Type.IMMEDIATE) .build(); when(stationStore.getEvseIds()).thenReturn(Collections.singletonList(1)); when(stationStore.hasOngoingTransaction(anyInt())).thenReturn(true); when(stationStore.findEvse(anyInt())).thenReturn(evse); when(evse.getWattConsumedLastSession()).thenReturn(0L); resetRequestHandler.handle(DEFAULT_MESSAGE_ID, request); verify(stationStore).stopCharging(anyInt()); verify(stationMessageSender).sendTransactionEventEndedAndSubscribe(anyInt(), anyInt(), any(TransactionEventRequest.TriggerReason.class), any(TransactionData.StoppedReason.class), anyLong(), any(Subscriber.class)); }
@Test void verifyRebooting() { ResetRequest request = OcppMessageFactory.createResetRequest() .withType(ResetRequest.Type.IMMEDIATE) .build(); when(stationStore.getEvseIds()).thenReturn(Collections.singletonList(1)); when(stationStore.hasOngoingTransaction(anyInt())).thenReturn(false); resetRequestHandler.handle(DEFAULT_MESSAGE_ID, request); verify(stationStore).clearTokens(); verify(stationStore).clearTransactions(); verify(stationMessageSender, times(3)).sendMessage(any(AbstractWebSocketClientInboxMessage.class)); verify(stationMessageSender).sendBootNotification(any(BootNotificationRequest.Reason.class)); }
@Test void verifyMessageOnIdleResetRequestType() throws JsonProcessingException { ResetRequest request = OcppMessageFactory.createResetRequest() .withType(ResetRequest.Type.ON_IDLE) .build(); resetRequestHandler.handle(DEFAULT_MESSAGE_ID, request); ResetResponse payload = new ResetResponse().withStatus(ResetResponse.Status.ACCEPTED); ArgumentCaptor<AbstractWebSocketClientInboxMessage> messageCaptor = ArgumentCaptor.forClass(AbstractWebSocketClientInboxMessage.class); verify(stationMessageSender).sendMessage(messageCaptor.capture()); String expectedCallResult = JsonMessageTypeFactory.createCallResult() .withMessageId(DEFAULT_MESSAGE_ID) .withPayload(payload) .toJson(); assertThat(messageCaptor.getValue().getData().get()).isEqualTo(expectedCallResult); }