Class ServiceExtension

java.lang.Object
org.osgi.test.junit5.inject.InjectingExtension<InjectService>
org.osgi.test.junit5.service.ServiceExtension
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

public class ServiceExtension extends InjectingExtension<InjectService>
A JUnit 5 Extension to depend on OSGi services.

Example:

 @ExtendWith(ServiceExtension.class)
 class MyTests {

        @InjectService
        Foo foo;

        @Test
        public void test() {
                // use foo
        }
 }
 
  • Constructor Details

    • ServiceExtension

      public ServiceExtension()
  • Method Details

    • supportsType

      protected boolean supportsType(TargetType targetType, org.junit.jupiter.api.extension.ExtensionContext extensionContext)
      Description copied from class: InjectingExtension
      Determine if this extender supports resolution for the specified TargetType for the specified ExtensionContext. The default implementation checks through all of the types that were passed to the constructor.
      Overrides:
      supportsType in class InjectingExtension<InjectService>
    • resolveValue

      protected Object resolveValue(TargetType targetType, InjectService injectService, org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws org.junit.jupiter.api.extension.ParameterResolutionException
      Description copied from class: InjectingExtension
      Resolve the value for the specified TargetType and injection annotation for the specified ExtensionContext.
      Specified by:
      resolveValue in class InjectingExtension<InjectService>
      Throws:
      org.junit.jupiter.api.extension.ParameterResolutionException
    • getServiceConfiguration

      public static <S> ServiceConfiguration<S> getServiceConfiguration(Class<S> serviceType, String format, String[] args, int cardinality, long timeout, org.junit.jupiter.api.extension.ExtensionContext extensionContext)