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