1 /**
2 * Copyright (c) 2004-2011 QOS.ch
3 * All rights reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 *
24 */
25 package org.slf4j.migrator.line;
26
27 import org.slf4j.migrator.line.JCLRuleSet;
28 import org.slf4j.migrator.line.LineConverter;
29 import org.slf4j.migrator.line.Log4jRuleSet;
30
31 import junit.framework.TestCase;
32
33 public class NoConversionTest extends TestCase {
34
35 /**
36 * This test shows that performing JCL to SLF4J conversion has no impact on
37 * Log4j implementation
38 */
39 public void testJclOverLog4jConversion() {
40 // running jcl to slf4j conversion
41 //JCLMatcher jclMatcher =
42 LineConverter jclLineConverter = new LineConverter(new JCLRuleSet());
43 // no changes on log4j.LogManager import
44 assertEquals("import org.apache.log4j.LogManager;", jclLineConverter
45 .getOneLineReplacement("import org.apache.log4j.LogManager;"));
46 // no changes on log4j.Logger import
47 assertEquals("import org.apache.log4j.Logger;", jclLineConverter
48 .getOneLineReplacement("import org.apache.log4j.Logger;"));
49 // no changes on Logger instanciation using LogManager
50 assertEquals(
51 "Logger log = LogManager.getLogger(MyClass.class);",
52 jclLineConverter
53 .getOneLineReplacement("Logger log = LogManager.getLogger(MyClass.class);"));
54 // no changes on Logger instanciation using Logger.getLogger
55 assertEquals(
56 "public static Logger mylog1 = Logger.getLogger(MyClass.class);",
57 jclLineConverter
58 .getOneLineReplacement("public static Logger mylog1 = Logger.getLogger(MyClass.class);"));
59 }
60
61 /**
62 * This test shows that performing Log4j to SLF4J conversion has no impact on
63 * JCL implementation
64 */
65 public void testLog4jOverJclConversion() {
66 // running log4j to slf4j conversion
67 LineConverter log4jConverter = new LineConverter(new Log4jRuleSet());
68
69 // no changes on LogFactory import
70 assertEquals("import org.apache.commons.logging.LogFactory;", log4jConverter
71 .getOneLineReplacement("import org.apache.commons.logging.LogFactory;"));
72 // no changes on Log import
73 assertEquals("import org.apache.commons.logging.Log;", log4jConverter
74 .getOneLineReplacement("import org.apache.commons.logging.Log;"));
75 // no changes on Log instanciation using Logfactory.getLog
76 assertEquals(
77 "public static Log mylog1 = LogFactory.getLog(MyClass.class);",
78 log4jConverter
79 .getOneLineReplacement("public static Log mylog1 = LogFactory.getLog(MyClass.class);"));
80 // no changes on log instanciation using LogFactory.getFactory().getInstance
81 assertEquals(
82 "public Log mylog=LogFactory.getFactory().getInstance(MyClass.class);",
83 log4jConverter
84 .getOneLineReplacement("public Log mylog=LogFactory.getFactory().getInstance(MyClass.class);"));
85
86 }
87 }