Package org.apache.sling.junit.rules
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 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.
-
-
-
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 interfaceorg.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.
-
-