### Question:
BarSeriesManager { public TradingRecord run(Strategy strategy) { return run(strategy, OrderType.BUY); } BarSeriesManager();  BarSeriesManager(BarSeries barSeries);  BarSeriesManager(BarSeries barSeries, CostModel transactionCostModel, CostModel holdingCostModel); void setBarSeries(BarSeries barSeries); BarSeries getBarSeries(); TradingRecord run(Strategy strategy); TradingRecord run(Strategy strategy, int startIndex, int finishIndex); TradingRecord run(Strategy strategy, OrderType orderType); TradingRecord run(Strategy strategy, OrderType orderType, int startIndex, int finishIndex); TradingRecord run(Strategy strategy, OrderType orderType, Num amount); TradingRecord run(Strategy strategy, OrderType orderType, Num amount, int startIndex, int finishIndex);  }### Answer:
@Test public void runOnSeries() { List<Trade> trades = manager.run(strategy).getTrades(); assertEquals(2, trades.size()); assertEquals(Order.buyAt(2, seriesForRun.getBar(2).getClosePrice(), numOf(1)), trades.get(0).getEntry()); assertEquals(Order.sellAt(4, seriesForRun.getBar(4).getClosePrice(), numOf(1)), trades.get(0).getExit()); assertEquals(Order.buyAt(6, seriesForRun.getBar(6).getClosePrice(), numOf(1)), trades.get(1).getEntry()); assertEquals(Order.sellAt(7, seriesForRun.getBar(7).getClosePrice(), numOf(1)), trades.get(1).getExit()); }
@Test public void runWithOpenEntryBuyLeft() { Strategy aStrategy = new BaseStrategy(new FixedRule(1), new FixedRule(3)); List<Trade> trades = manager.run(aStrategy, 0, 3).getTrades(); assertEquals(1, trades.size()); assertEquals(Order.buyAt(1, seriesForRun.getBar(1).getClosePrice(), numOf(1)), trades.get(0).getEntry()); assertEquals(Order.sellAt(3, seriesForRun.getBar(3).getClosePrice(), numOf(1)), trades.get(0).getExit()); }
@Test public void runWithOpenEntrySellLeft() { Strategy aStrategy = new BaseStrategy(new FixedRule(1), new FixedRule(3)); List<Trade> trades = manager.run(aStrategy, OrderType.SELL, 0, 3).getTrades(); assertEquals(1, trades.size()); assertEquals(Order.sellAt(1, seriesForRun.getBar(1).getClosePrice(), numOf(1)), trades.get(0).getEntry()); assertEquals(Order.buyAt(3, seriesForRun.getBar(3).getClosePrice(), numOf(1)), trades.get(0).getExit()); }
@Test public void runBetweenIndexes() { List<Trade> trades = manager.run(strategy, 0, 3).getTrades(); assertEquals(1, trades.size()); assertEquals(Order.buyAt(2, seriesForRun.getBar(2).getClosePrice(), numOf(1)), trades.get(0).getEntry()); assertEquals(Order.sellAt(4, seriesForRun.getBar(4).getClosePrice(), numOf(1)), trades.get(0).getExit()); trades = manager.run(strategy, 4, 4).getTrades(); assertTrue(trades.isEmpty()); trades = manager.run(strategy, 5, 8).getTrades(); assertEquals(1, trades.size()); assertEquals(Order.buyAt(6, seriesForRun.getBar(6).getClosePrice(), numOf(1)), trades.get(0).getEntry()); assertEquals(Order.sellAt(7, seriesForRun.getBar(7).getClosePrice(), numOf(1)), trades.get(0).getExit()); }