001/**
002 * Logback: the reliable, generic, fast and flexible logging framework.
003 * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
004 *
005 * This program and the accompanying materials are dual-licensed under
006 * either the terms of the Eclipse Public License v1.0 as published by
007 * the Eclipse Foundation
008 *
009 *   or (per the licensee's choosing)
010 *
011 * under the terms of the GNU Lesser General Public License version 2.1
012 * as published by the Free Software Foundation.
013 */
014package ch.qos.logback.classic.util;
015
016import org.junit.Test;
017
018import java.util.ArrayList;
019import java.util.List;
020
021import static org.junit.Assert.assertEquals;
022
023public class LoggerNameUtilTest {
024
025    @Test
026    public void smoke0() {
027        List<String> witnessList = new ArrayList<String>();
028        witnessList.add("a");
029        witnessList.add("b");
030        witnessList.add("c");
031        List<String> partList = LoggerNameUtil.computeNameParts("a.b.c");
032        assertEquals(witnessList, partList);
033    }
034
035    @Test
036    public void smoke1() {
037        List<String> witnessList = new ArrayList<String>();
038        witnessList.add("com");
039        witnessList.add("foo");
040        witnessList.add("Bar");
041        List<String> partList = LoggerNameUtil.computeNameParts("com.foo.Bar");
042        assertEquals(witnessList, partList);
043    }
044
045    @Test
046    public void emptyStringShouldReturnAListContainingOneEmptyString() {
047        List<String> witnessList = new ArrayList<String>();
048        witnessList.add("");
049        List<String> partList = LoggerNameUtil.computeNameParts("");
050        assertEquals(witnessList, partList);
051    }
052
053    @Test
054    public void dotAtLastPositionShouldReturnAListWithAnEmptyStringAsLastElement() {
055        List<String> witnessList = new ArrayList<String>();
056        witnessList.add("com");
057        witnessList.add("foo");
058        witnessList.add("");
059
060        List<String> partList = LoggerNameUtil.computeNameParts("com.foo.");
061        assertEquals(witnessList, partList);
062    }
063
064    @Test
065    public void supportNestedClasses() {
066        List<String> witnessList = new ArrayList<String>();
067        witnessList.add("com");
068        witnessList.add("foo");
069        witnessList.add("Bar");
070        witnessList.add("Nested");
071
072        List<String> partList = LoggerNameUtil.computeNameParts("com.foo.Bar$Nested");
073        assertEquals(witnessList, partList);
074    }
075
076    @Test
077    public void supportNestedClassesWithNestedDot() {
078        // LOGBACK-384
079        List<String> witnessList = new ArrayList<String>();
080        witnessList.add("com");
081        witnessList.add("foo");
082        witnessList.add("Bar");
083        witnessList.add("Nested");
084        witnessList.add("dot");
085
086        List<String> partList = LoggerNameUtil.computeNameParts("com.foo.Bar$Nested.dot");
087        assertEquals(witnessList, partList);
088    }
089
090    @Test
091    public void supportNestedClassesAtBeginning() {
092        List<String> witnessList = new ArrayList<String>();
093        witnessList.add("foo");
094        witnessList.add("Nested");
095        witnessList.add("bar");
096
097        List<String> partList = LoggerNameUtil.computeNameParts("foo$Nested.bar");
098        assertEquals(witnessList, partList);
099    }
100
101}