You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by jo...@apache.org on 2022/08/08 13:47:00 UTC

[sling-org-apache-sling-testing-osgi-mock] branch master updated: SLING-11505 implement BundleContext.getProperty (#23)

This is an automated email from the ASF dual-hosted git repository.

joerghoh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-osgi-mock.git


The following commit(s) were added to refs/heads/master by this push:
     new 0683fc2  SLING-11505 implement BundleContext.getProperty (#23)
0683fc2 is described below

commit 0683fc266963c2badf99080723af6b6c817a0c8f
Author: Jörg Hoh <jo...@users.noreply.github.com>
AuthorDate: Mon Aug 8 15:46:56 2022 +0200

    SLING-11505 implement BundleContext.getProperty (#23)
---
 .../org/apache/sling/testing/mock/osgi/MockBundleContext.java  |  5 +++--
 .../apache/sling/testing/mock/osgi/MockBundleContextTest.java  | 10 +++++++++-
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/core/src/main/java/org/apache/sling/testing/mock/osgi/MockBundleContext.java b/core/src/main/java/org/apache/sling/testing/mock/osgi/MockBundleContext.java
index d7867c9..9c5c2e9 100644
--- a/core/src/main/java/org/apache/sling/testing/mock/osgi/MockBundleContext.java
+++ b/core/src/main/java/org/apache/sling/testing/mock/osgi/MockBundleContext.java
@@ -440,8 +440,9 @@ class MockBundleContext implements BundleContext {
 
     @Override
     public String getProperty(final String s) {
-        // no mock implementation, simulate that no property is found and return null
-        return null;
+        // not full support for Framework properties yet, but we can fall back to system properties,
+        // as it is defined by the OSGI spec
+        return System.getProperty(s);
     }
 
     @Override
diff --git a/core/src/test/java/org/apache/sling/testing/mock/osgi/MockBundleContextTest.java b/core/src/test/java/org/apache/sling/testing/mock/osgi/MockBundleContextTest.java
index 8ca1be7..c3c14d9 100644
--- a/core/src/test/java/org/apache/sling/testing/mock/osgi/MockBundleContextTest.java
+++ b/core/src/test/java/org/apache/sling/testing/mock/osgi/MockBundleContextTest.java
@@ -287,7 +287,15 @@ public class MockBundleContextTest {
 
     @Test
     public void testGetProperty() {
-        assertNull(bundleContext.getProperty("anyProperty"));
+        String propName = this.getClass().getName();
+        System.setProperty(propName, "random");
+        try {
+            assertEquals("random",bundleContext.getProperty(propName));
+        } finally {
+            System.getProperties().remove(propName);
+        }
+        assertNull(bundleContext.getProperty(propName));
+        
     }
 
     @Test