(no commit message)
[utils] / system / general / src / test / java / org / wamblee / system / graph / CompositeEdgeFilterTest.java
index 6507efa93bcb093553c61198fd50f54d03507651..042b8edfa677a0a4c59a9490b8a2946425e7d8f7 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2008 the original author or authors.
+ * Copyright 2005-2010 the original author or authors.
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
- */ 
+ */
 package org.wamblee.system.graph;
 
-import java.util.Arrays;
-
 import junit.framework.TestCase;
+import static org.mockito.Matchers.*;
+import static org.mockito.Mockito.*;
 
-import org.easymock.classextension.EasyMock;
-import org.easymock.classextension.IMocksControl;
-import static org.easymock.classextension.EasyMock.*;
 import org.wamblee.system.container.Application;
 import org.wamblee.system.core.Component;
 import org.wamblee.system.core.Environment;
@@ -30,92 +27,83 @@ import org.wamblee.system.core.RequiredInterface;
 import org.wamblee.system.graph.component.ProvidedInterfaceNode;
 import org.wamblee.system.graph.component.RequiredInterfaceNode;
 
+/**
+ * 
+ * @author $author$
+ * @version $Revision$
+ */
 public class CompositeEdgeFilterTest extends TestCase {
-    private Application _app = new Application(); 
-    private Environment _env = new Environment();
-    
-    private Edge createEdge(Component aClient, RequiredInterface aRequired, 
-            Component aServer, ProvidedInterface aProvided) { 
+    private Application app = new Application();
+
+    private Environment env = new Environment();
+
+    private Edge createEdge(Component aClient, RequiredInterface aRequired,
+        Component aServer, ProvidedInterface aProvided) {
         Node from = new RequiredInterfaceNode(aClient, aRequired);
         Node to = new ProvidedInterfaceNode(aServer, aProvided);
+
         return new DefaultEdge(from, to);
     }
 
-    public void testEmpty() { 
-        EdgeFilter restriction = new CompositeEdgeFilter(); 
-        assertFalse(restriction.isViolated(createEdge(_app, _app.getRequiredInterfaces()[0], 
-                _env, _env.getProvidedInterfaces()[0])));
+    public void testEmpty() {
+        EdgeFilter restriction = new CompositeEdgeFilter();
+        assertFalse(restriction.isViolated(createEdge(app, app
+            .getRequiredInterfaces().get(0), env, env.getProvidedInterfaces()
+            .get(0))));
     }
-    
-    private void configureRestriction(EdgeFilter base, boolean aResult) {
-        base.isViolated( (Edge)EasyMock.anyObject());
-        EasyMock.expectLastCall().andReturn(aResult);
+
+    private void configureRestriction(EdgeFilter aBase, boolean aResult) {
+        stub(aBase.isViolated((Edge) anyObject())).toReturn(aResult);
     }
-    
-    public void testOneRestriction() { 
-        IMocksControl control = EasyMock.createStrictControl();
-      
-        EdgeFilter base = control.createMock(EdgeFilter.class);
+
+    public void testOneRestriction() {
+        EdgeFilter base = mock(EdgeFilter.class);
         CompositeEdgeFilter composite = new CompositeEdgeFilter();
         composite.add(base);
-        
-        // First let the base return false and verify the result. 
-        
+
+        // First let the base return false and verify the result.
         configureRestriction(base, false);
-        
-        control.replay();
-        assertFalse(composite.isViolated(createEdge(_app, _app.getRequiredInterfaces()[0], 
-                _env, _env.getProvidedInterfaces()[0])));
-        control.verify();
-        
+
+        assertFalse(composite.isViolated(createEdge(app, app
+            .getRequiredInterfaces().get(0), env, env.getProvidedInterfaces()
+            .get(0))));
+
         // Second let the base return true and verify the result.
-        control.reset();
         configureRestriction(base, true);
-        
-        control.replay();
-        assertTrue(composite.isViolated(createEdge(_app, _app.getRequiredInterfaces()[0], 
-                _env, _env.getProvidedInterfaces()[0])));
-        control.verify();
+
+        assertTrue(composite.isViolated(createEdge(app, app
+            .getRequiredInterfaces().get(0), env, env.getProvidedInterfaces()
+            .get(0))));
     }
 
-   
-    
-    public void testTwoRestrictions() { 
-        IMocksControl control = EasyMock.createStrictControl();
-        
-        EdgeFilter base1 = control.createMock(EdgeFilter.class);
+    public void testTwoRestrictions() {
+        EdgeFilter base1 = mock(EdgeFilter.class);
         CompositeEdgeFilter composite = new CompositeEdgeFilter();
         composite.add(base1);
-        EdgeFilter base2 = control.createMock(EdgeFilter.class);
+
+        EdgeFilter base2 = mock(EdgeFilter.class);
         composite.add(base2);
-        
-        // 1. base1 not violated and base 2 not violated -> not violated. 
-        
+
+        // 1. base1 not violated and base 2 not violated -> not violated.
         configureRestriction(base1, false);
         configureRestriction(base2, false);
-        control.replay();
-        assertFalse(composite.isViolated(createEdge(_app, _app.getRequiredInterfaces()[0], 
-                _env, _env.getProvidedInterfaces()[0])));
-        control.verify();
-        control.reset();
-        
+        assertFalse(composite.isViolated(createEdge(app, app
+            .getRequiredInterfaces().get(0), env, env.getProvidedInterfaces()
+            .get(0))));
+
         // 2. base 1 not violated but base 2 violated -> violated
         configureRestriction(base1, false);
         configureRestriction(base2, true);
-        control.replay();
-        assertTrue(composite.isViolated(createEdge(_app, _app.getRequiredInterfaces()[0], 
-                _env, _env.getProvidedInterfaces()[0])));
-        control.verify();
-        control.reset();
-        
-        // 3. base 1 violated -> violated and base 2 not called. 
+
+        assertTrue(composite.isViolated(createEdge(app, app
+            .getRequiredInterfaces().get(0), env, env.getProvidedInterfaces()
+            .get(0))));
+
+        // 3. base 1 violated -> violated and base 2 not called.
         configureRestriction(base1, true);
         // base 2 should not be called.
-        control.replay();
-        assertTrue(composite.isViolated(createEdge(_app, _app.getRequiredInterfaces()[0], 
-                _env, _env.getProvidedInterfaces()[0])));
-        control.verify();
-        control.reset();
+        assertTrue(composite.isViolated(createEdge(app, app
+            .getRequiredInterfaces().get(0), env, env.getProvidedInterfaces()
+            .get(0))));
     }
-    
 }