### Question:
Plug implements UserMessage { @Override public CompletableFuture<UserMessageResult> perform(StateManager stateManager) { return stateManager.cablePlugged(evseId, connectorId); }  @Override CompletableFuture<UserMessageResult> perform(StateManager stateManager);  }### Answer:
@Test void shouldFutureFailOnIllegalState() throws Exception { when(stationStoreMock.findEvse(anyInt())).thenReturn(evseMock); when(evseMock.findConnector(anyInt())).thenReturn(connectorMock); when(connectorMock.getCableStatus()).thenReturn(CableStatus.LOCKED); assertEquals(UserMessageResult.FAILED, plug.perform(stateManagerMock).get()); }
@Test void verifyTransactionEventUpdate() { when(stationStoreMock.findEvse(anyInt())).thenReturn(evseMock); when(evseMock.findConnector(anyInt())).thenReturn(connectorMock); when(evseMock.hasOngoingTransaction()).thenReturn(true); when(connectorMock.getCableStatus()).thenReturn(CableStatus.UNPLUGGED); when(evseMock.getEvseState()).thenReturn(new WaitingForPlugState()); plug.perform(stateManagerMock); ArgumentCaptor<Subscriber<StatusNotificationRequest, StatusNotificationResponse>> subscriberCaptor = ArgumentCaptor.forClass(Subscriber.class); verify(stationMessageSenderMock).sendStatusNotificationAndSubscribe(any(Evse.class), any(Connector.class), subscriberCaptor.capture()); subscriberCaptor.getValue().onResponse(new StatusNotificationRequest(), new StatusNotificationResponse()); verify(stationMessageSenderMock, times(2)).sendTransactionEventUpdate(anyInt(), anyInt(), any(TransactionEventRequest.TriggerReason.class), isNull(), any(TransactionData.ChargingState.class)); }
@Test void verifyTransactionEventStart() { when(stationStoreMock.findEvse(anyInt())).thenReturn(evseMock); when(stationStoreMock.getTxStartPointValues()).thenReturn(new OptionList<>(Arrays.asList(TxStartStopPointVariableValues.EV_CONNECTED))); when(evseMock.findConnector(anyInt())).thenReturn(connectorMock); when(connectorMock.getCableStatus()).thenReturn(CableStatus.UNPLUGGED); plug.perform(stateManagerMock); ArgumentCaptor<Subscriber<StatusNotificationRequest, StatusNotificationResponse>> subscriberCaptor = ArgumentCaptor.forClass(Subscriber.class); verify(stationMessageSenderMock).sendStatusNotificationAndSubscribe(any(Evse.class), any(Connector.class), subscriberCaptor.capture()); subscriberCaptor.getValue().onResponse(new StatusNotificationRequest(), new StatusNotificationResponse()); verify(stationMessageSenderMock).sendTransactionEventStart(anyInt(), anyInt(), any(TransactionEventRequest.TriggerReason.class), any(TransactionData.ChargingState.class)); }