Update the tests now that Entity requires a connection in the constructor.
authorAndy Allan <andy@gravitystorm.co.uk>
Wed, 22 Feb 2012 16:40:49 +0000 (16:40 +0000)
committerAndy Allan <andy@gravitystorm.co.uk>
Wed, 22 Feb 2012 16:40:49 +0000 (16:40 +0000)
Note how to mock an object that requires variables in the constructor - not exactly well documented in mockito-flex, but figured it out in the end.

tests/src/net/systemeD/halcyon/connection/NodeTest.as
tests/src/net/systemeD/halcyon/connection/actions/AddMemberToRelationActionTest.as
tests/src/net/systemeD/halcyon/connection/actions/JoinNodeActionTest.as
tests/src/net/systemeD/halcyon/connection/actions/SetTagActionTest.as

index 9524b16..0e68c1c 100644 (file)
@@ -4,8 +4,12 @@ package net.systemeD.halcyon.connection {
     import net.systemeD.halcyon.connection.Node;
     import net.systemeD.halcyon.connection.UndoableAction;
 
+    [RunWith("org.mockito.integrations.flexunit4.MockitoClassRunner")]
     public class NodeTest {
 
+      [Mock(type="net.systemeD.halcyon.connection.Connection", argsList="constructorArgs")]
+      public var connection:Connection;
+      public var constructorArgs:Array = ["name", "api", "policy"];
     
       [Test]
       public function dummy():void {
@@ -14,13 +18,13 @@ package net.systemeD.halcyon.connection {
 
       [Test]
       public function newNode():void {
-          var n:Node = new Node(1,1,{},true,5,10);
+          var n:Node = new Node(connection,1,1,{},true,5,10);
           Assert.assertEquals(n.lat, 5);
       }
 
       [Test]
       public function moveNode():void {
-          var n:Node = new Node(1,1,{},true,5,10);
+          var n:Node = new Node(connection,1,1,{},true,5,10);
           n.setLatLon(14,41, function(action:UndoableAction):void { action.doAction(); });
           Assert.assertEquals(n.lat, 14);
           Assert.assertEquals(n.lon, 41);
@@ -28,7 +32,7 @@ package net.systemeD.halcyon.connection {
 
       [Test]
       public function within():void {
-          var n:Node = new Node(1,1,{},true,5,10);
+          var n:Node = new Node(connection,1,1,{},true,5,10);
           Assert.assertTrue(n.within(9,11,6,4));
           Assert.assertFalse(n.within(9,11,1,2));
           Assert.assertFalse(n.within(11,12,6,4));
index 084b135..fcc43bc 100644 (file)
@@ -8,21 +8,26 @@ package net.systemeD.halcyon.connection.actions {
     import net.systemeD.halcyon.connection.UndoableAction;
     import net.systemeD.halcyon.connection.*;
 
+    [RunWith("org.mockito.integrations.flexunit4.MockitoClassRunner")]
     public class AddMemberToRelationActionTest {
 
+        [Mock(type="net.systemeD.halcyon.connection.Connection", argsList="constructorArgs")]
+        public var connection:Connection;
+        public var constructorArgs:Array = ["name", "api", "policy"];
+
         [Before]
         public function setUp():void {
             //Instantiate the connection first to prevent errors
-            Connection.getConnection();
+            //Connection.getConnection();
         }
 
 
         [Test]
         public function addMember():void {
 
-            var n:Node = new Node(1,1,{},true,5,10);
+            var n:Node = new Node(connection,1,1,{},true,5,10);
 
-            var rel:Relation = new Relation(1,1,{},true,[]);
+            var rel:Relation = new Relation(connection,1,1,{},true,[]);
             var member:RelationMember = new RelationMember(n, "foo");
 
             rel.appendMember(member, function(action:UndoableAction):void { action.doAction(); });
@@ -46,15 +51,15 @@ package net.systemeD.halcyon.connection.actions {
 
         [Test]
         public function appendMember():void {
-            var n:Node = new Node(1,1,{},true,5,10);
-            var n2:Node = new Node(2,1,{},true,5,10);
-            var n3:Node = new Node(3,1,{},true,5,10);
+            var n:Node = new Node(connection,1,1,{},true,5,10);
+            var n2:Node = new Node(connection,2,1,{},true,5,10);
+            var n3:Node = new Node(connection,3,1,{},true,5,10);
 
             var member1:RelationMember = new RelationMember(n, "first");
             var member2:RelationMember = new RelationMember(n2, "second");
             var member3:RelationMember = new RelationMember(n3, "third");
 
-            var rel:Relation = new Relation(1,1,{},true, [member1, member2]);
+            var rel:Relation = new Relation(connection,1,1,{},true, [member1, member2]);
             Assert.assertEquals(2, rel.length);
 
             rel.appendMember(member3, function(action:UndoableAction):void { action.doAction(); });
@@ -63,15 +68,15 @@ package net.systemeD.halcyon.connection.actions {
 
         [Test]
         public function setMember():void {
-            var n:Node = new Node(1,1,{},true,5,10);
-            var n2:Node = new Node(2,1,{},true,5,10);
-            var n3:Node = new Node(3,1,{},true,5,10);
+            var n:Node = new Node(connection,1,1,{},true,5,10);
+            var n2:Node = new Node(connection,2,1,{},true,5,10);
+            var n3:Node = new Node(connection,3,1,{},true,5,10);
 
             var member1:RelationMember = new RelationMember(n, "first");
             var member2:RelationMember = new RelationMember(n2, "second");
             var member3:RelationMember = new RelationMember(n3, "third");
 
-            var rel:Relation = new Relation(1,1,{},true, [member1, member2]);
+            var rel:Relation = new Relation(connection,1,1,{},true, [member1, member2]);
             Assert.assertEquals(2, rel.length);
 
             rel.setMember(1, member3, function(action:UndoableAction):void { action.doAction(); });
index f8c6f11..1130c0d 100644 (file)
@@ -4,13 +4,19 @@ package net.systemeD.halcyon.connection.actions {
     import net.systemeD.halcyon.connection.actions.JoinNodeAction;
     import net.systemeD.halcyon.connection.Node;
     import net.systemeD.halcyon.connection.UndoableAction;
+    import net.systemeD.halcyon.connection.Connection;
 
+    [RunWith("org.mockito.integrations.flexunit4.MockitoClassRunner")]
     public class JoinNodeActionTest {
 
+      [Mock(type="net.systemeD.halcyon.connection.Connection", argsList="constructorArgs")]
+      public var connection:Connection;
+      public var constructorArgs:Array = ["name", "api", "policy"];
+
         [Test]
         public function joinTwoNodes():void {
-            var n:Node = new Node(1,1,{},true,5,10);
-            var n1:Node = new Node(2,1,{},true,5,10);
+            var n:Node = new Node(connection,1,1,{},true,5,10);
+            var n1:Node = new Node(connection,2,1,{},true,5,10);
             var action:UndoableAction = new JoinNodeAction(n, [n1], []);
             action.doAction();
             Assert.assertFalse(n.isDeleted());
index 7ca18ec..5405392 100644 (file)
@@ -6,17 +6,22 @@ package net.systemeD.halcyon.connection.actions {
     import net.systemeD.halcyon.connection.Entity;
     import net.systemeD.halcyon.connection.Connection;
 
+    [RunWith("org.mockito.integrations.flexunit4.MockitoClassRunner")]
     public class SetTagActionTest {
 
+        [Mock(type="net.systemeD.halcyon.connection.Connection", argsList="constructorArgs")]
+        public var connection:Connection;
+        public var constructorArgs:Array = ["name", "api", "policy"];
+
         [Before]
         public function setUp():void {
             //Instantiate the connection first to prevent errors
-            Connection.getConnection();
+            //Connection.getConnection();
         }
 
         [Test]
         public function setTag():void {
-            var e:Entity = new Entity(1,1,{},true,1,"");
+            var e:Entity = new Entity(connection,1,1,{},true,1,"");
             var action:UndoableAction = new SetTagAction(e, "foo", "bar");
             action.doAction();
 
@@ -25,7 +30,7 @@ package net.systemeD.halcyon.connection.actions {
 
         [Test]
         public function setNullTag():void {
-            var e:Entity = new Entity(1,1,{foo: "bar"},true,1,"");
+            var e:Entity = new Entity(connection,1,1,{foo: "bar"},true,1,"");
             var action:UndoableAction = new SetTagAction(e, "foo", null);
             action.doAction();