@Test
public void testConfigDirLog4jConfig() throws IOException {
RuntimeInfo runtimeInfo = Mockito.mock(RuntimeInfo.class);
File configDir = new File("target", UUID.randomUUID().toString());
Assert.assertTrue(configDir.mkdirs());
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("log4j.properties");
OutputStream os = new FileOutputStream(new File(configDir, "log4j.properties"));
IOUtils.copy(is, os);
is.close();
os.close();
Mockito.when(runtimeInfo.getConfigDir()).thenReturn(configDir.getAbsolutePath());
Mockito.when(runtimeInfo.getLog4jPropertiesFileName()).thenReturn("log4j.properties");
new LogConfigurator(runtimeInfo).configure();
Mockito.verify(runtimeInfo, Mockito.times(1)).getConfigDir();
boolean foundFileWatcher = false;
for (Thread thread : Thread.getAllStackTraces().keySet()) {
foundFileWatcher |= (thread instanceof FileWatchdog);
}
Assert.assertTrue(foundFileWatcher);
Mockito.verify(runtimeInfo, Mockito.times(1)).setAttribute(Mockito.eq(RuntimeInfo.LOG4J_CONFIGURATION_URL_ATTR),
Mockito.any());
}
TestLogConfigurator.java 文件源码
java
阅读 21
收藏 0
点赞 0
评论 0
项目:datacollector
作者:
评论列表
文章目录