@Test public void shouldPassRuntimeExceptionToExceptionHandler() throws CommunicationException { final RequestTradingAlgorithmMessage msg = new RequestTradingAlgorithmMessage(AlgorithmType.TREND_INDICATOR, EXAMPLE_INDICATOR_NUMBER); final RuntimeException exampleRuntimeException = new RuntimeException(); when(exampleMessageBasedClientConnection.readMessage(RequestTradingAlgorithmMessage.class)).thenReturn(msg); doThrow(exampleRuntimeException).when(exampleIndicatorProtocol).start(); cut.newClientCommunicationHandler(exampleClientConnection).run(); verify(exampleExceptionHandler).handleException(exampleRuntimeException); }
public Runnable newClientCommunicationHandler(final ClientConnection client) { final MessageBasedClientConnection messageBasedClient = protocolFactory.newMessageBasedClientConnection(client); return () -> { try { final RequestTradingAlgorithmMessage algorithmMessage = messageBasedClient .readMessage(RequestTradingAlgorithmMessage.class); switch (algorithmMessage.getAlgorithmType()) { case TREND_INDICATOR: protocolFactory.newIndicatorProtocol(messageBasedClient, algorithmMessage.getAlgorithmNumber()) .start(); break; case EXPERT_ADVISOR: protocolFactory .newExpertAdvisorProtocol(messageBasedClient, algorithmMessage.getAlgorithmNumber()) .start(); break; default: throw new ProtocolException("Trading algorithms of type " + algorithmMessage.getAlgorithmType() + " are not supported by this server."); } } catch (final CommunicationException e) { protocolFactory.newExceptionHandler(client).handleException(e); } catch (final RuntimeException e) { protocolFactory.newExceptionHandler(client).handleException(e); } }; }
ClientCommunicator { public Runnable newClientCommunicationHandler(final ClientConnection client) { final MessageBasedClientConnection messageBasedClient = protocolFactory.newMessageBasedClientConnection(client); return () -> { try { final RequestTradingAlgorithmMessage algorithmMessage = messageBasedClient .readMessage(RequestTradingAlgorithmMessage.class); switch (algorithmMessage.getAlgorithmType()) { case TREND_INDICATOR: protocolFactory.newIndicatorProtocol(messageBasedClient, algorithmMessage.getAlgorithmNumber()) .start(); break; case EXPERT_ADVISOR: protocolFactory .newExpertAdvisorProtocol(messageBasedClient, algorithmMessage.getAlgorithmNumber()) .start(); break; default: throw new ProtocolException("Trading algorithms of type " + algorithmMessage.getAlgorithmType() + " are not supported by this server."); } } catch (final CommunicationException e) { protocolFactory.newExceptionHandler(client).handleException(e); } catch (final RuntimeException e) { protocolFactory.newExceptionHandler(client).handleException(e); } }; } }
ClientCommunicator { public Runnable newClientCommunicationHandler(final ClientConnection client) { final MessageBasedClientConnection messageBasedClient = protocolFactory.newMessageBasedClientConnection(client); return () -> { try { final RequestTradingAlgorithmMessage algorithmMessage = messageBasedClient .readMessage(RequestTradingAlgorithmMessage.class); switch (algorithmMessage.getAlgorithmType()) { case TREND_INDICATOR: protocolFactory.newIndicatorProtocol(messageBasedClient, algorithmMessage.getAlgorithmNumber()) .start(); break; case EXPERT_ADVISOR: protocolFactory .newExpertAdvisorProtocol(messageBasedClient, algorithmMessage.getAlgorithmNumber()) .start(); break; default: throw new ProtocolException("Trading algorithms of type " + algorithmMessage.getAlgorithmType() + " are not supported by this server."); } } catch (final CommunicationException e) { protocolFactory.newExceptionHandler(client).handleException(e); } catch (final RuntimeException e) { protocolFactory.newExceptionHandler(client).handleException(e); } }; } ClientCommunicator(final ProtocolFactory protocolFactory); }
ClientCommunicator { public Runnable newClientCommunicationHandler(final ClientConnection client) { final MessageBasedClientConnection messageBasedClient = protocolFactory.newMessageBasedClientConnection(client); return () -> { try { final RequestTradingAlgorithmMessage algorithmMessage = messageBasedClient .readMessage(RequestTradingAlgorithmMessage.class); switch (algorithmMessage.getAlgorithmType()) { case TREND_INDICATOR: protocolFactory.newIndicatorProtocol(messageBasedClient, algorithmMessage.getAlgorithmNumber()) .start(); break; case EXPERT_ADVISOR: protocolFactory .newExpertAdvisorProtocol(messageBasedClient, algorithmMessage.getAlgorithmNumber()) .start(); break; default: throw new ProtocolException("Trading algorithms of type " + algorithmMessage.getAlgorithmType() + " are not supported by this server."); } } catch (final CommunicationException e) { protocolFactory.newExceptionHandler(client).handleException(e); } catch (final RuntimeException e) { protocolFactory.newExceptionHandler(client).handleException(e); } }; } ClientCommunicator(final ProtocolFactory protocolFactory); Runnable newClientCommunicationHandler(final ClientConnection client); }
ClientCommunicator { public Runnable newClientCommunicationHandler(final ClientConnection client) { final MessageBasedClientConnection messageBasedClient = protocolFactory.newMessageBasedClientConnection(client); return () -> { try { final RequestTradingAlgorithmMessage algorithmMessage = messageBasedClient .readMessage(RequestTradingAlgorithmMessage.class); switch (algorithmMessage.getAlgorithmType()) { case TREND_INDICATOR: protocolFactory.newIndicatorProtocol(messageBasedClient, algorithmMessage.getAlgorithmNumber()) .start(); break; case EXPERT_ADVISOR: protocolFactory .newExpertAdvisorProtocol(messageBasedClient, algorithmMessage.getAlgorithmNumber()) .start(); break; default: throw new ProtocolException("Trading algorithms of type " + algorithmMessage.getAlgorithmType() + " are not supported by this server."); } } catch (final CommunicationException e) { protocolFactory.newExceptionHandler(client).handleException(e); } catch (final RuntimeException e) { protocolFactory.newExceptionHandler(client).handleException(e); } }; } ClientCommunicator(final ProtocolFactory protocolFactory); Runnable newClientCommunicationHandler(final ClientConnection client);  }