⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 log4jrulesettest.java

📁 Java开发最新的日志记录工具slf4j的源码
💻 JAVA
字号:
package org.slf4j.migrator.line;import java.util.Arrays;import org.slf4j.migrator.line.LineConverter;import org.slf4j.migrator.line.Log4jRuleSet;import junit.framework.TestCase;public class Log4jRuleSetTest extends TestCase {  LineConverter log4jConverter = new LineConverter(new Log4jRuleSet());    public void testImportReplacement() {    // LogFactory import replacement    assertEquals("import org.slf4j.LoggerFactory;", log4jConverter        .getOneLineReplacement("import org.apache.log4j.LogManager;"));    // Log import replacement    assertTrue(Arrays.equals(         new String[] {"import org.slf4j.Logger;", "import org.slf4j.LoggerFactory;" },        log4jConverter.getReplacement("import org.apache.log4j.Logger;")));  }  public void testLogManagerGetLoggerReplacement() {    // Logger declaration and instanciation without modifier    assertEquals(" Logger l = LoggerFactory.getLogger(MyClass.class);",        log4jConverter            .getOneLineReplacement(" Logger l = LogManager.getLogger(MyClass.class);"));    // Logger declaration and instanciation with one modifier    assertEquals(        "public Logger mylog=LoggerFactory.getLogger(MyClass.class);",        log4jConverter            .getOneLineReplacement("public Logger mylog=LogManager.getLogger(MyClass.class);"));    // Logger declaration and instanciation with two modifier    assertEquals(        "public static Logger mylog1 = LoggerFactory.getLogger(MyClass.class);",        log4jConverter            .getOneLineReplacement("public static Logger mylog1 = LogManager.getLogger(MyClass.class);"));    // Logger declaration and instanciation with two modifier and comment at the    // end of line    assertEquals(        "public static Logger mylog1 = LoggerFactory.getLogger(MyClass.class);//logger instanciation and declaration",        log4jConverter            .getOneLineReplacement("public static Logger mylog1 = LogManager.getLogger(MyClass.class);//logger instanciation and declaration"));    // Logger instanciation without declaration and comment at the end of line    assertEquals(        " myLog = LoggerFactory.getLogger(MyClass.class);//logger instanciation",        log4jConverter            .getOneLineReplacement(" myLog = LogManager.getLogger(MyClass.class);//logger instanciation"));    // commented Logger declaration and instanciation with two modifier    assertEquals(        "//public static Logger mylog1 = LoggerFactory.getLogger(MyClass.class);",        log4jConverter            .getOneLineReplacement("//public static Logger mylog1 = LogManager.getLogger(MyClass.class);"));    // commented Logger instanciation without declaration    assertEquals(        "// myLog = LoggerFactory.getLogger(MyClass.class);//logger instanciation",        log4jConverter            .getOneLineReplacement("// myLog = LogManager.getLogger(MyClass.class);//logger instanciation"));  }  public void testLoggerGetLoggerReplacement() {    // Logger declaration and instanciation without modifier    assertEquals("Logger l = LoggerFactory.getLogger(MyClass.class);",        log4jConverter            .getOneLineReplacement("Logger l = Logger.getLogger(MyClass.class);"));    // Logger declaration and instanciation with one modifier    assertEquals(        "public Logger mylog=LoggerFactory.getLogger(MyClass.class);",        log4jConverter            .getOneLineReplacement("public Logger mylog=Logger.getLogger(MyClass.class);"));    // Logger declaration and instanciation with modifiers    assertEquals(        "public static Logger mylog1 = LoggerFactory.getLogger(MyClass.class);",        log4jConverter            .getOneLineReplacement("public static Logger mylog1 = Logger.getLogger(MyClass.class);"));    // Logger declaration and instanciation with two modifier and comment at the    // end of line    assertEquals(        "public static Logger mylog1 = LoggerFactory.getLogger(MyClass.class); // logger instanciation and declaration",        log4jConverter            .getOneLineReplacement("public static Logger mylog1 = Logger.getLogger(MyClass.class); // logger instanciation and declaration"));    // Logger instanciation without declaration and comment at the end of line    assertEquals(        " myLog = LoggerFactory.getLogger(MyClass.class);//logger instanciation",        log4jConverter            .getOneLineReplacement(" myLog = Logger.getLogger(MyClass.class);//logger instanciation"));    // commented Logger declaration and instanciation with two modifier    assertEquals(        "//public static Logger mylog1 = LoggerFactory.getLogger(MyClass.class);",        log4jConverter            .getOneLineReplacement("//public static Logger mylog1 = Logger.getLogger(MyClass.class);"));    // commented Logger instanciation without declaration    assertEquals(        "// myLog = LoggerFactory.getLogger(MyClass.class);//logger instanciation",        log4jConverter            .getOneLineReplacement("// myLog = Logger.getLogger(MyClass.class);//logger instanciation"));  }  public void testLogDeclarationReplacement() {    // simple Logger declaration    assertEquals("Logger mylog;", log4jConverter.getOneLineReplacement("Logger mylog;"));    // Logger declaration with a modifier    assertEquals("private Logger mylog;", log4jConverter        .getOneLineReplacement("private Logger mylog;"));    // Logger declaration with modifiers    assertEquals("public static final Logger myLog;", log4jConverter        .getOneLineReplacement("public static final Logger myLog;"));    // Logger declaration with modifiers and comment at the end of line    assertEquals("public Logger myLog;//logger declaration", log4jConverter        .getOneLineReplacement("public Logger myLog;//logger declaration"));    // commented Logger declaration    assertEquals("//private Logger myLog;", log4jConverter        .getOneLineReplacement("//private Logger myLog;"));  }  public void testMultiLineReplacement()  {   // Logger declaration on a line   assertEquals("protected Logger log =", log4jConverter   .getOneLineReplacement("protected Logger log ="));       // Logger instanciation on the next line   assertEquals(" LoggerFactory.getLogger(MyComponent.class);", log4jConverter   .getOneLineReplacement(" LogManager.getLogger(MyComponent.class);"));   // Logger declaration on a line   assertEquals("protected Logger log ", log4jConverter   .getOneLineReplacement("protected Logger log "));   // Logger instanciation on the next line   assertEquals(   " = LoggerFactory.getLogger(MyComponent.class);",   log4jConverter   .getOneLineReplacement(" = LogManager.getLogger(MyComponent.class);"));   }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -