Class Service

  • All Implemented Interfaces:
    org.junit.rules.TestRule
    Direct Known Subclasses:
    OSGiService

    public class Service
    extends java.lang.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 Summary

      Constructors 
      Constructor Description
      Service​(java.lang.Class<?> serviceClass)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      org.junit.runners.model.Statement apply​(org.junit.runners.model.Statement base, org.junit.runner.Description description)  
      <T> T getService​(java.lang.Class<T> serviceClass)
      Return the service object.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Service

        public Service​(java.lang.Class<?> serviceClass)
    • Method Detail

      • 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​(java.lang.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.