Created
December 1, 2011 10:43
-
-
Save njbartlett/1415736 to your computer and use it in GitHub Desktop.
Java 7 OSGi testing ideas
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ExampleBundleTest extends TestCase { | |
private final BundleContext context = FrameworkUtil.getBundle(ExampleBundleTest.class).getBundleContext(); | |
public void testServiceAvailable() { | |
// Tests that a specific service exists and can be invoked successfully. | |
// The service reference is released automatically. | |
try (ServiceConsumer<MyService> svc = new ServiceConsumer<>(MyService.class, context)) { | |
assertEquals("Hello Neil", svc.get().sayHello("Neil")); | |
} | |
} | |
public void testServiceInvoked() { | |
// Temporarily register a service, expecting that somebody invokes it immediately. | |
// The service is automatically unregistered after the test. | |
LogService log = mock(LogService.class); | |
try (ServicePublisher<LogService> sp = new ServicePublisher<>(LogService.class, log, context)) { | |
verify(log).log(LogService.LOG_INFO, "Expected log message"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment