@Test public void shouldWriteTrendForMarketDataMessages() throws CommunicationException { final TrendForMarketDataMessage trend1 = new TrendForMarketDataMessage(Optional.of(MarketDirection.DOWN)); final TrendForMarketDataMessage trend2 = new TrendForMarketDataMessage(Optional.of(MarketDirection.UP)); cut.sendMessage(trend1); cut.sendMessage(trend2); final InOrder inOrder = inOrder(client); inOrder.verify(client).trySendByte(MessageType.TREND_FOR_MARKET_DATA.getMessageNumber()); inOrder.verify(client).trySendByte((byte) 1); inOrder.verify(client).trySendByte(MessageType.TREND_FOR_MARKET_DATA.getMessageNumber()); inOrder.verify(client).trySendByte((byte) 0); }
public void sendMessage(final Message message) throws CommunicationException { final MessageType messageType = MessageType.forMessageClass(message.getClass()); writeMessageNumber(messageType); switch (messageType) { case TREND_FOR_MARKET_DATA: writeMessage((TrendForMarketDataMessage) message); break; case CLOSE_OR_CANCEL_PENDING_ORDER: writeMessage((CloseOrCancelPendingOrderMessage) message); break; case PLACE_PENDING_ORDER: writeMessage((PlacePendingOrderMessage) message); break; case CHANGE_CLOSE_CONDITIONS: writeMessage((ChangeCloseConditionsMessage) message); break; case EVENT_HANDLING_FINISHED: break; default: throw new UnsupportedOperationException("Writing of " + messageType + " messages is not supported."); } }
MessageBasedClientConnection { public void sendMessage(final Message message) throws CommunicationException { final MessageType messageType = MessageType.forMessageClass(message.getClass()); writeMessageNumber(messageType); switch (messageType) { case TREND_FOR_MARKET_DATA: writeMessage((TrendForMarketDataMessage) message); break; case CLOSE_OR_CANCEL_PENDING_ORDER: writeMessage((CloseOrCancelPendingOrderMessage) message); break; case PLACE_PENDING_ORDER: writeMessage((PlacePendingOrderMessage) message); break; case CHANGE_CLOSE_CONDITIONS: writeMessage((ChangeCloseConditionsMessage) message); break; case EVENT_HANDLING_FINISHED: break; default: throw new UnsupportedOperationException("Writing of " + messageType + " messages is not supported."); } } }
MessageBasedClientConnection { public void sendMessage(final Message message) throws CommunicationException { final MessageType messageType = MessageType.forMessageClass(message.getClass()); writeMessageNumber(messageType); switch (messageType) { case TREND_FOR_MARKET_DATA: writeMessage((TrendForMarketDataMessage) message); break; case CLOSE_OR_CANCEL_PENDING_ORDER: writeMessage((CloseOrCancelPendingOrderMessage) message); break; case PLACE_PENDING_ORDER: writeMessage((PlacePendingOrderMessage) message); break; case CHANGE_CLOSE_CONDITIONS: writeMessage((ChangeCloseConditionsMessage) message); break; case EVENT_HANDLING_FINISHED: break; default: throw new UnsupportedOperationException("Writing of " + messageType + " messages is not supported."); } } MessageBasedClientConnection(final ClientConnection connection); }
MessageBasedClientConnection { public void sendMessage(final Message message) throws CommunicationException { final MessageType messageType = MessageType.forMessageClass(message.getClass()); writeMessageNumber(messageType); switch (messageType) { case TREND_FOR_MARKET_DATA: writeMessage((TrendForMarketDataMessage) message); break; case CLOSE_OR_CANCEL_PENDING_ORDER: writeMessage((CloseOrCancelPendingOrderMessage) message); break; case PLACE_PENDING_ORDER: writeMessage((PlacePendingOrderMessage) message); break; case CHANGE_CLOSE_CONDITIONS: writeMessage((ChangeCloseConditionsMessage) message); break; case EVENT_HANDLING_FINISHED: break; default: throw new UnsupportedOperationException("Writing of " + messageType + " messages is not supported."); } } MessageBasedClientConnection(final ClientConnection connection); Message readMessage(); @SuppressWarnings("unchecked") M readMessage(final Class<M> messageClass); void sendMessage(final Message message); @Override String toString(); }
MessageBasedClientConnection { public void sendMessage(final Message message) throws CommunicationException { final MessageType messageType = MessageType.forMessageClass(message.getClass()); writeMessageNumber(messageType); switch (messageType) { case TREND_FOR_MARKET_DATA: writeMessage((TrendForMarketDataMessage) message); break; case CLOSE_OR_CANCEL_PENDING_ORDER: writeMessage((CloseOrCancelPendingOrderMessage) message); break; case PLACE_PENDING_ORDER: writeMessage((PlacePendingOrderMessage) message); break; case CHANGE_CLOSE_CONDITIONS: writeMessage((ChangeCloseConditionsMessage) message); break; case EVENT_HANDLING_FINISHED: break; default: throw new UnsupportedOperationException("Writing of " + messageType + " messages is not supported."); } } MessageBasedClientConnection(final ClientConnection connection); Message readMessage(); @SuppressWarnings("unchecked") M readMessage(final Class<M> messageClass); void sendMessage(final Message message); @Override String toString();  }