updated coding rules.
[utils] / system / general / src / test / java / org / wamblee / system / container / ContainerTest.java
index e61c023ca0e35ae66908b04259a0d99bee520a28..bda07b218a62d5b64c9b4ab0c0ea476e1149e0a3 100644 (file)
@@ -21,9 +21,6 @@ import java.util.List;
 
 import junit.framework.TestCase;
 
-import org.easymock.classextension.ConstructorArgs;
-import org.easymock.classextension.EasyMock;
-import org.easymock.classextension.IMocksControl;
 import org.wamblee.general.Pair;
 import org.wamblee.system.core.Component;
 import org.wamblee.system.core.DefaultProvidedInterface;
@@ -36,17 +33,16 @@ import org.wamblee.system.core.Scope;
 import org.wamblee.system.core.StringComponent;
 import org.wamblee.system.core.SystemAssemblyException;
 import org.wamblee.test.AssertionUtils;
-import org.wamblee.test.EasyMockMatchers;
 import org.wamblee.test.EventTracker;
 
 public class ContainerTest extends TestCase {
 
-       private EventTracker<String> _tracker;
+       private EventTracker<String> tracker;
 
        @Override
        protected void setUp() throws Exception {
                super.setUp();
-               _tracker = new EventTracker<String>();
+               tracker = new EventTracker<String>();
        }
 
        private static class MyMultiple implements Serializable, Runnable {
@@ -67,15 +63,15 @@ public class ContainerTest extends TestCase {
        }
 
        public void testEnvironmentApplication() {
-               Environment environment = new Environment(_tracker);
-               Application application = new Application(_tracker);
+               Environment environment = new Environment(tracker);
+               Application application = new Application(tracker);
                Container container = new Container("root", new Component[] {
                                environment, application }, new ProvidedInterface[0],
                                new RequiredInterface[0]);
                Scope scope = container.start();
                assertTrue(container.isSealed());
                AssertionUtils.assertEquals(new String[] { "start.environment",
-                               "start.application" }, _tracker.getEvents(
+                               "start.application" }, tracker.getEvents(
                                Thread.currentThread()).toArray(new String[0]));
                assertEquals(0, scope.getProvidedInterfaces().size());
 
@@ -85,14 +81,14 @@ public class ContainerTest extends TestCase {
        }
 
        public void testEnvironmentApplicationSimpleConstructor() {
-               Environment environment = new Environment(_tracker);
-               Application application = new Application(_tracker);
+               Environment environment = new Environment(tracker);
+               Application application = new Application(tracker);
                Container container = new Container("root").addComponent(environment)
                                .addComponent(application);
 
                Scope scope = container.start();
                AssertionUtils.assertEquals(new String[] { "start.environment",
-                               "start.application" }, _tracker.getEvents(
+                               "start.application" }, tracker.getEvents(
                                Thread.currentThread()).toArray(new String[0]));
                assertEquals(0, scope.getProvidedInterfaces().size());
 
@@ -117,9 +113,9 @@ public class ContainerTest extends TestCase {
        }
 
        public void testComposite() {
-               Component<?> environment = new Environment(_tracker);
-               Component<?> application = new Application(_tracker);
-               assertEquals(0, _tracker.getEventCount());
+               Component<?> environment = new Environment(tracker);
+               Component<?> application = new Application(tracker);
+               assertEquals(0, tracker.getEventCount());
 
                Container system = new Container("all", new Component[] { environment,
                                application }, new ProvidedInterface[0],
@@ -131,13 +127,13 @@ public class ContainerTest extends TestCase {
                assertEquals(0, provided.size());
 
                AssertionUtils.assertEquals(new String[] { "start.environment",
-                               "start.application" }, _tracker.getEvents(
+                               "start.application" }, tracker.getEvents(
                                Thread.currentThread()).toArray(new String[0]));
-               _tracker.clear();
+               tracker.clear();
 
                system.stop(runtime);
                AssertionUtils.assertEquals(new String[] { "stop.application",
-                               "stop.environment" }, _tracker
+                               "stop.environment" }, tracker
                                .getEvents(Thread.currentThread()).toArray(new String[0]));
 
        }
@@ -280,17 +276,14 @@ public class ContainerTest extends TestCase {
 
        public void testEnvironmentApplicationRollbackOnException()
                        throws Exception {
-               IMocksControl control = EasyMock.createStrictControl();
-
-               Environment environment = new Environment(_tracker);
-               Application application = control.createMock(Application.class,
-                               new ConstructorArgs(Application.class.getConstructor()),
-                               Application.class.getDeclaredMethod("doStart", Scope.class));
-
-               application.doStart(EasyMockMatchers.anyObject(Scope.class));
-               EasyMock.expectLastCall().andThrow(new RuntimeException());
-               control.replay();
-
+               Environment environment = new Environment(tracker);
+               Application application = new Application() { 
+                       @Override
+                       public Object doStart(Scope aScope) {
+                               throw new RuntimeException();
+                       }
+               };
+               
                try {
                        Container container = new Container("root", new Component[] {
                                        environment, application }, new ProvidedInterface[0],
@@ -299,7 +292,7 @@ public class ContainerTest extends TestCase {
                        container.start();
                } catch (RuntimeException e) {
                        AssertionUtils.assertEquals(new String[] { "start.environment",
-                                       "stop.environment" }, _tracker.getEvents(
+                                       "stop.environment" }, tracker.getEvents(
                                        Thread.currentThread()).toArray(new String[0]));
                        return;
                }
@@ -308,27 +301,22 @@ public class ContainerTest extends TestCase {
 
        public void testEnvironmentApplicationRollbackOnExceptionWithExceptionOnStop()
                        throws Exception {
-               IMocksControl control = EasyMock.createControl();
 
-               Environment environment = new Environment(_tracker);
+               Environment environment = new Environment(tracker);
                // Application 1 will throw an exception while stopping.
-               Application application1 = control.createMock(Application.class,
-                               new ConstructorArgs(Application.class.getConstructor()),
-                               Application.class.getDeclaredMethod("doStop", Object.class));
-
-               application1.doStop(EasyMock.anyObject());
-               EasyMock.expectLastCall().andThrow(new RuntimeException());
+               Application application1 = new Application("app1")  {
+                       @Override
+                       public void doStop(Object aRuntime) {
+                               throw new RuntimeException();
+                       }
+               };
 
                // application 2 will throw an exception while starting
-               Application application2 = control.createMock(Application.class,
-                               new ConstructorArgs(Application.class
-                                               .getConstructor(String.class), "application2"),
-                               Application.class.getDeclaredMethod("doStart", Scope.class));
-
-               application2.doStart(EasyMockMatchers.anyObject(Scope.class));
-               EasyMock.expectLastCall().andThrow(new RuntimeException());
-
-               control.replay();
+               Application application2 = new Application("app2") {
+                       public Object doStart(Scope aScope) { 
+                               throw new RuntimeException();
+                       }
+               };
 
                try {
                        Container container = new Container("root", new Component[] {
@@ -338,7 +326,7 @@ public class ContainerTest extends TestCase {
                        container.start();
                } catch (RuntimeException e) {
                        AssertionUtils.assertEquals(new String[] { "start.environment",
-                                       "stop.environment" }, _tracker.getEvents(
+                                       "stop.environment" }, tracker.getEvents(
                                        Thread.currentThread()).toArray(new String[0]));
                        return;
                }
@@ -554,7 +542,7 @@ public class ContainerTest extends TestCase {
        }
 
        public void testProvidedInterfaces() {
-               Environment env = new Environment(_tracker);
+               Environment env = new Environment(tracker);
                Container envcontainer = new Container("0").addComponent(env)
                                .addProvidedInterface(
                                                new DefaultProvidedInterface("string", String.class))
@@ -563,21 +551,21 @@ public class ContainerTest extends TestCase {
                Scope scope = envcontainer.start();
 
                AssertionUtils.assertEquals(new String[] { "start.environment" },
-                               _tracker.getEvents(Thread.currentThread()).toArray(
+                               tracker.getEvents(Thread.currentThread()).toArray(
                                                new String[0]));
 
                envcontainer.stop(scope);
        }
 
        public void testCoupleTwoContainers() {
-               Environment env = new Environment(_tracker);
+               Environment env = new Environment(tracker);
                Container envcontainer = new Container("0").addComponent(env)
                                .addProvidedInterface(
                                                new DefaultProvidedInterface("string", String.class))
                                .addProvidedInterface(
                                                new DefaultProvidedInterface("integer", Integer.class));
 
-               Application app = new Application(_tracker);
+               Application app = new Application(tracker);
                Container appcontainer = new Container("1").addComponent(app)
                                .addRequiredInterface(
                                                new DefaultRequiredInterface("string", String.class))
@@ -589,7 +577,7 @@ public class ContainerTest extends TestCase {
 
                top.start();
                AssertionUtils.assertEquals(new String[] { "start.environment",
-                               "start.application" }, _tracker.getEvents(
+                               "start.application" }, tracker.getEvents(
                                Thread.currentThread()).toArray(new String[0]));
 
        }