View Javadoc

1   package com.atlassian.plugin.osgi.container.felix;
2   
3   import junit.framework.TestCase;
4   import org.apache.felix.framework.Logger;
5   import static org.mockito.Mockito.mock;
6   import static org.mockito.Mockito.when;
7   import static org.mockito.Mockito.verify;
8   import static org.mockito.Mockito.verifyNoMoreInteractions;
9   
10  public class TestFelixLoggerBridge extends TestCase
11  {
12      private org.slf4j.Logger log;
13  
14      @Override
15      protected void setUp() throws Exception
16      {
17          super.setUp();
18          log = mock(org.slf4j.Logger.class);
19      }
20  
21      public void testFrameworkLogInfo()
22      {
23          when(log.isInfoEnabled()).thenReturn(true);
24          FelixLoggerBridge bridge = new FelixLoggerBridge(log);
25          bridge.doLog(null, Logger.LOG_INFO, "foo", null);
26          verify(log).info("foo");
27      }
28  
29      public void testClassNotFound()
30      {
31          when(log.isInfoEnabled()).thenReturn(true);
32          FelixLoggerBridge bridge = new FelixLoggerBridge(log);
33          bridge.doLog(null, Logger.LOG_WARNING, "foo", new ClassNotFoundException("foo"));
34          verify(log).debug("Class not found in bundle: foo");
35      }
36  
37      public void testClassNotFoundOnDebug()
38      {
39          when(log.isInfoEnabled()).thenReturn(true);
40          FelixLoggerBridge bridge = new FelixLoggerBridge(log);
41          bridge.doLog(null, Logger.LOG_WARNING, "*** foo", new ClassNotFoundException("*** foo", new ClassNotFoundException("bar")));
42          verify(log).debug("Class not found in bundle: *** foo");
43      }
44  
45      public void testLameClassNotFound()
46      {
47          when(log.isInfoEnabled()).thenReturn(true);
48          FelixLoggerBridge bridge = new FelixLoggerBridge(log);
49          verify(log).isDebugEnabled();
50          verify(log).isInfoEnabled();
51          bridge.doLog(null, Logger.LOG_WARNING, "org.springframework.foo", new ClassNotFoundException("org.springframework.foo"));
52          verifyNoMoreInteractions(log);
53      }
54  
55      public void testLameClassNotFoundInDebug()
56      {
57          when(log.isInfoEnabled()).thenReturn(true);
58          FelixLoggerBridge bridge = new FelixLoggerBridge(log);
59          verify(log).isDebugEnabled();
60          verify(log).isInfoEnabled();
61          bridge.doLog(null, Logger.LOG_WARNING, "*** org.springframework.foo",
62                  new ClassNotFoundException("*** org.springframework.foo", new ClassNotFoundException("org.springframework.foo")));
63          verifyNoMoreInteractions(log);
64      }
65  }