Updated the test to use a new feature of the Ensure helper class that allows you to test multiple invocations of the same method by specifying a list of sequence numbers that must match with the invocations.
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1022567 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/dependencymanager/test/src/test/java/org/apache/felix/dm/test/ServiceDependencyInjectionTest.java b/dependencymanager/test/src/test/java/org/apache/felix/dm/test/ServiceDependencyInjectionTest.java
index e24529b..c9408a9 100644
--- a/dependencymanager/test/src/test/java/org/apache/felix/dm/test/ServiceDependencyInjectionTest.java
+++ b/dependencymanager/test/src/test/java/org/apache/felix/dm/test/ServiceDependencyInjectionTest.java
@@ -23,8 +23,8 @@
import static org.ops4j.pax.exam.CoreOptions.provision;
import junit.framework.Assert;
-import org.apache.felix.dm.DependencyManager;
import org.apache.felix.dm.Component;
+import org.apache.felix.dm.DependencyManager;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.Option;
@@ -47,8 +47,9 @@
@Test
public void testServiceInjection(BundleContext context) {
DependencyManager m = new DependencyManager(context);
+ Ensure e = new Ensure();
// create a service provider and consumer
- ServiceProvider provider = new ServiceProvider();
+ ServiceProvider provider = new ServiceProvider(e);
Component sp = m.createComponent().setImplementation(provider).setInterface(ServiceInterface2.class.getName(), null);
Component sc = m.createComponent().setImplementation(new ServiceConsumer()).add(m.createServiceDependency().setService(ServiceInterface2.class).setRequired(true));
Component sc2 = m.createComponent()
@@ -63,7 +64,7 @@
m.add(sc2);
m.remove(sc2);
m.remove(sp);
- provider.validate(2, 3);
+ e.waitForStep(5, 5000);
}
static interface ServiceInterface {
@@ -75,20 +76,22 @@
}
static class ServiceProvider implements ServiceInterface2 {
- private int m_counter1 = 0;
- private int m_counter2 = 0;
+ private final Ensure m_ensure;
+ private Ensure.Steps m_invokeSteps = new Ensure.Steps(4, 5);
+ private Ensure.Steps m_invoke2Steps = new Ensure.Steps(1, 2, 3);
+ public ServiceProvider(Ensure e) {
+ m_ensure = e;
+ }
+
public void invoke() {
- m_counter1++;
+ System.out.println("invoke");
+ m_ensure.steps(m_invokeSteps);
}
public void invoke2() {
- m_counter2++;
- }
-
- public void validate(int c1, int c2) {
- Assert.assertEquals("invoke() should have been called this many times", c1, m_counter1);
- Assert.assertEquals("invoke2() should have been called this many times", c2, m_counter2);
+ System.out.println("invoke2");
+ m_ensure.steps(m_invoke2Steps);
}
}