NoConversionTest xref

View Javadoc

    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 static org.junit.Assert.assertEquals;
    28
    29  import org.junit.Test;
    30
    31  public class NoConversionTest {
    32
    33      /**
    34       * This test shows that performing JCL to SLF4J conversion has no impact on
    35       * Log4j implementation
    36       */
    37      @Test
    38      public void testJclOverLog4jConversion() {
    39          // running jcl to slf4j conversion
    40          // JCLMatcher jclMatcher =
    41          LineConverter jclLineConverter = new LineConverter(new JCLRuleSet());
    42          // no changes on log4j.LogManager import
    43          assertEquals("import org.apache.log4j.LogManager;", jclLineConverter.getOneLineReplacement("import org.apache.log4j.LogManager;"));
    44          // no changes on log4j.Logger import
    45          assertEquals("import org.apache.log4j.Logger;", jclLineConverter.getOneLineReplacement("import org.apache.log4j.Logger;"));
    46          // no changes on Logger instanciation using LogManager
    47          assertEquals("Logger log = LogManager.getLogger(MyClass.class);",
    48                          jclLineConverter.getOneLineReplacement("Logger log = LogManager.getLogger(MyClass.class);"));
    49          // no changes on Logger instanciation using Logger.getLogger
    50          assertEquals("public static Logger mylog1 = Logger.getLogger(MyClass.class);",
    51                          jclLineConverter.getOneLineReplacement("public static Logger mylog1 = Logger.getLogger(MyClass.class);"));
    52      }
    53
    54      /**
    55       * This test shows that performing Log4j to SLF4J conversion has no impact on
    56       * JCL implementation
    57       */
    58      @Test
    59      public void testLog4jOverJclConversion() {
    60          // running log4j to slf4j conversion
    61          LineConverter log4jConverter = new LineConverter(new Log4jRuleSet());
    62
    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      }
    75  }