Class Service

java.lang.Object
org.apache.sling.junit.rules.Service
All Implemented Interfaces:
org.junit.rules.TestRule
Direct Known Subclasses:
OSGiService

public class Service extends Object implements org.junit.rules.TestRule
Allows a test class to obtain a reference to an OSGi service. This rule embodies the logic to get a bundle context, obtain a service reference, fetch the reference to the object and perform the proper cleanup after the test has run. The {#link TeleporterRule} also provides access to OSGi services for server-side tests, in a more integrated way.
  • Constructor Details

    • Service

      public Service(Class<?> serviceClass)
  • Method Details

    • apply

      public org.junit.runners.model.Statement apply(org.junit.runners.model.Statement base, org.junit.runner.Description description)
      Specified by:
      apply in interface org.junit.rules.TestRule
    • getService

      public <T> T getService(Class<T> serviceClass)
      Return the service object.
      Type Parameters:
      T - The type of the service.
      Parameters:
      serviceClass - Use this class to perform a cast before the object is returned.
      Returns:
      The service object.