private OrderBookEntry createOrderBookEntry() { OrderBookEntry orderBookEntry = new OrderBookEntry(); orderBookEntry.setIdentifier(orderBookIdentifier.toString()); orderBookEntry.setCompanyIdentifier(companyIdentifier.toString()); orderBookEntry.setCompanyName(DEFAULT_COMPANY_NAME); return orderBookEntry; }
@Test public void handleSellTransactionCancelledEvent() { TransactionEntry transactionEntry = new TransactionEntry(); transactionEntry.setIdentifier(transactionIdentifier.toString()); transactionEntry.setAmountOfExecutedItems(0); transactionEntry.setPricePerItem(DEFAULT_ITEM_PRICE); transactionEntry.setState(STARTED); transactionEntry.setAmountOfItems(DEFAULT_TOTAL_ITEMS); transactionEntry.setCompanyName(DEFAULT_COMPANY_NAME); transactionEntry.setOrderbookIdentifier(orderBookIdentifier.toString()); transactionEntry.setPortfolioIdentifier(portfolioIdentifier.toString()); transactionEntry.setType(SELL); Mockito.when(transactionQueryRepository.findOne(transactionIdentifier.toString())) .thenReturn(transactionEntry); SellTransactionCancelledEvent event = new SellTransactionCancelledEvent( transactionIdentifier, DEFAULT_TOTAL_ITEMS, DEFAULT_TOTAL_ITEMS); listener.handleEvent(event); Mockito.verify(transactionQueryRepository) .save( Matchers.argThat( new TransactionEntryMatcher( DEFAULT_TOTAL_ITEMS, 0, DEFAULT_COMPANY_NAME, DEFAULT_ITEM_PRICE, CANCELLED, SELL))); }
@Before public void setUp() throws Exception { transactionQueryRepository = Mockito.mock(TransactionQueryRepository.class); OrderBookQueryRepository orderBookQueryRepository = Mockito.mock(OrderBookQueryRepository.class); listener = new TransactionEventListener(); listener.setTransactionQueryRepository(transactionQueryRepository); listener.setOrderBookQueryRepository(orderBookQueryRepository); Mockito.when(orderBookQueryRepository.findOne(orderBookIdentifier.toString())) .thenReturn(createOrderBookEntry()); }