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.spi;
015
016import static org.junit.Assert.assertEquals;
017import static org.junit.Assert.assertNotNull;
018import static org.junit.Assert.assertTrue;
019
020import org.junit.Test;
021
022public class CallerDataTest {
023
024    @Test
025    public void testBasic() {
026        Throwable t = new Throwable();
027        StackTraceElement[] steArray = t.getStackTrace();
028
029        StackTraceElement[] cda = CallerData.extract(t, CallerDataTest.class.getName(), 50, null);
030        assertNotNull(cda);
031        assertTrue(cda.length > 0);
032        assertEquals(steArray.length - 1, cda.length);
033    }
034
035    /**
036     * This test verifies that in case caller data cannot be
037     * extracted, CallerData.extract does not throw an exception
038     *
039     */
040    @Test
041    public void testDeferredProcessing() {
042        StackTraceElement[] cda = CallerData.extract(new Throwable(), "com.inexistent.foo", 10, null);
043        assertNotNull(cda);
044        assertEquals(0, cda.length);
045    }
046
047}