AndroidLoggerFactoryTest xref

View Javadoc

    1   /*
    2    * Copyright (c) 2004-2013 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.impl;
    26
    27  import org.junit.Test;
    28
    29  import static org.junit.Assert.assertEquals;
    30
    31  public class AndroidLoggerFactoryTest {
    32      @Test
    33      public void shortLoggerNames() {
    34          assertEquals("o.test.p.TestClass", AndroidLoggerFactory.loggerNameToTag("o.test.p.TestClass"));
    35          assertEquals("ex.test.TestClass", AndroidLoggerFactory.loggerNameToTag("ex.test.TestClass"));
    36          assertEquals("MyClass", AndroidLoggerFactory.loggerNameToTag("MyClass"));
    37      }
    38
    39      @Test
    40      public void emptyLoggerNames() {
    41          assertEquals(AndroidLoggerFactory.ANONYMOUS_TAG, AndroidLoggerFactory.loggerNameToTag(null));
    42          assertEquals("", AndroidLoggerFactory.loggerNameToTag(""));
    43      }
    44
    45      @Test
    46      public void simpleLoggerName() {
    47          assertEquals("o*.t*.p*.TestClass", AndroidLoggerFactory.loggerNameToTag("org.test.package.TestClass"));
    48      }
    49
    50      @Test
    51      public void loggerNameWithOneCharPackage() {
    52          assertEquals("o.t*.p*.p*.TestClass", AndroidLoggerFactory.loggerNameToTag("o.test.project.package.TestClass"));
    53          assertEquals("o.t*.p*.p.TestClass", AndroidLoggerFactory.loggerNameToTag("o.test.project.p.TestClass"));
    54      }
    55
    56      @Test
    57      public void longLoggerName() {
    58          assertEquals("AndroidLoggerFactory", AndroidLoggerFactory.loggerNameToTag("org.slf4j.impl.AndroidLoggerFactory"));
    59      }
    60
    61      @Test
    62      public void veryLongLoggerName() {
    63          assertEquals("*meAndShouldBeTruncated", AndroidLoggerFactory.loggerNameToTag("IAmAVeryLongLoggerNameAndShouldBeTruncated"));
    64      }
    65
    66      @Test
    67      public void oneWordLoggerName() {
    68          assertEquals("TestClass", AndroidLoggerFactory.loggerNameToTag("TestClass"));
    69      }
    70
    71      @Test
    72      public void weirdLoggerNames() {
    73          assertEquals("WeirdLoggerName.", AndroidLoggerFactory.loggerNameToTag("WeirdLoggerName."));
    74          assertEquals(".WeirdLoggerName", AndroidLoggerFactory.loggerNameToTag(".WeirdLoggerName"));
    75          assertEquals(".WeirdLoggerName.", AndroidLoggerFactory.loggerNameToTag(".WeirdLoggerName."));
    76          assertEquals(".", AndroidLoggerFactory.loggerNameToTag("."));
    77          assertEquals("..", AndroidLoggerFactory.loggerNameToTag(".."));
    78      }
    79  }