ReportGenerator implements IReportGenerator { protected synchronized void writeRoundTripToFile(IRoundTrip roundTrip) { logger.info("Writing round trip to result file: " + roundTrip); String resultString = roundTrip.getResults() + "\n"; try { Files.write(Paths.get(outputFile), resultString.getBytes(), StandardOpenOption.APPEND, StandardOpenOption.CREATE); } catch (IOException e) { throw new IllegalStateException(e); } } protected  ReportGenerator();  ReportGenerator(String strategyName, String dir, IRoundTripBuilder roundTripBuilder); @Override void loadPartialRoundTrips(); @Override void savePartial(String correlationId, IRoundTrip trip); @Override void deletePartial(String correlationId); @Override void orderEvent(OrderEvent event);  }
@Test public void testWriteRoundTrip() throws Exception { Path path = Files.createTempFile("ReportGeneratorUnitTest", ".txt"); reportGenerator.outputFile = path.toString(); String expected = "2016-03-19T07:01:10,Long,ABC,100,100.23,0,2016-03-20T06:01:10,101.23,0,Short,XYZ,50,250.34,0,251.34,0"; Ticker longTicker = new StockTicker("ABC"); Ticker shortTicker = new StockTicker("XYZ"); int longSize = 100; int shortSize = 50; double longEntryFillPrice = 100.23; double longExitFillPrice = 101.23; double shortEntryFillPrice = 250.34; double shortExitFillPrice = 251.34; ZonedDateTime entryTime = ZonedDateTime.of(2016, 3, 19, 7, 1, 10, 0, ZoneId.systemDefault()); ZonedDateTime exitTime = ZonedDateTime.of(2016, 3, 20, 6, 1, 10, 0, ZoneId.systemDefault()); TradeOrder longEntry = new TradeOrder("123", longTicker, longSize, TradeDirection.BUY); longEntry.setFilledPrice(longEntryFillPrice); longEntry.setOrderFilledTime(entryTime); TradeOrder longExit = new TradeOrder("123", longTicker, longSize, TradeDirection.SELL); longExit.setFilledPrice(longExitFillPrice); longExit.setOrderFilledTime(exitTime); TradeOrder shortEntry = new TradeOrder("123", shortTicker, shortSize, TradeDirection.SELL); shortEntry.setFilledPrice(shortEntryFillPrice); shortEntry.setOrderFilledTime(entryTime); TradeOrder shortExit = new TradeOrder("123", shortTicker, shortSize, TradeDirection.BUY); shortExit.setFilledPrice(shortExitFillPrice); shortExit.setOrderFilledTime(exitTime); PairTradeRoundTrip roundTrip = new PairTradeRoundTrip(); roundTrip.longEntry = longEntry; roundTrip.longExit = longExit; roundTrip.shortEntry = shortEntry; roundTrip.shortExit = shortExit; System.out.println("Writing out to file: " + path); reportGenerator.writeRoundTripToFile(roundTrip); List<String> lines = Files.readAllLines(path); assertEquals(1, lines.size()); assertEquals(expected, lines.get(0)); Files.deleteIfExists(path); }