From 3b9a86efc24e19839229232c66f126dd458c263a Mon Sep 17 00:00:00 2001 From: hebelala Date: Wed, 26 Sep 2018 12:18:29 +0800 Subject: [PATCH] #509 add test for info(msg, t) --- .../vip/saturn/job/utils/LogUtilsTest.java | 80 +++++++++++-------- .../src/test/resources/logback-test.xml | 2 +- 2 files changed, 49 insertions(+), 33 deletions(-) diff --git a/saturn-core/src/test/java/com/vip/saturn/job/utils/LogUtilsTest.java b/saturn-core/src/test/java/com/vip/saturn/job/utils/LogUtilsTest.java index 1f90dcf12..9044969a8 100644 --- a/saturn-core/src/test/java/com/vip/saturn/job/utils/LogUtilsTest.java +++ b/saturn-core/src/test/java/com/vip/saturn/job/utils/LogUtilsTest.java @@ -43,18 +43,22 @@ public void info() { LogUtils.info(log, "event", "this is info"); assertEquals("[event] msg=this is info", testLogAppender.getLastMessage()); - LogUtils.info(log, "event", "this is info {}", "info1"); - assertEquals("[event] msg=this is info info1", testLogAppender.getLastMessage()); + LogUtils.info(log, "event", "this is info {}", "arg1"); + assertEquals("[event] msg=this is info arg1", testLogAppender.getLastMessage()); - LogUtils.info(log, "event", "this is info {} {}", "info1", "info2"); - assertEquals("[event] msg=this is info info1 info2", testLogAppender.getLastMessage()); + LogUtils.info(log, "event", "this is info {} {}", "arg1", "arg2"); + assertEquals("[event] msg=this is info arg1 arg2", testLogAppender.getLastMessage()); - LogUtils.info(log, "event", "this is info {} {}", "info1", "info2", new ClassNotFoundException("com.abc")); - assertEquals("[event] msg=this is info info1 info2", testLogAppender.getLastMessage()); + LogUtils.info(log, "event", "this is info {} {}", "arg1", "arg2", new ClassNotFoundException("com.abc")); + assertEquals("[event] msg=this is info arg1 arg2", testLogAppender.getLastMessage()); assertEquals("com.abc", testLogAppender.getLastEvent().getThrowableProxy().getMessage()); - LogUtils.info(log, "event", "this is error {}", "error1", new Error("com.def")); - assertEquals("[event] msg=this is error error1", testLogAppender.getLastMessage()); + LogUtils.info(log, "event", "this is info {}", "arg1", new Error("com.def")); + assertEquals("[event] msg=this is info arg1", testLogAppender.getLastMessage()); + assertEquals("com.def", testLogAppender.getLastEvent().getThrowableProxy().getMessage()); + + LogUtils.info(log, "event", "this is info", new Exception("com.def")); + assertEquals("[event] msg=this is info", testLogAppender.getLastMessage()); assertEquals("com.def", testLogAppender.getLastEvent().getThrowableProxy().getMessage()); } @@ -63,18 +67,22 @@ public void debug() { LogUtils.debug(log, "event", "this is debug"); assertEquals("[event] msg=this is debug", testLogAppender.getLastMessage()); - LogUtils.debug(log, "event", "this is debug {}", "info1"); - assertEquals("[event] msg=this is debug info1", testLogAppender.getLastMessage()); + LogUtils.debug(log, "event", "this is debug {}", "arg1"); + assertEquals("[event] msg=this is debug arg1", testLogAppender.getLastMessage()); - LogUtils.debug(log, "event", "this is debug {} {}", "info1", "info2"); - assertEquals("[event] msg=this is debug info1 info2", testLogAppender.getLastMessage()); + LogUtils.debug(log, "event", "this is debug {} {}", "arg1", "arg2"); + assertEquals("[event] msg=this is debug arg1 arg2", testLogAppender.getLastMessage()); - LogUtils.debug(log, "event", "this is debug {} {}", "info1", "info2", new ClassNotFoundException("com.abc")); - assertEquals("[event] msg=this is debug info1 info2", testLogAppender.getLastMessage()); + LogUtils.debug(log, "event", "this is debug {} {}", "arg1", "arg2", new ClassNotFoundException("com.abc")); + assertEquals("[event] msg=this is debug arg1 arg2", testLogAppender.getLastMessage()); assertEquals("com.abc", testLogAppender.getLastEvent().getThrowableProxy().getMessage()); - LogUtils.debug(log, "event", "this is error {}", "error1", new Error("com.def")); - assertEquals("[event] msg=this is error error1", testLogAppender.getLastMessage()); + LogUtils.debug(log, "event", "this is debug {}", "arg1", new Error("com.def")); + assertEquals("[event] msg=this is debug arg1", testLogAppender.getLastMessage()); + assertEquals("com.def", testLogAppender.getLastEvent().getThrowableProxy().getMessage()); + + LogUtils.debug(log, "event", "this is debug", new Exception("com.def")); + assertEquals("[event] msg=this is debug", testLogAppender.getLastMessage()); assertEquals("com.def", testLogAppender.getLastEvent().getThrowableProxy().getMessage()); } @@ -83,18 +91,22 @@ public void error() { LogUtils.error(log, "event", "this is error"); assertEquals("[event] msg=this is error", testLogAppender.getLastMessage()); - LogUtils.error(log, "event", "this is error {}", "info1"); - assertEquals("[event] msg=this is error info1", testLogAppender.getLastMessage()); + LogUtils.error(log, "event", "this is error {}", "arg1"); + assertEquals("[event] msg=this is error arg1", testLogAppender.getLastMessage()); - LogUtils.error(log, "event", "this is error {} {}", "info1", "info2"); - assertEquals("[event] msg=this is error info1 info2", testLogAppender.getLastMessage()); + LogUtils.error(log, "event", "this is error {} {}", "arg1", "arg2"); + assertEquals("[event] msg=this is error arg1 arg2", testLogAppender.getLastMessage()); - LogUtils.error(log, "event", "this is error {} {}", "info1", "info2", new ClassNotFoundException("com.abc")); - assertEquals("[event] msg=this is error info1 info2", testLogAppender.getLastMessage()); + LogUtils.error(log, "event", "this is error {} {}", "arg1", "arg2", new ClassNotFoundException("com.abc")); + assertEquals("[event] msg=this is error arg1 arg2", testLogAppender.getLastMessage()); assertEquals("com.abc", testLogAppender.getLastEvent().getThrowableProxy().getMessage()); - LogUtils.error(log, "event", "this is error {}", "error1", new Error("com.def")); - assertEquals("[event] msg=this is error error1", testLogAppender.getLastMessage()); + LogUtils.error(log, "event", "this is error {}", "arg1", new Error("com.def")); + assertEquals("[event] msg=this is error arg1", testLogAppender.getLastMessage()); + assertEquals("com.def", testLogAppender.getLastEvent().getThrowableProxy().getMessage()); + + LogUtils.error(log, "event", "this is error", new Exception("com.def")); + assertEquals("[event] msg=this is error", testLogAppender.getLastMessage()); assertEquals("com.def", testLogAppender.getLastEvent().getThrowableProxy().getMessage()); } @@ -103,18 +115,22 @@ public void warn() { LogUtils.warn(log, "event", "this is warn"); assertEquals("[event] msg=this is warn", testLogAppender.getLastMessage()); - LogUtils.warn(log, "event", "this is warn {}", "info1"); - assertEquals("[event] msg=this is warn info1", testLogAppender.getLastMessage()); + LogUtils.warn(log, "event", "this is warn {}", "arg1"); + assertEquals("[event] msg=this is warn arg1", testLogAppender.getLastMessage()); - LogUtils.warn(log, "event", "this is warn {} {}", "info1", "info2"); - assertEquals("[event] msg=this is warn info1 info2", testLogAppender.getLastMessage()); + LogUtils.warn(log, "event", "this is warn {} {}", "arg1", "arg2"); + assertEquals("[event] msg=this is warn arg1 arg2", testLogAppender.getLastMessage()); - LogUtils.warn(log, "event", "this is warn {} {}", "info1", "info2", new ClassNotFoundException("com.abc")); - assertEquals("[event] msg=this is warn info1 info2", testLogAppender.getLastMessage()); + LogUtils.warn(log, "event", "this is warn {} {}", "arg1", "arg2", new ClassNotFoundException("com.abc")); + assertEquals("[event] msg=this is warn arg1 arg2", testLogAppender.getLastMessage()); assertEquals("com.abc", testLogAppender.getLastEvent().getThrowableProxy().getMessage()); - LogUtils.warn(log, "event", "this is warn {}", "error1", new Error("com.def")); - assertEquals("[event] msg=this is warn error1", testLogAppender.getLastMessage()); + LogUtils.warn(log, "event", "this is warn {}", "arg1", new Error("com.def")); + assertEquals("[event] msg=this is warn arg1", testLogAppender.getLastMessage()); + assertEquals("com.def", testLogAppender.getLastEvent().getThrowableProxy().getMessage()); + + LogUtils.warn(log, "event", "this is warn", new Exception("com.def")); + assertEquals("[event] msg=this is warn", testLogAppender.getLastMessage()); assertEquals("com.def", testLogAppender.getLastEvent().getThrowableProxy().getMessage()); } diff --git a/saturn-core/src/test/resources/logback-test.xml b/saturn-core/src/test/resources/logback-test.xml index 9468421ff..5ca9508bd 100644 --- a/saturn-core/src/test/resources/logback-test.xml +++ b/saturn-core/src/test/resources/logback-test.xml @@ -13,7 +13,7 @@ - +