Skip navigation links

Package no.steria.osgi.mocks

This package contains mock implementations of the OSGi framework similar to what's found in Apache Sling OSGi mocks and in Spring OSGi mocks.

See: Description

Package no.steria.osgi.mocks Description

This package contains mock implementations of the OSGi framework similar to what's found in Apache Sling OSGi mocks and in Spring OSGi mocks.

The implemented classes implement basic service registration, and retrieval, service notification and callback registration.

These OSGi mocks were written for unit tests in the Jsr330Activator project because the Apache Sling OSGi mocks were compiled against an older version of OSGi than the Jsr330Activator project was using, and because the Spring OSGi mocks didn't return null references for non-existing services, and because the tests required more logic than mockito mocks could provide.

These mocks can be used the Jsr330Activator, they only have dependencies to the OSGi core and the java runtime, and they can be easily used in unit tests.

Add the following maven dependency:

   <project>
    <dependencies>
     <dependency>
      <groupId>no.steria.osgi.jsr330activator</groupId>
      <artifactId>jsr330activator.mocks</artifactId>
      <version>1.0.1</version>
      <scope>test</scope>
     </dependency>
    </dependencies>
   </project>
 

Then in the test, create a MockBundleContext and give it as an argument where a BundleContext is expected, e.g. with a BundleActivator: public class MyOsgiTests() {

Author:
Steinar Bang

Copyright © 2018. All rights reserved.