Class OsgiContextExtension

  • All Implemented Interfaces:
    org.junit.jupiter.api.extension.AfterEachCallback, org.junit.jupiter.api.extension.AfterTestExecutionCallback, org.junit.jupiter.api.extension.BeforeEachCallback, org.junit.jupiter.api.extension.Extension, org.junit.jupiter.api.extension.ParameterResolver, org.junit.jupiter.api.extension.TestInstancePostProcessor

    public final class OsgiContextExtension
    extends Object
    implements org.junit.jupiter.api.extension.ParameterResolver, org.junit.jupiter.api.extension.TestInstancePostProcessor, org.junit.jupiter.api.extension.BeforeEachCallback, org.junit.jupiter.api.extension.AfterEachCallback, org.junit.jupiter.api.extension.AfterTestExecutionCallback
    JUnit 5 extension that allows to inject OsgiContext (or subclasses of it) parameters in test methods, and ensures that the context is set up and teared down properly for each test method.
    • Constructor Detail

      • OsgiContextExtension

        public OsgiContextExtension()
    • Method Detail

      • postProcessTestInstance

        public void postProcessTestInstance​(Object testInstance,
                                            org.junit.jupiter.api.extension.ExtensionContext extensionContext)
                                     throws Exception
        Checks if test class has a OsgiContext or derived field. If it has and is not instantiated, create an new OsgiContext and store it in the field. If it is already instantiated reuse this instance and use it for all test methods.
        Specified by:
        postProcessTestInstance in interface org.junit.jupiter.api.extension.TestInstancePostProcessor
        Throws:
        Exception
      • supportsParameter

        public boolean supportsParameter​(org.junit.jupiter.api.extension.ParameterContext parameterContext,
                                         org.junit.jupiter.api.extension.ExtensionContext extensionContext)
        Support parameter injection for test methods of parameter type is derived from OsgiContext.
        Specified by:
        supportsParameter in interface org.junit.jupiter.api.extension.ParameterResolver
      • resolveParameter

        public Object resolveParameter​(org.junit.jupiter.api.extension.ParameterContext parameterContext,
                                       org.junit.jupiter.api.extension.ExtensionContext extensionContext)
        Resolve (or create) OsgiContext instance for test method parameter.
        Specified by:
        resolveParameter in interface org.junit.jupiter.api.extension.ParameterResolver
      • beforeEach

        public void beforeEach​(org.junit.jupiter.api.extension.ExtensionContext extensionContext)
                        throws Exception
        Specified by:
        beforeEach in interface org.junit.jupiter.api.extension.BeforeEachCallback
        Throws:
        Exception
      • afterTestExecution

        public void afterTestExecution​(org.junit.jupiter.api.extension.ExtensionContext extensionContext)
                                throws Exception
        Specified by:
        afterTestExecution in interface org.junit.jupiter.api.extension.AfterTestExecutionCallback
        Throws:
        Exception
      • afterEach

        public void afterEach​(org.junit.jupiter.api.extension.ExtensionContext extensionContext)
        Specified by:
        afterEach in interface org.junit.jupiter.api.extension.AfterEachCallback