Add easylog test cases. Need refactor these classes later.
This commit is contained in:
parent
99024b3d0f
commit
ee7cf9da2b
|
|
@ -3,9 +3,6 @@ package com.a.eye.skywalking.api.logging;
|
|||
import com.a.eye.skywalking.api.conf.Config;
|
||||
|
||||
public class WriterFactory {
|
||||
private WriterFactory(){
|
||||
}
|
||||
|
||||
public static IWriter getLogWriter(){
|
||||
if (Config.SkyWalking.IS_PREMAIN_MODE){
|
||||
return SyncFileWriter.instance();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,14 @@
|
|||
package com.a.eye.skywalking.api.logging;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Created by wusheng on 2017/2/28.
|
||||
*/
|
||||
public class EasyLogResolverTest {
|
||||
@Test
|
||||
public void testGetLogger(){
|
||||
Assert.assertTrue(new EasyLogResolver().getLogger(EasyLogResolverTest.class) instanceof EasyLogger);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
package com.a.eye.skywalking.api.logging;
|
||||
|
||||
import com.a.eye.skywalking.api.conf.Config;
|
||||
import java.io.PrintStream;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.times;
|
||||
|
||||
/**
|
||||
* Created by wusheng on 2017/2/28.
|
||||
*/
|
||||
public class EasyLoggerTest {
|
||||
private static PrintStream outRef;
|
||||
private static PrintStream errRef;
|
||||
|
||||
@BeforeClass
|
||||
public static void initAndHoldOut(){
|
||||
outRef = System.out;
|
||||
errRef = System.err;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLog(){
|
||||
Config.SkyWalking.IS_PREMAIN_MODE = false;
|
||||
|
||||
PrintStream output = Mockito.mock(PrintStream.class);
|
||||
System.setOut(output);
|
||||
PrintStream err = Mockito.mock(PrintStream.class);
|
||||
System.setErr(err);
|
||||
EasyLogger logger = new EasyLogger(EasyLoggerTest.class);
|
||||
|
||||
Assert.assertTrue(logger.isDebugEnable());
|
||||
Assert.assertTrue(logger.isInfoEnable());
|
||||
Assert.assertTrue(logger.isWarnEnable());
|
||||
Assert.assertTrue(logger.isErrorEnable());
|
||||
|
||||
logger.debug("hello world");
|
||||
logger.debug("hello {}", "world");
|
||||
logger.info("hello world");
|
||||
logger.info("hello {}", "world");
|
||||
|
||||
logger.warn("hello {}", "world");
|
||||
logger.warn("hello world");
|
||||
logger.error("hello world");
|
||||
logger.error("hello world", new NullPointerException());
|
||||
logger.error(new NullPointerException(),"hello {}", "world");
|
||||
|
||||
Mockito.verify(output,times(4))
|
||||
.println(anyString());
|
||||
Mockito.verify(err,times(7))
|
||||
.println(anyString());
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void reset(){
|
||||
System.setOut(outRef);
|
||||
System.setErr(errRef);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
package com.a.eye.skywalking.api.logging;
|
||||
|
||||
import com.a.eye.skywalking.api.conf.Config;
|
||||
import java.io.PrintStream;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
/**
|
||||
* Created by wusheng on 2017/2/28.
|
||||
*/
|
||||
public class WriterFactoryTest {
|
||||
private static PrintStream errRef;
|
||||
|
||||
@BeforeClass
|
||||
public static void initAndHoldOut(){
|
||||
errRef = System.err;
|
||||
}
|
||||
|
||||
/**
|
||||
* During this test case,
|
||||
* reset {@link System#out} to a Mock object, for avoid a console system.error.
|
||||
*/
|
||||
@Test
|
||||
public void testGetLogWriter(){
|
||||
Config.SkyWalking.IS_PREMAIN_MODE = true;
|
||||
PrintStream mockStream = Mockito.mock(PrintStream.class);
|
||||
System.setErr(mockStream);
|
||||
Assert.assertEquals(SyncFileWriter.instance(), WriterFactory.getLogWriter());
|
||||
|
||||
Config.SkyWalking.IS_PREMAIN_MODE = false;
|
||||
Assert.assertTrue(WriterFactory.getLogWriter() instanceof STDOutWriter);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void reset(){
|
||||
Config.SkyWalking.IS_PREMAIN_MODE = false;
|
||||
System.setErr(errRef);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue