### Question:
StopGainRule 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 = isBuyGainSatisfied(entryPrice, currentPrice); } else { satisfied = isSellGainSatisfied(entryPrice, currentPrice); } } } traceIsSatisfied(index, satisfied); return satisfied; } StopGainRule(ClosePriceIndicator closePrice, Number gainPercentage);  StopGainRule(ClosePriceIndicator closePrice, Num gainPercentage); @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); StopGainRule rule = new StopGainRule(closePrice, numOf(30)); assertFalse(rule.isSatisfied(0, null)); assertFalse(rule.isSatisfied(1, tradingRecord)); tradingRecord.enter(2, numOf(108), tradedAmount); assertFalse(rule.isSatisfied(2, tradingRecord)); assertFalse(rule.isSatisfied(3, tradingRecord)); assertTrue(rule.isSatisfied(4, tradingRecord)); tradingRecord.exit(5); tradingRecord.enter(5, numOf(118), 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); StopGainRule rule = new StopGainRule(closePrice, numOf(10)); assertFalse(rule.isSatisfied(0, null)); assertFalse(rule.isSatisfied(1, tradingRecord)); tradingRecord.enter(7, numOf(178), tradedAmount); assertFalse(rule.isSatisfied(7, tradingRecord)); assertFalse(rule.isSatisfied(8, tradingRecord)); assertTrue(rule.isSatisfied(9, tradingRecord)); tradingRecord.exit(10); tradingRecord.enter(3, numOf(119), tradedAmount); assertFalse(rule.isSatisfied(3, tradingRecord)); assertFalse(rule.isSatisfied(2, tradingRecord)); assertTrue(rule.isSatisfied(1, tradingRecord)); assertTrue(rule.isSatisfied(10, tradingRecord)); }