Logger extends ServiceTracker implements LogService { public Logger(BundleContext context) { super(context, LogService.class.getName(), null); } Logger(BundleContext context); void log(int level, String message); void log(int level, String message, Throwable exception); void log(ServiceReference ref, int level, String message); void log(ServiceReference ref, int level, String message, Throwable exception);  }
@Test public void testLogger() { Logger logger = new Logger(ctx); logger.open(); logger.log(LogService.LOG_INFO, "This message will disappear"); TestLogService tls = new TestLogService(); ctx.registerService(LogService.class.getName(), tls, null); Assert.assertEquals("Precondition", 0, tls.logData.size()); logger.log(LogService.LOG_INFO, "Hi"); Assert.assertEquals(1, tls.logData.size()); LogData ld = tls.logData.get(0); Assert.assertEquals(LogService.LOG_INFO, ld.level); Assert.assertEquals("Hi", ld.message); logger.close(); logger.log(LogService.LOG_INFO, "This message will disappear too"); Assert.assertEquals("The logger was closed so log messages shouldn't appear in the LogService any more", 1, tls.logData.size()); }