Added more tests to enable 100% coverage as required by clover taget
diff --git a/org.eclipse.virgo.teststubs.osgi/src/test/java/org/eclipse/virgo/teststubs/osgi/framework/StubBundleContextTests.java b/org.eclipse.virgo.teststubs.osgi/src/test/java/org/eclipse/virgo/teststubs/osgi/framework/StubBundleContextTests.java
index 320f35c..791dd48 100644
--- a/org.eclipse.virgo.teststubs.osgi/src/test/java/org/eclipse/virgo/teststubs/osgi/framework/StubBundleContextTests.java
+++ b/org.eclipse.virgo.teststubs.osgi/src/test/java/org/eclipse/virgo/teststubs/osgi/framework/StubBundleContextTests.java
@@ -95,6 +95,11 @@
}
@Test
+ public void getBundleByLocation() {
+ assertNull(this.bundleContext.getBundle("testLocation"));
+ }
+
+ @Test
public void getBundleById() {
StubBundle bundle = new StubBundle(25L, "testSymbolicName", new Version(1, 0, 0), "testLocation");
this.bundleContext.addInstalledBundle(bundle);
@@ -299,6 +304,12 @@
assertNotNull(this.bundleContext.getServiceReference(Object.class));
}
+ @Test
+ public void getServiceReferenceNoMatching() throws InvalidSyntaxException {
+ this.bundleContext.addFilter(new FalseTestFilter());
+ this.bundleContext.registerService(Object.class, new Object(), null);
+ assertEquals(0, this.bundleContext.getServiceReferences(Object.class, "falseTestFilter").size());
+ }
@Test
public void getServiceReferenceTwoValues() throws InvalidSyntaxException {
@@ -391,4 +402,22 @@
}
}
+
+ private static class FalseTestFilter extends TestFilter {
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean match(ServiceReference<?> reference) {
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getFilterString() {
+ return "falseTestFilter";
+ }
+
+ }
}
diff --git a/org.eclipse.virgo.teststubs.osgi/src/test/java/org/eclipse/virgo/teststubs/osgi/framework/StubBundleTests.java b/org.eclipse.virgo.teststubs.osgi/src/test/java/org/eclipse/virgo/teststubs/osgi/framework/StubBundleTests.java
index 5e0b6cf..758d9ae 100644
--- a/org.eclipse.virgo.teststubs.osgi/src/test/java/org/eclipse/virgo/teststubs/osgi/framework/StubBundleTests.java
+++ b/org.eclipse.virgo.teststubs.osgi/src/test/java/org/eclipse/virgo/teststubs/osgi/framework/StubBundleTests.java
@@ -24,11 +24,7 @@
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
-import java.util.ArrayList;
-import java.util.Dictionary;
-import java.util.Enumeration;
-import java.util.Hashtable;
-import java.util.List;
+import java.util.*;
import org.junit.Test;
import org.osgi.framework.Bundle;
@@ -36,6 +32,7 @@
import org.osgi.framework.BundleException;
import org.osgi.framework.BundleListener;
import org.osgi.framework.Version;
+import org.osgi.framework.startlevel.BundleStartLevel;
public class StubBundleTests {
@@ -465,6 +462,40 @@
assertContains("state", toString);
}
+ @Test
+ public void compareTo() {
+ assertEquals(0, this.bundle.compareTo(this.bundle));
+ assertEquals(0, this.bundle.compareTo(new StubBundle(DEFAULT_BUNDLE_ID, DEFAULT_SYMBOLIC_NAME, DEFAULT_VERSION, DEFAULT_LOCATION)));
+ assertTrue(0 != this.bundle.compareTo(new StubBundle(2L, DEFAULT_SYMBOLIC_NAME, DEFAULT_VERSION, DEFAULT_LOCATION)));
+ assertTrue(0 != this.bundle.compareTo(new StubBundle(DEFAULT_BUNDLE_ID, "testName", DEFAULT_VERSION, DEFAULT_LOCATION)));
+ assertTrue(0 != this.bundle.compareTo(new StubBundle(DEFAULT_BUNDLE_ID, DEFAULT_SYMBOLIC_NAME, new Version(1, 0, 0), DEFAULT_LOCATION)));
+ assertTrue(0 != this.bundle.compareTo(new StubBundle(DEFAULT_BUNDLE_ID, DEFAULT_SYMBOLIC_NAME, DEFAULT_VERSION, "testLocation")));
+ assertEquals(0, this.bundle.compareTo(new StubBundle()));
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void compareToNull() {
+ this.bundle.compareTo(null);
+ }
+
+ @Test
+ public void testGetSignerCertificates() {
+ assertEquals(0, this.bundle.getSignerCertificates(0).size());
+ assertEquals(0, this.bundle.getSignerCertificates(7).size());
+ }
+
+ @Test
+ public void adapt() {
+ assertNull(this.bundle.adapt(null));
+ assertNull(this.bundle.adapt(BundleStartLevel.class));
+ }
+
+ @Test
+ public void getDataFile() {
+ assertNull(this.bundle.getDataFile(null));
+ assertNull(this.bundle.getDataFile("testFile"));
+ }
+
private static final class TestInputStream extends InputStream {
@Override
diff --git a/org.eclipse.virgo.teststubs.osgi/src/test/java/org/eclipse/virgo/teststubs/osgi/service/component/StubComponentContextTests.java b/org.eclipse.virgo.teststubs.osgi/src/test/java/org/eclipse/virgo/teststubs/osgi/service/component/StubComponentContextTests.java
new file mode 100755
index 0000000..fef3313
--- /dev/null
+++ b/org.eclipse.virgo.teststubs.osgi/src/test/java/org/eclipse/virgo/teststubs/osgi/service/component/StubComponentContextTests.java
@@ -0,0 +1,106 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 SAP AG
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * SAP AG - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.teststubs.osgi.service.component;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.ServiceReference;
+
+import org.eclipse.virgo.teststubs.osgi.framework.StubBundleContext;
+
+public class StubComponentContextTests {
+
+ private StubBundleContext bundleContext = new StubBundleContext();
+
+ private StubComponentContext componentContext = new StubComponentContext(this.bundleContext);
+
+ @Test
+ public void getProperties() {
+ assertNotNull(this.componentContext.getProperties());
+ assertTrue(0 != this.componentContext.getProperties().size());
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void locateServiceWithName() {
+ this.componentContext.locateService("testName");
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void locateServiceWithNameAndServiceReference() {
+ this.componentContext.locateService("testName", new ServiceReference<Object>() {
+
+ public int compareTo(Object reference) {
+ throw new UnsupportedOperationException();
+ }
+
+ public Bundle getBundle() {
+ throw new UnsupportedOperationException();
+ }
+
+ public Object getProperty(String key) {
+ return null;
+ }
+
+ public String[] getPropertyKeys() {
+ throw new UnsupportedOperationException();
+ }
+
+ public Bundle[] getUsingBundles() {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean isAssignableTo(Bundle bundle, String className) {
+ throw new UnsupportedOperationException();
+ }
+ });
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void locateServices() {
+ this.componentContext.locateServices("testName");
+ }
+
+ @Test
+ public void getBundleContext() {
+ assertEquals(this.bundleContext, this.componentContext.getBundleContext());
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void getUsingBundle() {
+ this.componentContext.getUsingBundle();
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void getComponentInstance() {
+ this.componentContext.getComponentInstance();
+ }
+
+ @Test
+ public void enableComponent() {
+ this.componentContext.enableComponent("testName");
+ }
+
+ @Test
+ public void disableComponent() {
+ this.componentContext.disableComponent("testName");
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void getServiceReference() {
+ this.componentContext.getServiceReference();
+ }
+
+}
diff --git a/org.eclipse.virgo.teststubs.osgi/src/test/java/org/eclipse/virgo/teststubs/osgi/support/FalseFilterTests.java b/org.eclipse.virgo.teststubs.osgi/src/test/java/org/eclipse/virgo/teststubs/osgi/support/FalseFilterTests.java
index a9c8305..a4b2970 100644
--- a/org.eclipse.virgo.teststubs.osgi/src/test/java/org/eclipse/virgo/teststubs/osgi/support/FalseFilterTests.java
+++ b/org.eclipse.virgo.teststubs.osgi/src/test/java/org/eclipse/virgo/teststubs/osgi/support/FalseFilterTests.java
@@ -15,6 +15,7 @@
import static org.junit.Assert.assertFalse;
import java.util.Dictionary;
+import java.util.Map;
import org.junit.Test;
import org.osgi.framework.ServiceReference;
@@ -25,12 +26,12 @@
private final FalseFilter filter = new FalseFilter();
- @SuppressWarnings("unchecked")
@Test
public void match() {
- assertFalse(filter.match((Dictionary) null));
- assertFalse(filter.match((ServiceReference) null));
+ assertFalse(filter.match((Dictionary<String, ?>) null));
+ assertFalse(filter.match((ServiceReference<?>) null));
assertFalse(filter.matchCase(null));
+ assertFalse(filter.matches((Map<String, ?>) null));
}
@Test
diff --git a/org.eclipse.virgo.teststubs.osgi/src/test/java/org/eclipse/virgo/teststubs/osgi/support/ObjectClassFilterTests.java b/org.eclipse.virgo.teststubs.osgi/src/test/java/org/eclipse/virgo/teststubs/osgi/support/ObjectClassFilterTests.java
index bc94427..6df0fdb 100644
--- a/org.eclipse.virgo.teststubs.osgi/src/test/java/org/eclipse/virgo/teststubs/osgi/support/ObjectClassFilterTests.java
+++ b/org.eclipse.virgo.teststubs.osgi/src/test/java/org/eclipse/virgo/teststubs/osgi/support/ObjectClassFilterTests.java
@@ -16,7 +16,9 @@
import static org.junit.Assert.assertTrue;
import java.util.Dictionary;
+import java.util.HashMap;
import java.util.Hashtable;
+import java.util.Map;
import org.junit.Test;
import org.osgi.framework.Bundle;
@@ -60,7 +62,7 @@
assertTrue(this.classFilter.match(objectServiceReference));
assertTrue(this.classNameFilter.match(objectServiceReference));
-
+
ServiceReference<Object> exceptionServiceReference = new ServiceReference<Object>() {
public int compareTo(Object reference) {
@@ -92,6 +94,19 @@
assertFalse(this.classNameFilter.match(exceptionServiceReference));
}
+ @Test
+ public void matches() {
+ Map<String, String[]> classNameMap = new HashMap<String, String[]>();
+ classNameMap.put(Constants.OBJECTCLASS, new String[]{Object.class.getName(), Object.class.getName()});
+
+ assertTrue(this.classFilter.matches(classNameMap));
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void matchesWithEmptyMap() {
+ this.classFilter.matches(new HashMap<String, Object>());
+ }
+
@SuppressWarnings("unchecked")
@Test
public void matchDictionaryTrue() {
diff --git a/org.eclipse.virgo.teststubs.osgi/src/test/java/org/eclipse/virgo/teststubs/osgi/support/PropertiesFilterTests.java b/org.eclipse.virgo.teststubs.osgi/src/test/java/org/eclipse/virgo/teststubs/osgi/support/PropertiesFilterTests.java
index 022dc89..5e98491 100644
--- a/org.eclipse.virgo.teststubs.osgi/src/test/java/org/eclipse/virgo/teststubs/osgi/support/PropertiesFilterTests.java
+++ b/org.eclipse.virgo.teststubs.osgi/src/test/java/org/eclipse/virgo/teststubs/osgi/support/PropertiesFilterTests.java
@@ -116,6 +116,47 @@
}));
}
+ @Test
+ public void matchesSameProperties() {
+ Map<String, Object> properties = new HashMap<String, Object>();
+ properties.put("testKey", "testValue");
+ PropertiesFilter filter = new PropertiesFilter(properties);
+
+ assertTrue(filter.matches(properties));
+
+ properties.put("newTestKey", "newTestValue");
+ assertTrue(filter.matches(properties));
+
+ properties.remove("testKey"); //removes from filter
+ assertTrue(filter.matches(properties));
+ }
+
+ @Test
+ public void matchesNewProperties() {
+ Map<String, Object> properties = new HashMap<String, Object>();
+ properties.put("testKey", "testValue");
+ PropertiesFilter filter = new PropertiesFilter(properties);
+
+ Map<String, Object> newProperties = new HashMap<String, Object>();
+ newProperties.put("testKey", "testValue");
+
+ assertTrue(filter.matches(newProperties));
+
+ newProperties.put("newTestKey", "newTestValue");
+ assertTrue(filter.matches(newProperties));
+
+ newProperties.remove("testKey");
+ assertFalse(filter.matches(newProperties));
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void matchesNull() {
+ Map<String, Object> properties = new HashMap<String, Object>();
+ properties.put("testKey", "testValue");
+ PropertiesFilter filter = new PropertiesFilter(properties);
+ filter.matches(null);
+ }
+
@SuppressWarnings("unchecked")
@Test
public void matchDictionary() {
diff --git a/org.eclipse.virgo.teststubs.osgi/src/test/java/org/eclipse/virgo/teststubs/osgi/support/TrueFilterTests.java b/org.eclipse.virgo.teststubs.osgi/src/test/java/org/eclipse/virgo/teststubs/osgi/support/TrueFilterTests.java
index 2a17c45..3557e6b 100644
--- a/org.eclipse.virgo.teststubs.osgi/src/test/java/org/eclipse/virgo/teststubs/osgi/support/TrueFilterTests.java
+++ b/org.eclipse.virgo.teststubs.osgi/src/test/java/org/eclipse/virgo/teststubs/osgi/support/TrueFilterTests.java
@@ -15,6 +15,7 @@
import static org.junit.Assert.assertTrue;
import java.util.Dictionary;
+import java.util.Map;
import org.junit.Test;
import org.osgi.framework.ServiceReference;
@@ -28,6 +29,7 @@
assertTrue(filter.match((Dictionary<String, ?>) null));
assertTrue(filter.match((ServiceReference<?>) null));
assertTrue(filter.matchCase(null));
+ assertTrue(filter.matches((Map<String, ?>) null));
}
@Test