Unit tests for Feature, using mockito to mock MapFeatures
authorAndy Allan <gravitystorm@gmail.com>
Tue, 25 Jan 2011 10:57:34 +0000 (10:57 +0000)
committerAndy Allan <gravitystorm@gmail.com>
Tue, 25 Jan 2011 10:57:34 +0000 (10:57 +0000)
tests/src/AllHalcyonTests.as
tests/src/HalcyonTestRunner.mxml
tests/src/net/systemeD/potlatch2/mapfeatures/FeatureTest.as [new file with mode: 0644]

index 10ee3dd..7b26996 100644 (file)
@@ -2,6 +2,7 @@ package {
 
     import net.systemeD.halcyon.connection.NodeTest;
     import net.systemeD.halcyon.connection.actions.JoinNodeActionTest;
+    import net.systemeD.potlatch2.mapfeatures.FeatureTest;
 
     [Suite]
     [RunWith("org.flexunit.runners.Suite")]
@@ -10,5 +11,8 @@ package {
         public var nodeTest:NodeTest;
         public var joinNodeActionTest:JoinNodeActionTest;
 
+        //Potlatch2 tests. If anyone wants to separate these out, and / or rename the suite, feel free
+        public var featureTest:FeatureTest;
+
     }
 }
index 1b41a20..608ba14 100644 (file)
       import org.flexunit.listeners.CIListener;
       import org.flexunit.listeners.UIListener;
       import org.flexunit.runner.FlexUnitCore;
+      import org.mockito.integrations.flexunit4.MockitoClassRunner;
+
       private var core:FlexUnitCore;
-      
+
+      private var mockitoRunner:MockitoClassRunner;
+
       private function onCreationComplete():void
       {
       core = new FlexUnitCore();
diff --git a/tests/src/net/systemeD/potlatch2/mapfeatures/FeatureTest.as b/tests/src/net/systemeD/potlatch2/mapfeatures/FeatureTest.as
new file mode 100644 (file)
index 0000000..84a23ff
--- /dev/null
@@ -0,0 +1,41 @@
+package net.systemeD.potlatch2.mapfeatures {
+
+    import org.flexunit.Assert;
+    import net.systemeD.potlatch2.mapfeatures.Feature;
+    import net.systemeD.potlatch2.mapfeatures.MapFeatures;
+    import org.mockito.integrations.verify;
+
+    [RunWith("org.mockito.integrations.flexunit4.MockitoClassRunner")]
+    public class FeatureTest {
+
+        // Running with [Rule] is now 'preferred' instead of using the RunWith statement above,
+        // but I couldn't get it to work.
+        // [Rule]
+        // public var mockitoRule:IMethodRule = new MockitoRule();
+
+        [Mock(type="net.systemeD.potlatch2.mapfeatures.MapFeatures")]
+        public var mockMapfeatures:MapFeatures;
+
+        [Test]
+        public function testFeature():void {
+            // This just tests that the mocking is working properly
+            var f:Feature = new Feature(mockMapfeatures, XML("<feature />"));
+            Assert.assertNull(f.name);
+        }
+
+        [Test]
+        public function testFeatureName():void {
+            var f:Feature = new Feature(mockMapfeatures, XML('<feature name="my_feature"/>'));
+            Assert.assertEquals("my_feature", f.name);
+        }
+
+        [Test]
+        public function testTagsFromFeature():void {
+            var f:Feature = new Feature(mockMapfeatures, XML('<feature><tag k="highway" v="residential" /></feature>'));
+            Assert.assertEquals("highway", f.tags[0].k);
+        }
+
+        // TODO - test that a feature with an inputSet has the keys from the inputSet available via the tags method.
+        // i.e. test that [25133] works, and also test it works for nested inputSets.
+    }
+}