Annotation Type InjectService


@Inherited @Target({FIELD,PARAMETER}) @Retention(RUNTIME) @ExtendWith(ServiceExtension.class) @Documented public @interface InjectService
Inject OSGi services into test classes and methods.

Example:

 // For JUnit5
 @ExtendWith(ServiceExtension.class)
 class MyTests {
        // For JUnit4
        @Rule
        ServiceRule sr = new ServiceRule();

        @InjectService
        Foo foo;

        @Test
        public void test() {
                // use foo
        }
 }
 
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final class 
     
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    int
    Indicate the number of services that are required to arrive within the specified by timeout() before starting the test.
    Filter string used to target more specific services using the String.format pattern.
    Optional arguments to the format string provided by filter().
    Indicate to take the serviceClass from not from the parameter.
    long
    Indicate require services must arrive within the specified timeout.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final long
     
  • Field Details

  • Element Details

    • filter

      String filter
      Filter string used to target more specific services using the String.format pattern. Must use valid OSGi filter syntax.
      Returns:
      The filter string.
      Default:
      ""
    • filterArguments

      String[] filterArguments
      Optional arguments to the format string provided by filter().
      Returns:
      The filter arguments.
      Default:
      {}
    • cardinality

      int cardinality
      Indicate the number of services that are required to arrive within the specified by timeout() before starting the test.
      Returns:
      The cardinality.
      Default:
      1
    • timeout

      long timeout
      Indicate require services must arrive within the specified timeout.
      Returns:
      The timeout.
      Default:
      200L
    • service

      Class<?> service
      Indicate to take the serviceClass from not from the parameter. Use `org.osgi.test.common.annotation.InjectService.AnyService` and the ParameterType or FieldType `java.lang.Object` for any Service.
      Returns:
      The service class.
      Default:
      org.osgi.test.common.annotation.InjectService.class