Commits

Anonymous committed 726ab1e

* added StyleRule with test

Comments (0)

Files changed (7)

.idea/libraries/Maven__org_hamcrest_hamcrest_swc_1_1_3.xml

+<component name="libraryTable">
+  <library name="Maven: org.hamcrest:hamcrest:swc:1.1.3" type="flex">
+    <CLASSES>
+      <root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest/1.1.3/hamcrest-1.1.3.swc!/" />
+    </CLASSES>
+    <JAVADOC>
+      <root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest/1.1.3/hamcrest-1.1.3-asdoc.zip!/" />
+    </JAVADOC>
+    <SOURCES>
+      <root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest/1.1.3/hamcrest-1.1.3-sources.jar!/" />
+    </SOURCES>
+  </library>
+</component>

.idea/libraries/Maven__org_mockolate_mockolate_swc_0_12_2.xml

+<component name="libraryTable">
+  <library name="Maven: org.mockolate:mockolate:swc:0.12.2" type="flex">
+    <CLASSES>
+      <root url="jar://$MAVEN_REPOSITORY$/org/mockolate/mockolate/0.12.2/mockolate-0.12.2.swc!/" />
+    </CLASSES>
+    <JAVADOC>
+      <root url="jar://$MAVEN_REPOSITORY$/org/mockolate/mockolate/0.12.2/mockolate-0.12.2-asdoc.zip!/" />
+    </JAVADOC>
+    <SOURCES>
+      <root url="jar://$MAVEN_REPOSITORY$/org/mockolate/mockolate/0.12.2/mockolate-0.12.2-sources.jar!/" />
+    </SOURCES>
+  </library>
+</component>
             <artifactId>flexunit</artifactId>
             <version>4.1-rc-2</version>
             <type>swc</type>
+        </dependency>
+        <dependency>
+            <groupId>org.mockolate</groupId>
+            <artifactId>mockolate</artifactId>
+            <version>0.12.2</version>
+            <type>swc</type>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.hamcrest</groupId>
+            <artifactId>hamcrest</artifactId>
+            <version>1.1.3</version>
+            <type>swc</type>
             <scope>test</scope>
         </dependency>
     </dependencies>

src/main/flex/com/ludia/client/SomeClass.as

-/**
- *  Copyright 2008 Marvin Herman Froeder
- *  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
- *  http://www.apache.org/licenses/LICENSE-2.0
- *  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, 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 com.ludia.client {
-
-	public class SomeClass {
-
-		public static function greeting(name:String):String {
-			return "Hello, " + name;
-		}
-
-	}
-
-}

src/main/flex/com/ludia/tests/rules/StyleRule.as

+/**
+ * Created with IntelliJ IDEA.
+ * User: alassauzay
+ * Date: 12-05-16
+ * Time: 2:42 PM
+ * To change this template use File | Settings | File Templates.
+ */
+package com.ludia.tests.rules {
+import mx.core.Application;
+import mx.core.FlexGlobals;
+import mx.styles.IStyleManager2;
+
+import org.flexunit.internals.runners.statements.IAsyncStatement;
+import org.flexunit.internals.runners.statements.MethodRuleBase;
+import org.flexunit.internals.runners.statements.StatementSequencer;
+import org.flexunit.rules.IMethodRule;
+import org.flexunit.runners.model.FrameworkMethod;
+import org.flexunit.token.AsyncTestToken;
+
+
+public class StyleRule extends MethodRuleBase implements IMethodRule {
+
+    public var styleManager:IStyleManager2 = Application(FlexGlobals.topLevelApplication).styleManager;
+    public var sequence:StatementSequencer;
+
+    private var _urls:Array;
+
+    public function StyleRule(...styleSheetURLs) {
+        _urls = styleSheetURLs;
+    }
+
+
+
+    override public function apply(base:IAsyncStatement, method:FrameworkMethod, test:Object):IAsyncStatement {
+        super.apply(base, method, test);
+
+        sequence = new StatementSequencer();
+
+        for each(var url:String in _urls)
+        {
+            sequence.addStep(new LoadStyleStatement(styleManager, url));
+        }
+
+        sequence.addStep(base);
+
+        return this;
+    }
+
+    override public function evaluate(parentToken:AsyncTestToken):void {
+        super.evaluate(parentToken);
+
+        sequence.evaluate(myToken);
+    }
+}
+}
+
+import flash.events.IEventDispatcher;
+
+import mx.events.StyleEvent;
+
+import mx.styles.IStyleManager2;
+
+import mx.styles.StyleManager;
+import mx.styles.StyleManager;
+
+import org.flexunit.internals.runners.statements.IAsyncStatement;
+import org.flexunit.token.AsyncTestToken;
+
+class LoadStyleStatement implements IAsyncStatement {
+
+    private var styleManager:IStyleManager2;
+    private var url:String;
+
+    public function LoadStyleStatement(styleManager:IStyleManager2, url:String)
+    {
+        this.styleManager = styleManager;
+        this.url = url;
+    }
+
+
+    public function evaluate(parentToken:AsyncTestToken):void {
+        var loader:IEventDispatcher = styleManager.loadStyleDeclarations2(url, true);
+
+        loader.addEventListener(StyleEvent.COMPLETE, function(event:StyleEvent):void{
+            parentToken.sendResult();
+        });
+    }
+}

