Annotation Interface MockOsgiService
Annotation used to mock OSGi services using Mockito. To mock an OSGi service, add the
ServiceRegistrationRule to the Pax Exam test class and annotate
any OSGi service field that needs to be mocked.
Service properties can be assigned to the service using the properties() attribute,
and all supported Mockito Answers modes can be specified using the answer()
attribute.
For instance, the following code would mock the Catalog Framework and Mime Type Resolver services in a Pax Exam test class:
public class TestClass {
@Rule
public final ServiceRegistrationRule serviceRegistrationRule = new ServiceRegistrationRule();
@MockOsgiService
private CatalogFramework catalogFramework;
@MockOsgiService(properties = {
@Property(key = "name", value = "tikaMimeTypeResolver")})
private MimeTypeResolver mimeTypeResolver;
// ...
}
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic @interfaceAnnotation used to assign a property to an OSGi service -
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionorg.mockito.AnswersAnswer mode to use for the mockProperties to assign to the service when registering the mock with OSGi.
-
Element Details
-
answer
org.mockito.Answers answerAnswer mode to use for the mock- Default:
- RETURNS_DEFAULTS
-
properties
MockOsgiService.Property[] propertiesProperties to assign to the service when registering the mock with OSGi.- Default:
- {}
-