SLING-4101 - accept running outside of an OSGi environment, for example when combined with SlingRemoteExecutionRule. Patch contributed by Rob Ryan, thanks!
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1641657 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/main/java/org/apache/sling/junit/annotations/SlingAnnotationsTestRunner.java b/src/main/java/org/apache/sling/junit/annotations/SlingAnnotationsTestRunner.java
index 1f0c81e..7925414 100644
--- a/src/main/java/org/apache/sling/junit/annotations/SlingAnnotationsTestRunner.java
+++ b/src/main/java/org/apache/sling/junit/annotations/SlingAnnotationsTestRunner.java
@@ -40,7 +40,8 @@
@Override
protected Object createTest() throws Exception {
final BundleContext ctx = Activator.getBundleContext();
- final ServiceReference ref = ctx.getServiceReference(TestObjectProcessor.class.getName());
+ final ServiceReference ref =
+ ctx == null ? null : ctx.getServiceReference(TestObjectProcessor.class.getName());
final TestObjectProcessor top = ref == null ? null : (TestObjectProcessor)ctx.getService(ref);
if(top == null) {