### Question:
WaitForRule extends AbstractRule { @Override public boolean isSatisfied(int index, TradingRecord tradingRecord) { boolean satisfied = false; if (tradingRecord != null) { Order lastOrder = tradingRecord.getLastOrder(orderType); if (lastOrder != null) { int currentNumberOfBars = index - lastOrder.getIndex(); satisfied = currentNumberOfBars >= numberOfBars; } } traceIsSatisfied(index, satisfied); return satisfied; } WaitForRule(OrderType orderType, int numberOfBars); @Override boolean isSatisfied(int index, TradingRecord tradingRecord);  }### Answer:
@Test public void waitForSinceLastBuyRuleIsSatisfied() { rule = new WaitForRule(Order.OrderType.BUY, 3); assertFalse(rule.isSatisfied(0, null)); assertFalse(rule.isSatisfied(1, tradingRecord)); tradingRecord.enter(10); assertFalse(rule.isSatisfied(10, tradingRecord)); assertFalse(rule.isSatisfied(11, tradingRecord)); assertFalse(rule.isSatisfied(12, tradingRecord)); assertTrue(rule.isSatisfied(13, tradingRecord)); assertTrue(rule.isSatisfied(14, tradingRecord)); tradingRecord.exit(15); assertTrue(rule.isSatisfied(15, tradingRecord)); assertTrue(rule.isSatisfied(16, tradingRecord)); tradingRecord.enter(17); assertFalse(rule.isSatisfied(17, tradingRecord)); assertFalse(rule.isSatisfied(18, tradingRecord)); assertFalse(rule.isSatisfied(19, tradingRecord)); assertTrue(rule.isSatisfied(20, tradingRecord)); }
@Test public void waitForSinceLastSellRuleIsSatisfied() { rule = new WaitForRule(Order.OrderType.SELL, 2); assertFalse(rule.isSatisfied(0, null)); assertFalse(rule.isSatisfied(1, tradingRecord)); tradingRecord.enter(10); assertFalse(rule.isSatisfied(10, tradingRecord)); assertFalse(rule.isSatisfied(11, tradingRecord)); assertFalse(rule.isSatisfied(12, tradingRecord)); assertFalse(rule.isSatisfied(13, tradingRecord)); tradingRecord.exit(15); assertFalse(rule.isSatisfied(15, tradingRecord)); assertFalse(rule.isSatisfied(16, tradingRecord)); assertTrue(rule.isSatisfied(17, tradingRecord)); tradingRecord.enter(17); assertTrue(rule.isSatisfied(17, tradingRecord)); assertTrue(rule.isSatisfied(18, tradingRecord)); tradingRecord.exit(20); assertFalse(rule.isSatisfied(20, tradingRecord)); assertFalse(rule.isSatisfied(21, tradingRecord)); assertTrue(rule.isSatisfied(22, tradingRecord)); }