1   package ch.qos.logback.classic.spi;
2   
3   import static org.junit.Assert.assertEquals;
4   import static org.junit.Assert.assertNotNull;
5   import static org.junit.Assert.assertTrue;
6   
7   import org.junit.Test;
8   
9   public class CallerDataTest  {
10  
11  
12    @Test
13    public void testBasic() {
14      Throwable t = new Throwable();
15      StackTraceElement[] steArray = t.getStackTrace();
16      
17      CallerData[] cda = CallerData.extract(t, CallerDataTest.class.getName());
18      assertNotNull(cda);
19      assertTrue(cda.length > 0);
20      assertEquals(steArray.length - 1, cda.length);
21    }
22    
23    /**
24     * This test verifies that in case caller data cannot be
25     * extracted, CallerData.extract does not throw an exception
26     *
27     */
28    @Test
29    public void testDeferredProcessing() {
30      CallerData[] cda = CallerData.extract(new Throwable(), "com.inexistent.foo");
31      assertNotNull(cda);
32      assertEquals(0, cda.length);
33    }
34    
35  }