@Test
  public void testStatisticStatistics() throws Exception {
    File tempFile = File.createTempFile("ais-ab-stat-builder", "");
    String outputFilename = tempFile.getCanonicalPath();
    String inputDirectory = "src/test/resources";
    String inputFilenamePattern = "ais-sample-micro.txt.gz";
    String[] args =
        new String[] {
          "-inputDirectory",
          inputDirectory,
          "-input",
          inputFilenamePattern,
          "-output",
          outputFilename
        };

    Injector injector =
        Guice.createInjector(
            new AbnormalStatBuilderAppTestModule(
                tempFile.getCanonicalPath(), inputDirectory, inputFilenamePattern, false, 200.0));
    AbnormalStatBuilderApp.setInjector(injector);
    AbnormalStatBuilderApp app = injector.getInstance(AbnormalStatBuilderApp.class);

    AbnormalStatBuilderApp.userArguments = parseUserArguments(args);
    app.execute(new String[] {});

    AppStatisticsService appStatistics = injector.getInstance(AppStatisticsService.class);
    assertEquals(
        (Long) 8L,
        appStatistics.getStatisticStatistics("ShipTypeAndSizeStatistic", "Events processed"));
  }
  @Test
  public void testMetadataWrittenToDatabase() throws Exception {
    File tempFile = File.createTempFile("ais-ab-stat-builder", "");
    String outputFilename = tempFile.getCanonicalPath();
    String inputDirectory = "src/test/resources";
    String inputFilenamePattern = "ais-sample-micro.txt.gz";
    String[] args =
        new String[] {
          "-inputDirectory",
          inputDirectory,
          "-input",
          inputFilenamePattern,
          "-output",
          outputFilename
        };

    Injector injector =
        Guice.createInjector(
            new AbnormalStatBuilderAppTestModule(
                tempFile.getCanonicalPath(), inputDirectory, inputFilenamePattern, false, 200.0));
    AbnormalStatBuilderApp.setInjector(injector);
    AbnormalStatBuilderApp app = injector.getInstance(AbnormalStatBuilderApp.class);

    AbnormalStatBuilderApp.userArguments = parseUserArguments(args);
    app.execute(new String[] {});

    // Repo is closed by app. Get a new one.
    Injector injector2 =
        Guice.createInjector(
            new AbnormalStatBuilderAppTestModule(
                tempFile.getCanonicalPath(), inputDirectory, inputFilenamePattern, false, 200.0));
    StatisticDataRepository statisticsRepository =
        injector2.getInstance(StatisticDataRepository.class);

    assertNotNull(statisticsRepository.getMetaData());
    assertEquals(
        (Double) 0.0017966313162819712 /* res 200.0 */,
        statisticsRepository.getMetaData().getGridResolution(),
        1e-10);
    assertEquals((Integer) 60, statisticsRepository.getMetaData().getDownsampling());
    assertEquals((Short) (short) 1, statisticsRepository.getMetaData().getFormatVersion());
  }