WriterFactory { public static IWriter getLogWriter() { switch (Config.Logging.OUTPUT) { case FILE: if (WRITER != null) { return WRITER; } if (SnifferConfigInitializer.isInitCompleted() && AgentPackagePath.isPathFound()) { if (StringUtil.isEmpty(Config.Logging.DIR)) { try { Config.Logging.DIR = AgentPackagePath.getPath() + "/logs"; } catch (AgentPackageNotFoundException e) { e.printStackTrace(); } } WRITER = FileWriter.get(); } else { return SystemOutWriter.INSTANCE; } break; default: return SystemOutWriter.INSTANCE; } return WRITER; }  static IWriter getLogWriter();  }
@Test public void alwaysReturnSystemLogWriteWithSetLoggingDir() { Config.Logging.OUTPUT = LogOutput.CONSOLE; PowerMockito.mockStatic(SnifferConfigInitializer.class); PowerMockito.mockStatic(AgentPackagePath.class); BDDMockito.given(SnifferConfigInitializer.isInitCompleted()).willReturn(true); BDDMockito.given(AgentPackagePath.isPathFound()).willReturn(true); assertTrue(SnifferConfigInitializer.isInitCompleted()); assertTrue(AgentPackagePath.isPathFound()); IWriter logWriter = WriterFactory.getLogWriter(); assertTrue(logWriter instanceof SystemOutWriter); }
@Test public void returnFileWriterWriteWithBlankLoggingDir() { Config.Logging.OUTPUT = LogOutput.FILE; PowerMockito.mockStatic(SnifferConfigInitializer.class); PowerMockito.mockStatic(AgentPackagePath.class); BDDMockito.given(SnifferConfigInitializer.isInitCompleted()).willReturn(true); BDDMockito.given(AgentPackagePath.isPathFound()).willReturn(true); assertTrue(SnifferConfigInitializer.isInitCompleted()); assertTrue(AgentPackagePath.isPathFound()); IWriter logWriter = WriterFactory.getLogWriter(); assertTrue(logWriter instanceof FileWriter); }