### Question:
CoinOrderBookListener { @EventHandler public void handleCoinCreated(CoinCreatedEvent event) { logger.info("About to dispatch a new command to create an OrderBook for the coin {}", event.getCoinIdentifier()); OrderBookId orderBookId = new OrderBookId(); final CoinId coinId = event.getCoinIdentifier(); final CurrencyPair currencyPair = new CurrencyPair(coinId.toString()); CreateOrderBookCommand createOrderBookCommand = new CreateOrderBookCommand(orderBookId, currencyPair); commandGateway.send(createOrderBookCommand); AddOrderBookToCoinCommand addOrderBookToCoinCommand = new AddOrderBookToCoinCommand( event.getCoinIdentifier(), orderBookId, currencyPair); commandGateway.send(addOrderBookToCoinCommand); }  @EventHandler void handleCoinCreated(CoinCreatedEvent event); @Autowired void setCommandGateway(CommandGateway commandGateway);  }### Answer:
@Test public void testHandleCoinCreated() throws Exception { final CoinId coinId = new CoinId("BTC"); final String coinName = "BTC Coin Name"; final BigMoney price = BigMoney.of(Constants.DEFAULT_CURRENCY_UNIT, 10); final BigMoney amount = BigMoney.of(Constants.CURRENCY_UNIT_BTC, 100); final CoinOrderBookListener listener = new CoinOrderBookListener(); final CommandGateway gateway = mock(CommandGateway.class); listener.setCommandGateway(gateway); listener.handleCoinCreated(new CoinCreatedEvent( coinId, coinName, price, amount)); ArgumentCaptor<CommandSupport> captor = ArgumentCaptor.forClass(CommandSupport.class); verify(gateway, times(2)).send(captor.capture()); final List<CommandSupport> commands = captor.getAllValues(); assertThat(commands, not(empty())); assertThat(commands, hasSize(2)); CommandSupport commandSupport = commands.get(0); assertThat(commandSupport, instanceOf(CreateOrderBookCommand.class)); CreateOrderBookCommand createOrderBookCommand = (CreateOrderBookCommand) commands.get(0); final OrderBookId orderBookIdentifier = createOrderBookCommand.getOrderBookIdentifier(); assertThat(createOrderBookCommand.getCurrencyPair(), equalTo(new CurrencyPair(coinId.toString()))); assertThat(createOrderBookCommand.getOrderBookIdentifier(), notNullValue()); commandSupport = commands.get(1); assertThat(commandSupport, instanceOf(AddOrderBookToCoinCommand.class)); AddOrderBookToCoinCommand addOrderBookToCoinCommand = (AddOrderBookToCoinCommand) commands.get(1); assertThat(addOrderBookToCoinCommand.getCurrencyPair(), equalTo(new CurrencyPair(coinId.toString()))); assertThat(addOrderBookToCoinCommand.getOrderBookId(), equalTo(orderBookIdentifier)); assertThat(addOrderBookToCoinCommand.getCoinId(), equalTo(coinId)); }