View Javadoc
1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
4    *
5    * This program and the accompanying materials are dual-licensed under
6    * either the terms of the Eclipse Public License v1.0 as published by
7    * the Eclipse Foundation
8    *
9    *   or (per the licensee's choosing)
10   *
11   * under the terms of the GNU Lesser General Public License version 2.1
12   * as published by the Free Software Foundation.
13   */
14  package ch.qos.logback.classic.spi;
15  
16  import static org.junit.Assert.assertEquals;
17  import static org.junit.Assert.assertNotNull;
18  import static org.junit.Assert.assertTrue;
19  
20  import org.junit.Test;
21  
22  public class CallerDataTest {
23  
24      @Test
25      public void testBasic() {
26          Throwable t = new Throwable();
27          StackTraceElement[] steArray = t.getStackTrace();
28  
29          StackTraceElement[] cda = CallerData.extract(t, CallerDataTest.class.getName(), 50, null);
30          assertNotNull(cda);
31          assertTrue(cda.length > 0);
32          assertEquals(steArray.length - 1, cda.length);
33      }
34  
35      /**
36       * This test verifies that in case caller data cannot be
37       * extracted, CallerData.extract does not throw an exception
38       *
39       */
40      @Test
41      public void testDeferredProcessing() {
42          StackTraceElement[] cda = CallerData.extract(new Throwable(), "com.inexistent.foo", 10, null);
43          assertNotNull(cda);
44          assertEquals(0, cda.length);
45      }
46  
47  }