### Question:
StopLossRule extends AbstractRule { @Override public boolean isSatisfied(int index, TradingRecord tradingRecord) { boolean satisfied = false; if (tradingRecord != null) { Trade currentTrade = tradingRecord.getCurrentTrade(); if (currentTrade.isOpened()) { Num entryPrice = currentTrade.getEntry().getNetPrice(); Num currentPrice = closePrice.getValue(index); if (currentTrade.getEntry().isBuy()) { satisfied = isBuyStopSatisfied(entryPrice, currentPrice); } else { satisfied = isSellStopSatisfied(entryPrice, currentPrice); } } } traceIsSatisfied(index, satisfied); return satisfied; } StopLossRule(ClosePriceIndicator closePrice, Number lossPercentage);  StopLossRule(ClosePriceIndicator closePrice, Num lossPercentage); @Override boolean isSatisfied(int index, TradingRecord tradingRecord);  }### Answer:
@Test public void isSatisfiedWorksForBuy() { final TradingRecord tradingRecord = new BaseTradingRecord(Order.OrderType.BUY); final Num tradedAmount = numOf(1); StopLossRule rule = new StopLossRule(closePrice, numOf(5)); assertFalse(rule.isSatisfied(0, null)); assertFalse(rule.isSatisfied(1, tradingRecord)); tradingRecord.enter(2, numOf(114), tradedAmount); assertFalse(rule.isSatisfied(2, tradingRecord)); assertFalse(rule.isSatisfied(3, tradingRecord)); assertTrue(rule.isSatisfied(4, tradingRecord)); tradingRecord.exit(5); tradingRecord.enter(5, numOf(128), tradedAmount); assertFalse(rule.isSatisfied(5, tradingRecord)); assertTrue(rule.isSatisfied(6, tradingRecord)); assertTrue(rule.isSatisfied(7, tradingRecord)); }
@Test public void isSatisfiedWorksForSell() { final TradingRecord tradingRecord = new BaseTradingRecord(Order.OrderType.SELL); final Num tradedAmount = numOf(1); StopLossRule rule = new StopLossRule(closePrice, numOf(5)); assertFalse(rule.isSatisfied(0, null)); assertFalse(rule.isSatisfied(1, tradingRecord)); tradingRecord.enter(1, numOf(108), tradedAmount); assertFalse(rule.isSatisfied(1, tradingRecord)); assertFalse(rule.isSatisfied(2, tradingRecord)); assertTrue(rule.isSatisfied(3, tradingRecord)); tradingRecord.exit(4); tradingRecord.enter(2, numOf(114), tradedAmount); assertFalse(rule.isSatisfied(2, tradingRecord)); assertTrue(rule.isSatisfied(3, tradingRecord)); assertFalse(rule.isSatisfied(4, tradingRecord)); assertTrue(rule.isSatisfied(5, tradingRecord)); }