Ceki Gulcu | 7ba0605 | 2011-10-16 10:28:44 +0200 | [diff] [blame] | 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 | */ |
Ceki Gulcu | ac39cd5 | 2008-02-21 18:58:13 +0000 | [diff] [blame] | 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 | |
Ceki Gulcu | 3121243 | 2015-03-26 12:59:25 +0100 | [diff] [blame^] | 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.getOneLineReplacement("import org.apache.log4j.LogManager;")); |
| 45 | // no changes on log4j.Logger import |
| 46 | assertEquals("import org.apache.log4j.Logger;", jclLineConverter.getOneLineReplacement("import org.apache.log4j.Logger;")); |
| 47 | // no changes on Logger instanciation using LogManager |
| 48 | assertEquals("Logger log = LogManager.getLogger(MyClass.class);", |
| 49 | jclLineConverter.getOneLineReplacement("Logger log = LogManager.getLogger(MyClass.class);")); |
| 50 | // no changes on Logger instanciation using Logger.getLogger |
| 51 | assertEquals("public static Logger mylog1 = Logger.getLogger(MyClass.class);", |
| 52 | jclLineConverter.getOneLineReplacement("public static Logger mylog1 = Logger.getLogger(MyClass.class);")); |
| 53 | } |
Ceki Gulcu | ac39cd5 | 2008-02-21 18:58:13 +0000 | [diff] [blame] | 54 | |
Ceki Gulcu | 3121243 | 2015-03-26 12:59:25 +0100 | [diff] [blame^] | 55 | /** |
| 56 | * This test shows that performing Log4j to SLF4J conversion has no impact on |
| 57 | * JCL implementation |
| 58 | */ |
| 59 | public void testLog4jOverJclConversion() { |
| 60 | // running log4j to slf4j conversion |
| 61 | LineConverter log4jConverter = new LineConverter(new Log4jRuleSet()); |
Ceki Gulcu | ac39cd5 | 2008-02-21 18:58:13 +0000 | [diff] [blame] | 62 | |
Ceki Gulcu | 3121243 | 2015-03-26 12:59:25 +0100 | [diff] [blame^] | 63 | // no changes on LogFactory import |
| 64 | assertEquals("import org.apache.commons.logging.LogFactory;", log4jConverter.getOneLineReplacement("import org.apache.commons.logging.LogFactory;")); |
| 65 | // no changes on Log import |
| 66 | assertEquals("import org.apache.commons.logging.Log;", log4jConverter.getOneLineReplacement("import org.apache.commons.logging.Log;")); |
| 67 | // no changes on Log instanciation using Logfactory.getLog |
| 68 | assertEquals("public static Log mylog1 = LogFactory.getLog(MyClass.class);", |
| 69 | log4jConverter.getOneLineReplacement("public static Log mylog1 = LogFactory.getLog(MyClass.class);")); |
| 70 | // no changes on log instanciation using LogFactory.getFactory().getInstance |
| 71 | assertEquals("public Log mylog=LogFactory.getFactory().getInstance(MyClass.class);", |
| 72 | log4jConverter.getOneLineReplacement("public Log mylog=LogFactory.getFactory().getInstance(MyClass.class);")); |
| 73 | |
| 74 | } |
Ceki Gulcu | ac39cd5 | 2008-02-21 18:58:13 +0000 | [diff] [blame] | 75 | } |