Reworks StubBundle to use single argument instead of varargs in addRegisteredService and addServiceInUse
diff --git a/org.eclipse.virgo.test.stubs/src/main/java/org/eclipse/virgo/test/stubs/framework/StubBundle.java b/org.eclipse.virgo.test.stubs/src/main/java/org/eclipse/virgo/test/stubs/framework/StubBundle.java
index ca49c39..fe7b195 100644
--- a/org.eclipse.virgo.test.stubs/src/main/java/org/eclipse/virgo/test/stubs/framework/StubBundle.java
+++ b/org.eclipse.virgo.test.stubs/src/main/java/org/eclipse/virgo/test/stubs/framework/StubBundle.java
@@ -361,15 +361,13 @@
/**
* Adds a {@link ServiceReference} for all subsequent calls to {@link #getRegisteredServices()}.
*
- * @param serviceReferences The {@link ServiceReference}s
+ * @param serviceReference The {@link ServiceReference}
* @return <code>this</code> instance of the {@link StubBundle}
*/
- public StubBundle addRegisteredService(StubServiceReference<Object>... serviceReferences) {
+ public StubBundle addRegisteredService(StubServiceReference<Object> serviceReference) {
synchronized (this.registeredServicesMonitor) {
- for (StubServiceReference<Object> serviceReference : serviceReferences) {
- serviceReference.setBundle(this);
- this.registeredServices.add(serviceReference);
- }
+ serviceReference.setBundle(this);
+ this.registeredServices.add(serviceReference);
return this;
}
}
@@ -435,15 +433,13 @@
/**
* Adds a {@link ServiceReference} for all subsequent calls to {@link #getServicesInUse()}.
*
- * @param serviceReferences The {@link ServiceReference}s
+ * @param serviceReference The {@link ServiceReference}
* @return <code>this</code> instance of the {@link StubBundle}
*/
- public StubBundle addServiceInUse(StubServiceReference<Object>... serviceReferences) {
+ public StubBundle addServiceInUse(StubServiceReference<Object> serviceReference) {
synchronized (this.servicesInUseMonitor) {
- for (StubServiceReference<Object> serviceReference : serviceReferences) {
- serviceReference.addUsingBundles(this);
- this.servicesInUse.add(serviceReference);
- }
+ serviceReference.addUsingBundles(this);
+ this.servicesInUse.add(serviceReference);
return this;
}
}
diff --git a/org.eclipse.virgo.test.stubs/src/test/java/org/eclipse/virgo/test/stubs/framework/StubBundleContextTests.java b/org.eclipse.virgo.test.stubs/src/test/java/org/eclipse/virgo/test/stubs/framework/StubBundleContextTests.java
index 24b0e9c..c00bef5 100644
--- a/org.eclipse.virgo.test.stubs/src/test/java/org/eclipse/virgo/test/stubs/framework/StubBundleContextTests.java
+++ b/org.eclipse.virgo.test.stubs/src/test/java/org/eclipse/virgo/test/stubs/framework/StubBundleContextTests.java
@@ -150,23 +150,21 @@
assertEquals(BundleEvent.INSTALLED, listener.getEvents()[0].getType());
}
- @SuppressWarnings("unchecked")
@Test
public void registerService() {
- Dictionary properties = new Hashtable();
+ Dictionary<String, String> properties = new Hashtable<>();
properties.put("testKey", "testValue");
Object service = new Object();
- ServiceRegistration serviceRegistration = this.bundleContext.registerService(Object.class.getName(), service, properties);
+ ServiceRegistration<?> serviceRegistration = this.bundleContext.registerService(Object.class.getName(), service, properties);
assertNotNull(serviceRegistration);
assertNotNull(serviceRegistration.getReference());
assertEquals("testValue", serviceRegistration.getReference().getProperty("testKey"));
assertSame(service, this.bundleContext.getService(serviceRegistration.getReference()));
}
- @SuppressWarnings("unchecked")
@Test
public void registerServiceTyped() {
- Dictionary properties = new Hashtable();
+ Dictionary<String, String> properties = new Hashtable<>();
properties.put("testKey", "testValue");
Object service = new Object();
ServiceRegistration<Object> serviceRegistration = this.bundleContext.registerService(Object.class, service, properties);
diff --git a/org.eclipse.virgo.test.stubs/src/test/java/org/eclipse/virgo/test/stubs/framework/StubBundleTests.java b/org.eclipse.virgo.test.stubs/src/test/java/org/eclipse/virgo/test/stubs/framework/StubBundleTests.java
index ef8d40b..10b5736 100644
--- a/org.eclipse.virgo.test.stubs/src/test/java/org/eclipse/virgo/test/stubs/framework/StubBundleTests.java
+++ b/org.eclipse.virgo.test.stubs/src/test/java/org/eclipse/virgo/test/stubs/framework/StubBundleTests.java
@@ -100,10 +100,9 @@
assertEquals("testValue", this.bundle.getHeaders().get("testKey"));
}
- @SuppressWarnings("unchecked")
@Test
public void getCustomLocalizedHeaders() {
- Dictionary testHeaders = new Hashtable();
+ Dictionary<String, String> testHeaders = new Hashtable<>();
this.bundle.setLocalizedHeaders(testHeaders);
assertEquals(testHeaders, this.bundle.getHeaders("testLocale"));
}
@@ -219,18 +218,16 @@
assertNull(this.bundle.getRegisteredServices());
}
- @SuppressWarnings("unchecked")
@Test(expected = IllegalStateException.class)
public void getRegisteredServicesUninstalled() throws BundleException {
- this.bundle.addRegisteredService(new StubServiceReference(new StubServiceRegistration<Object>(new StubBundleContext(this.bundle))));
+ this.bundle.addRegisteredService(new StubServiceReference<Object>(new StubServiceRegistration<Object>(new StubBundleContext(this.bundle))));
this.bundle.uninstall();
this.bundle.getRegisteredServices();
}
- @SuppressWarnings("unchecked")
@Test
public void getRegisteredServices() {
- this.bundle.addRegisteredService(new StubServiceReference(new StubServiceRegistration<Object>(new StubBundleContext(this.bundle))));
+ this.bundle.addRegisteredService(new StubServiceReference<Object>(new StubServiceRegistration<Object>(new StubBundleContext(this.bundle))));
assertNotNull(this.bundle.getRegisteredServices());
}
@@ -239,18 +236,16 @@
assertNull(this.bundle.getServicesInUse());
}
- @SuppressWarnings("unchecked")
@Test(expected = IllegalStateException.class)
public void getServicesInUseUninstalled() throws BundleException {
- this.bundle.addServiceInUse(new StubServiceReference(new StubServiceRegistration<Object>(new StubBundleContext(this.bundle))));
+ this.bundle.addServiceInUse(new StubServiceReference<Object>(new StubServiceRegistration<Object>(new StubBundleContext(this.bundle))));
this.bundle.uninstall();
this.bundle.getServicesInUse();
}
- @SuppressWarnings("unchecked")
@Test
public void getServicesInUse() {
- this.bundle.addServiceInUse(new StubServiceReference(new StubServiceRegistration<Object>(new StubBundleContext(this.bundle))));
+ this.bundle.addServiceInUse(new StubServiceReference<Object>(new StubServiceRegistration<Object>(new StubBundleContext(this.bundle))));
assertNotNull(this.bundle.getServicesInUse());
}
@@ -504,8 +499,8 @@
private static final class TestFindEntriesDelegate implements FindEntriesDelegate {
- public Enumeration findEntries(String path, String filePattern, boolean recurse) {
- return new TestEnumeration();
+ public Enumeration<Object> findEntries(String path, String filePattern, boolean recurse) {
+ return new TestEnumeration<Object>();
}
}
@@ -516,11 +511,6 @@
public void update(StubBundle bundle) throws BundleException {
this.updateCalled = true;
}
-
- public boolean getUpdateCalled() {
- return this.updateCalled;
- }
-
}
private static class TestEnumeration<S> implements Enumeration<S> {