src/test/flex/com/ludia/client/SomeTest.as

-/**
- *  Copyright 2008 Marvin Herman Froeder
- *  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
- *  http://www.apache.org/licenses/LICENSE-2.0
- *  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, 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 com.ludia.client {
-
-
-	public class SomeTest {
-
-        [Test]
-        public function testSomething():void
-        {
-
-
-        }
-
-    }
-}

src/test/flex/com/ludia/tests/rules/StyleRuleTest.as

+/**
+ * Created with IntelliJ IDEA.
+ * User: alassauzay
+ * Date: 12-05-30
+ * Time: 5:54 PM
+ * To change this template use File | Settings | File Templates.
+ */
+package com.ludia.tests.rules {
+import flash.events.EventDispatcher;
+
+import mockolate.expect;
+import mockolate.ingredients.Sequence;
+import mockolate.runner.MockolateRule;
+import mockolate.sequence;
+import mockolate.verify;
+
+import mx.events.StyleEvent;
+import mx.styles.IStyleManager2;
+
+import org.flexunit.asserts.assertEquals;
+import org.flexunit.internals.runners.statements.StatementSequencer;
+import org.flexunit.token.AsyncTestToken;
+
+public class StyleRuleTest {
+
+    [Rule]
+    public var rule:MockolateRule = new MockolateRule();
+
+    [Mock]
+    public var styleManager:IStyleManager2;
+
+    protected var styleRule:StyleRule;
+
+    [Before]
+    public function setUp():void {
+        styleRule = new StyleRule("sheet1.swf", "../sheet2.swf");
+        styleRule.styleManager = styleManager;
+    }
+
+    [Test]
+    public function testApply():void {
+
+        var order:Sequence = sequence();
+        var dispatcher:EventDispatcher = new EventDispatcher();
+
+
+        assertEquals(styleRule, styleRule.apply(new StatementSequencer(), null, null));
+
+        expect(styleManager.loadStyleDeclarations2("sheet1.swf", true)).returns(dispatcher).once().inSequence(order);
+
+        styleRule.sequence.evaluate(new AsyncTestToken());
+
+        verify(styleManager);
+
+
+        expect(styleManager.loadStyleDeclarations2("../sheet2.swf", true)).returns(dispatcher).once().inSequence(order);
+
+        dispatcher.dispatchEvent(new StyleEvent(StyleEvent.COMPLETE));
+
+
+        verify(styleManager);
+
+        dispatcher.dispatchEvent(new StyleEvent(StyleEvent.COMPLETE));
+
+
+    }
+}
+}