001: package org.slf4j.migrator.line;
002:
003: import org.slf4j.migrator.line.JCLRuleSet;
004: import org.slf4j.migrator.line.LineConverter;
005:
006: import junit.framework.TestCase;
007:
008: public class JCLRuleSetTest extends TestCase {
009:
010: LineConverter jclConverter = new LineConverter(new JCLRuleSet());
011:
012: public void testImportReplacement() {
013: // LogFactory import replacement
014: assertEquals(
015: "import org.slf4j.LoggerFactory;",
016: jclConverter
017: .getOneLineReplacement("import org.apache.commons.logging.LogFactory;"));
018: // Log import replacement
019: assertEquals(
020: "import org.slf4j.Logger;",
021: jclConverter
022: .getOneLineReplacement("import org.apache.commons.logging.Log;"));
023: }
024:
025: public void testLogFactoryGetLogReplacement() {
026: // Logger declaration and instanciation without modifier
027: assertEquals(
028: " Logger l = LoggerFactory.getLogger(MyClass.class);",
029: jclConverter
030: .getOneLineReplacement(" Log l = LogFactory.getLog(MyClass.class);"));
031: // Logger declaration and instanciation with one modifier
032: assertEquals(
033: "public Logger mylog=LoggerFactory.getLogger(MyClass.class);",
034: jclConverter
035: .getOneLineReplacement("public Log mylog=LogFactory.getLog(MyClass.class);"));
036: // Logger declaration and instanciation with two modifier
037: assertEquals(
038: "public static Logger mylog1 = LoggerFactory.getLogger(MyClass.class);",
039: jclConverter
040: .getOneLineReplacement("public static Log mylog1 = LogFactory.getLog(MyClass.class);"));
041: // Logger declaration and instanciation with two modifier and comment at the
042: // end of line
043: assertEquals(
044: "public static Logger mylog1 = LoggerFactory.getLogger(MyClass.class); //logger instanciation and declaration",
045: jclConverter
046: .getOneLineReplacement("public static Log mylog1 = LogFactory.getLog(MyClass.class); //logger instanciation and declaration"));
047: // Logger instanciation without declaration and comment at the end of line
048: assertEquals(
049: " myLog = LoggerFactory.getLogger(MyClass.class);//logger instanciation",
050: jclConverter
051: .getOneLineReplacement(" myLog = LogFactory.getLog(MyClass.class);//logger instanciation"));
052: // commented Logger declaration and instanciation with two modifier
053: assertEquals(
054: "//public static Logger mylog1 = LoggerFactory.getLogger(MyClass.class);",
055: jclConverter
056: .getOneLineReplacement("//public static Log mylog1 = LogFactory.getLog(MyClass.class);"));
057: // commented Logger instanciation without declaration
058: assertEquals(
059: "// myLog = LoggerFactory.getLogger(MyClass.class);//logger instanciation",
060: jclConverter
061: .getOneLineReplacement("// myLog = LogFactory.getLog(MyClass.class);//logger instanciation"));
062: }
063:
064: public void testLogFactoryGetFactoryReplacement() {
065:
066: // Logger declaration and instanciation without modifier
067: assertEquals(
068: "Logger l = LoggerFactory.getLogger(MyClass.class);",
069: jclConverter
070: .getOneLineReplacement("Log l = LogFactory.getFactory().getInstance(MyClass.class);"));
071: // Logger declaration and instanciation with one modifier
072: assertEquals(
073: "public Logger mylog=LoggerFactory.getLogger(MyClass.class);",
074: jclConverter
075: .getOneLineReplacement("public Log mylog=LogFactory.getFactory().getInstance(MyClass.class);"));
076: // Logger declaration and instanciation with modifiers
077: assertEquals(
078: "public static Logger mylog1 = LoggerFactory.getLogger(MyClass.class);",
079: jclConverter
080: .getOneLineReplacement("public static Log mylog1 = LogFactory.getFactory().getInstance(MyClass.class);"));
081: // Logger declaration and instanciation with two modifier and comment at the
082: // end of line
083: assertEquals(
084: "public static Logger mylog1 = LoggerFactory.getLogger(MyClass.class); //logger instanciation and declaration",
085: jclConverter
086: .getOneLineReplacement("public static Log mylog1 = LogFactory.getFactory().getInstance(MyClass.class); //logger instanciation and declaration"));
087: // Logger instanciation without declaration and comment at the end of line
088: assertEquals(
089: " myLog = LoggerFactory.getLogger(MyClass.class);//logger instanciation",
090: jclConverter
091: .getOneLineReplacement(" myLog = LogFactory.getFactory().getInstance(MyClass.class);//logger instanciation"));
092: // commented Logger declaration and instanciation with two modifier
093: assertEquals(
094: "//public static Logger mylog1 = LoggerFactory.getLogger(MyClass.class);",
095: jclConverter
096: .getOneLineReplacement("//public static Log mylog1 = LogFactory.getFactory().getInstance(MyClass.class);"));
097: // commented Logger instanciation without declaration
098: assertEquals(
099: "// myLog = LoggerFactory.getLogger(MyClass.class);//logger instanciation",
100: jclConverter
101: .getOneLineReplacement("// myLog = LogFactory.getFactory().getInstance(MyClass.class);//logger instanciation"));
102: }
103:
104: public void testLogDeclarationReplacement() {
105:
106: // simple Logger declaration
107: assertEquals("Logger mylog;", jclConverter
108: .getOneLineReplacement("Log mylog;"));
109: // Logger declaration with a modifier
110: assertEquals("private Logger mylog;", jclConverter
111: .getOneLineReplacement("private Log mylog;"));
112:
113: // Logger declaration with modifiers
114: assertEquals(
115: "public static final Logger myLog;",
116: jclConverter
117: .getOneLineReplacement("public static final Log myLog;"));
118: // Logger declaration with modifiers and comment at the end of line
119: assertEquals(
120: "public Logger myLog;//logger declaration",
121: jclConverter
122: .getOneLineReplacement("public Log myLog;//logger declaration"));
123: // commented Logger declaration
124: assertEquals("//private Logger myLog;", jclConverter
125: .getOneLineReplacement("//private Log myLog;"));
126: }
127:
128: public void testMultiLineReplacement() {
129: // Logger declaration on a line
130: assertEquals("protected Logger log =", jclConverter
131: .getOneLineReplacement("protected Log log ="));
132:
133: // Logger instanciation on the next line
134: assertEquals(
135: " LoggerFactory.getLogger(MyComponent.class);",
136: jclConverter
137: .getOneLineReplacement(" LogFactory.getLog(MyComponent.class);"));
138: // Logger declaration on a line
139: assertEquals("protected Logger log ", jclConverter
140: .getOneLineReplacement("protected Log log "));
141: // Logger instanciation on the next line
142: assertEquals(
143: " = LoggerFactory.getLogger(MyComponent.class);",
144: jclConverter
145: .getOneLineReplacement(" = LogFactory.getFactory().getInstance(MyComponent.class);"));
146: }
147: }
|