Class BundleContextExtension

java.lang.Object
org.osgi.test.junit5.inject.InjectingExtension<InjectBundleContext>
org.osgi.test.junit5.context.BundleContextExtension
All Implemented Interfaces:
org.junit.jupiter.api.extension.AfterAllCallback, org.junit.jupiter.api.extension.AfterEachCallback, org.junit.jupiter.api.extension.BeforeAllCallback, org.junit.jupiter.api.extension.BeforeEachCallback, org.junit.jupiter.api.extension.Extension, org.junit.jupiter.api.extension.ParameterResolver

@ExtendWith(BundleInstallerExtension.class) public class BundleContextExtension extends InjectingExtension<InjectBundleContext>
A JUnit 5 Extension to get the OSGi BundleContext of the test bundle.

The BundleContext implementation provided by this extension will automatically clean up all service registrations, bundle, service and framework listeners, as well as installed bundles left behind.

Example:

 @ExtendWith(BundleContextExtension.class)
 class MyTests {

        @InjectBundleContext
        BundleContext bundleContext;

        @Test
        public void aTest() {
                Bundle bundle = bundleContext.getBundle();
        }
 }