Permalink
Browse files

Update the tests now that Entity requires a connection in the constru…

…ctor.

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.
  • Loading branch information...
1 parent 69ec547 commit 1c01b1706aa8e24be5c90d5553f49fda6635e682 @gravitystorm gravitystorm committed Feb 22, 2012
@@ -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,21 +18,21 @@ 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);
}
[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));
@@ -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(); });
@@ -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());
@@ -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();

0 comments on commit 1c01b17

Please sign in to comment.