[slf4j-dev] svn commit: r892 - slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter
ceki at slf4j.org
ceki at slf4j.org
Wed Sep 12 22:41:01 CEST 2007
Author: ceki
Date: Wed Sep 12 22:41:00 2007
New Revision: 892
Added:
slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/AternativeApproach.java
Modified:
slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/JCLMatcherTest.java
Log:
- Modified JCLMatcherTest to list the expected value first in all assertions
- An example of an alternative and possibly simpler approach for conversion expressions
Added: slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/AternativeApproach.java
==============================================================================
--- (empty file)
+++ slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/AternativeApproach.java Wed Sep 12 22:41:00 2007
@@ -0,0 +1,48 @@
+package org.slf4j.converter;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import junit.framework.TestCase;
+
+public class AternativeApproach extends TestCase {
+
+ public void test() {
+ MultiGroupConversionRule cr2 = new MultiGroupConversionRule(Pattern
+ .compile("(.*)(Log)"));
+ cr2.addReplacement(2, "LOGGER");
+
+
+ String s = "abcd Log";
+ Pattern pat = cr2.getPattern();
+ Matcher m = pat.matcher(s);
+
+ assertTrue(m.matches());
+ String r = cr2.replace(m);
+ assertEquals("abcd LOGGER", r);
+
+ System.out.println(r);
+ }
+
+
+ public void test2() {
+ Pattern pat = Pattern.compile("Log");
+ String s = "abcd Log";
+ Matcher m = pat.matcher(s);
+ assertTrue(m.find());
+ String r = m.replaceAll("LOGGER");
+ assertEquals("abcd LOGGER", r);
+ }
+
+ public void test3() {
+ Pattern pat = Pattern.compile("LogFactory.getFactory\\(\\).getInstance\\(");
+ String s = "Log log = LogFactory.getFactory().getInstance(\"x\");";
+ Matcher m = pat.matcher(s);
+ assertTrue(m.find());
+ String r = m.replaceAll("LoggerFactory.getLogger(");
+ assertEquals("Log log = LoggerFactory.getLogger(\"x\");", r);
+
+ String nonMatching = "Log log = xxx;";
+ assertFalse(m.find());
+ }
+}
Modified: slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/JCLMatcherTest.java
==============================================================================
--- slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/JCLMatcherTest.java (original)
+++ slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/JCLMatcherTest.java Wed Sep 12 22:41:00 2007
@@ -19,117 +19,116 @@
public void testLogFactoryGetLogReplacement() {
JCLMatcher jclMatcher = new JCLMatcher();
// Logger declaration and instanciation without modifier
- assertEquals(jclMatcher
- .getReplacement("Log l = LogFactory.getLog(MyClass.class);"),
- "Logger l = LoggerFactory.getLogger(MyClass.class);");
+ assertEquals("Logger l = LoggerFactory.getLogger(MyClass.class);",
+ jclMatcher.getReplacement("Log l = LogFactory.getLog(MyClass.class);"));
// Logger declaration and instanciation with one modifier
- assertEquals(jclMatcher
- .getReplacement("public Log mylog=LogFactory.getLog(MyClass.class);"),
- "public Logger mylog=LoggerFactory.getLogger(MyClass.class);");
+ assertEquals(
+ "public Logger mylog=LoggerFactory.getLogger(MyClass.class);",
+ jclMatcher
+ .getReplacement("public Log mylog=LogFactory.getLog(MyClass.class);"));
// Logger declaration and instanciation with two modifier
assertEquals(
+ "public static Logger mylog1 = LoggerFactory.getLogger(MyClass.class);",
jclMatcher
- .getReplacement("public static Log mylog1 = LogFactory.getLog(MyClass.class);"),
- "public static Logger mylog1 = LoggerFactory.getLogger(MyClass.class);");
+ .getReplacement("public static Log mylog1 = LogFactory.getLog(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",
jclMatcher
- .getReplacement("public static Log mylog1 = LogFactory.getLog(MyClass.class); //logger instanciation and declaration"),
- "public static Logger mylog1 = LoggerFactory.getLogger(MyClass.class); //logger instanciation and declaration");
+ .getReplacement("public static Log mylog1 = LogFactory.getLog(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",
jclMatcher
- .getReplacement(" myLog = LogFactory.getLog(MyClass.class);//logger instanciation"),
- " myLog = LoggerFactory.getLogger(MyClass.class);//logger instanciation");
+ .getReplacement(" myLog = LogFactory.getLog(MyClass.class);//logger instanciation"));
// commented Logger declaration and instanciation with two modifier
assertEquals(
+ "//public static Logger mylog1 = LoggerFactory.getLogger(MyClass.class);",
jclMatcher
- .getReplacement("//public static Log mylog1 = LogFactory.getLog(MyClass.class);"),
- "//public static Logger mylog1 = LoggerFactory.getLogger(MyClass.class);");
+ .getReplacement("//public static Log mylog1 = LogFactory.getLog(MyClass.class);"));
// commented Logger instanciation without declaration
assertEquals(
+ "// myLog = LoggerFactory.getLogger(MyClass.class);//logger instanciation",
jclMatcher
- .getReplacement("// myLog = LogFactory.getLog(MyClass.class);//logger instanciation"),
- "// myLog = LoggerFactory.getLogger(MyClass.class);//logger instanciation");
+ .getReplacement("// myLog = LogFactory.getLog(MyClass.class);//logger instanciation"));
}
public void testLogFactoryGetFactoryReplacement() {
JCLMatcher jclMatcher = new JCLMatcher();
// Logger declaration and instanciation without modifier
assertEquals(
+ "Logger l = LoggerFactory.getLogger(MyClass.class);",
jclMatcher
- .getReplacement("Log l = LogFactory.getFactory().getInstance(MyClass.class);"),
- "Logger l = LoggerFactory.getLogger(MyClass.class);");
+ .getReplacement("Log l = LogFactory.getFactory().getInstance(MyClass.class);"));
// Logger declaration and instanciation with one modifier
assertEquals(
+ "public Logger mylog=LoggerFactory.getLogger(MyClass.class);",
jclMatcher
- .getReplacement("public Log mylog=LogFactory.getFactory().getInstance(MyClass.class);"),
- "public Logger mylog=LoggerFactory.getLogger(MyClass.class);");
+ .getReplacement("public Log mylog=LogFactory.getFactory().getInstance(MyClass.class);"));
// Logger declaration and instanciation with modifiers
assertEquals(
+ "public static Logger mylog1 = LoggerFactory.getLogger(MyClass.class);",
jclMatcher
- .getReplacement("public static Log mylog1 = LogFactory.getFactory().getInstance(MyClass.class);"),
- "public static Logger mylog1 = LoggerFactory.getLogger(MyClass.class);");
+ .getReplacement("public static Log mylog1 = LogFactory.getFactory().getInstance(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",
jclMatcher
- .getReplacement("public static Log mylog1 = LogFactory.getFactory().getInstance(MyClass.class); //logger instanciation and declaration"),
- "public static Logger mylog1 = LoggerFactory.getLogger(MyClass.class); //logger instanciation and declaration");
+ .getReplacement("public static Log mylog1 = LogFactory.getFactory().getInstance(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",
jclMatcher
- .getReplacement(" myLog = LogFactory.getFactory().getInstance(MyClass.class);//logger instanciation"),
- " myLog = LoggerFactory.getLogger(MyClass.class);//logger instanciation");
+ .getReplacement(" myLog = LogFactory.getFactory().getInstance(MyClass.class);//logger instanciation"));
// commented Logger declaration and instanciation with two modifier
assertEquals(
+ "//public static Logger mylog1 = LoggerFactory.getLogger(MyClass.class);",
jclMatcher
- .getReplacement("//public static Log mylog1 = LogFactory.getFactory().getInstance(MyClass.class);"),
- "//public static Logger mylog1 = LoggerFactory.getLogger(MyClass.class);");
+ .getReplacement("//public static Log mylog1 = LogFactory.getFactory().getInstance(MyClass.class);"));
// commented Logger instanciation without declaration
assertEquals(
+ "// myLog = LoggerFactory.getLogger(MyClass.class);//logger instanciation",
jclMatcher
- .getReplacement("// myLog = LogFactory.getFactory().getInstance(MyClass.class);//logger instanciation"),
- "// myLog = LoggerFactory.getLogger(MyClass.class);//logger instanciation");
+ .getReplacement("// myLog = LogFactory.getFactory().getInstance(MyClass.class);//logger instanciation"));
}
public void testLogDeclarationReplacement() throws IOException {
JCLMatcher jclMatcher = new JCLMatcher();
// simple Logger declaration
- assertEquals(jclMatcher.getReplacement("Log mylog;"), "Logger mylog;");
+ assertEquals("Logger mylog;", jclMatcher.getReplacement("Log mylog;"));
// Logger declaration with a modifier
- assertEquals(jclMatcher.getReplacement("private Log mylog;"),
- "private Logger mylog;");
+ assertEquals("private Logger mylog;", jclMatcher
+ .getReplacement("private Log mylog;"));
+
// Logger declaration with modifiers
- assertEquals(jclMatcher.getReplacement("public static final Log myLog;"),
- "public static final Logger myLog;");
+ assertEquals("public static final Logger myLog;", jclMatcher
+ .getReplacement("public static final Log myLog;"));
// Logger declaration with modifiers and comment at the end of line
- assertEquals(jclMatcher
- .getReplacement("public Log myLog;//logger declaration"),
- "public Logger myLog;//logger declaration");
+ assertEquals("public Logger myLog;//logger declaration", jclMatcher
+ .getReplacement("public Log myLog;//logger declaration"));
// commented Logger declaration
- assertEquals(jclMatcher.getReplacement("//private Log myLog;"),
- "//private Logger myLog;");
+ assertEquals("//private Logger myLog;", jclMatcher
+ .getReplacement("//private Log myLog;"));
}
public void testMultiLineReplacement() throws IOException {
JCLMatcher jclMatcher = new JCLMatcher();
// Logger declaration on a line
- assertEquals(jclMatcher.getReplacement("protected Log log ="),
- "protected Logger log =");
+ assertEquals("protected Logger log =", jclMatcher
+ .getReplacement("protected Log log ="));
+
// Logger instanciation on the next line
- assertEquals(jclMatcher
- .getReplacement(" LogFactory.getLog(MyComponent.class);"),
- " LoggerFactory.getLogger(MyComponent.class);");
+ assertEquals(" LoggerFactory.getLogger(MyComponent.class);", jclMatcher
+ .getReplacement(" LogFactory.getLog(MyComponent.class);"));
// Logger declaration on a line
- assertEquals(jclMatcher.getReplacement("protected Log log "),
- "protected Logger log ");
+ assertEquals("protected Logger log ", jclMatcher
+ .getReplacement("protected Log log "));
// Logger instanciation on the next line
assertEquals(
+ " = LoggerFactory.getLogger(MyComponent.class);",
jclMatcher
- .getReplacement(" = LogFactory.getFactory().getInstance(MyComponent.class);"),
- " = LoggerFactory.getLogger(MyComponent.class);");
+ .getReplacement(" = LogFactory.getFactory().getInstance(MyComponent.class);"));
}
-
}
More information about the slf4j-dev
mailing list