This is an automated email from the ASF dual-hosted git repository. rombert pushed a commit to branch issue/SLING-11913 in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-osgi-mock.git
commit f10ec2a52a9f88fe07818d7513696ecffcc1aa7a Author: Robert Munteanu <[email protected]> AuthorDate: Tue Jun 27 11:20:50 2023 +0200 SLING-11913 - Implement MockBundle.getVersion --- .../apache/sling/testing/mock/osgi/MockBundle.java | 20 +++++++++++++++----- .../apache/sling/testing/mock/osgi/package-info.java | 2 +- .../sling/testing/mock/osgi/MockBundleTest.java | 13 +++++++++++++ 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/org/apache/sling/testing/mock/osgi/MockBundle.java b/core/src/main/java/org/apache/sling/testing/mock/osgi/MockBundle.java index f53abd4..2e3f2a1 100644 --- a/core/src/main/java/org/apache/sling/testing/mock/osgi/MockBundle.java +++ b/core/src/main/java/org/apache/sling/testing/mock/osgi/MockBundle.java @@ -49,6 +49,7 @@ public final class MockBundle implements Bundle { private Map<String, String> headers = Collections.emptyMap(); private String symbolicName; private long lastModified; + private Version version = Version.emptyVersion; /** * Constructor @@ -194,6 +195,20 @@ public final class MockBundle implements Bundle { return null; } } + + @Override + public Version getVersion() { + return version; + } + + /** + * Sets a new version for this bundle + * + * @param version the new version + */ + public void setVersion(Version version) { + this.version = version; + } // --- unsupported operations --- @Override @@ -271,11 +286,6 @@ public final class MockBundle implements Bundle { throw new UnsupportedOperationException(); } - @Override - public Version getVersion() { - throw new UnsupportedOperationException(); - } - @Override public int compareTo(Bundle o) { throw new UnsupportedOperationException(); diff --git a/core/src/main/java/org/apache/sling/testing/mock/osgi/package-info.java b/core/src/main/java/org/apache/sling/testing/mock/osgi/package-info.java index b6ba265..cd480aa 100644 --- a/core/src/main/java/org/apache/sling/testing/mock/osgi/package-info.java +++ b/core/src/main/java/org/apache/sling/testing/mock/osgi/package-info.java @@ -19,5 +19,5 @@ /** * Mock implementation of selected OSGi APIs. */ [email protected]("3.6.0") [email protected]("3.7.0") package org.apache.sling.testing.mock.osgi; diff --git a/core/src/test/java/org/apache/sling/testing/mock/osgi/MockBundleTest.java b/core/src/test/java/org/apache/sling/testing/mock/osgi/MockBundleTest.java index 3f73c32..b87426a 100644 --- a/core/src/test/java/org/apache/sling/testing/mock/osgi/MockBundleTest.java +++ b/core/src/test/java/org/apache/sling/testing/mock/osgi/MockBundleTest.java @@ -30,6 +30,7 @@ import java.util.List; import org.junit.Before; import org.junit.Test; import org.osgi.framework.Bundle; +import org.osgi.framework.Version; import com.google.common.collect.ImmutableMap; @@ -154,4 +155,16 @@ public class MockBundleTest { assertTrue(paths.contains("bundleData/nested/first.txt")); assertTrue(paths.contains("bundleData/nested/second.txt")); } + + @Test + public void getVersion_default() { + assertEquals(Version.emptyVersion, bundle.getVersion()); + } + + @Test + public void getVersion_custom() { + bundle.setVersion(new Version(3, 2, 1)); + assertEquals("3.2.1", bundle.getVersion().toString()); + } + }
