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 org.junit.jupiter.api.Test;
17  
18  import java.util.Arrays;
19  
20  import static org.junit.jupiter.api.Assertions.assertEquals;
21  import static org.junit.jupiter.api.Assertions.assertNotNull;
22  import static org.junit.jupiter.api.Assertions.assertTrue;
23  
24  public class CallerDataTest {
25  
26      @Test
27      public void testBasic() {
28          Throwable t = new Throwable();
29          StackTraceElement[] steArray = t.getStackTrace();
30  
31          StackTraceElement[] cda = CallerData.extract(t, CallerDataTest.class.getName(), 100, null);
32          Arrays.stream(cda).forEach( ste -> System.out.println(ste));
33          assertNotNull(cda);
34          assertTrue(cda.length > 0);
35          assertEquals(steArray.length - 1, cda.length);
36      }
37  
38      /**
39       * This test verifies that in case caller data cannot be extracted,
40       * CallerData.extract does not throw an exception
41       *
42       */
43      @Test
44      public void testDeferredProcessing() {
45          StackTraceElement[] cda = CallerData.extract(new Throwable(), "com.inexistent.foo", 10, null);
46          assertNotNull(cda);
47          assertEquals(0, cda.length);
48      }
49  
50  }