commit | 0683fc266963c2badf99080723af6b6c817a0c8f | [log] [tgz] |
---|---|---|
author | Jörg Hoh <joerghoh@users.noreply.github.com> | Mon Aug 08 15:46:56 2022 +0200 |
committer | GitHub <noreply@github.com> | Mon Aug 08 15:46:56 2022 +0200 |
tree | 98a711f659482e7460012141c0dbea8ed01d5d58 | |
parent | 7170398dba33ffa303ae59645245b833ab2c53aa [diff] |
SLING-11505 implement BundleContext.getProperty (#23)
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 @@ @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 @@ @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