LoggingConfigLoader { @VisibleForTesting void maybeLoadDefaultLogConfiguration(LogManager logManager) throws SecurityException, IOException { logManager.reset(); File logDirectory = new File(caliperDirectory, "log"); logDirectory.mkdirs(); FileHandler fileHandler = new FileHandler( String.format( "%s%c%s.%s.log", logDirectory.getAbsolutePath(), File.separatorChar, ISODateTimeFormat.basicDateTimeNoMillis().print(run.startTime()), run.id())); fileHandler.setEncoding(UTF_8.name()); fileHandler.setFormatter(new SimpleFormatter()); Logger globalLogger = logManager.getLogger(""); globalLogger.addHandler(fileHandler); } @Inject  LoggingConfigLoader(@CaliperDirectory File caliperDirectory, LogManager logManager, Run run);   }
@Test public void testLoadDefaultLogConfiguration() throws SecurityException, IOException { when(logManager.getLogger("")).thenReturn(logger); loader.maybeLoadDefaultLogConfiguration(logManager); verify(logManager).reset(); verify(logger).addHandler(handlerCaptor.capture()); FileHandler fileHandler = (FileHandler) handlerCaptor.getValue(); assertEquals(UTF_8.name(), fileHandler.getEncoding()); assertTrue(fileHandler.getFormatter() instanceof SimpleFormatter); fileHandler.publish(new LogRecord(INFO, "some message")); File logFile = new File( new File(caliperDirectory, "log"), ISODateTimeFormat.basicDateTimeNoMillis().print(startTime) + "." + runId + ".log"); assertTrue(logFile.isFile()); assertTrue(Files.asCharSource(logFile, UTF_8).read().contains("some message")); }