Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add mock in composition tests. Make expectedReturnFor() public. Refac…

…tor tests (a bit).

git-svn-id: https://mock4as.googlecode.com/svn/trunk@21 faef3d04-e93e-0410-8cca-bf3cd97b13f1
  • Loading branch information...
commit 8f9186c1070f245d4040d3ae97aa217f0a6eb08e 1 parent a769b86
jpsoulsf@gmail.com authored
View
78 org/mock4as/AllTests.as
@@ -5,6 +5,7 @@ package org.mock4as
import org.mock4as.samples.bank.BankSystemTest;
import org.mock4as.samples.greeting.GreetingTest;
+ import org.mock4as.samples.mockInComposition.test.MockInCompositionTest;
import org.mock4as.samples.publisher.PublisherTest;
public class AllTests extends TestCase
@@ -13,63 +14,28 @@ package org.mock4as
public function AllTests(methodName : String){
super(methodName);
}
-
- public static function suite():TestSuite{
- var myTS:TestSuite = new TestSuite();
- myTS.addTest(new AllTests("testTheTruth"));
-
- // test negative scenarios
- myTS.addTest(new MockTest("testWrongMethodName"));
- myTS.addTest(new MockTest("testWrongFirstArg"));
- myTS.addTest(new MockTest("testWrongSecondArg"));
- myTS.addTest(new MockTest("testWrongThirdArg"));
- myTS.addTest(new MockTest("testWrongArgNumberLessArgs"));
- myTS.addTest(new MockTest("testMethodInvocationMoreTimesThanExpected"));
- myTS.addTest(new MockTest("testMethodInvocationLessTimesThanExpected"));
-
- myTS.addTest(new MockTest("testFailsIfMethodNeverCalled"));
- myTS.addTest(new MockTest("testFailsIfMoreMethodsAreCalledThanExpected"));
- // teest positive scenario
- myTS.addTest(new MockTest("testSuccessMethodInvocation"));
-
-
-
- // mock samples positive tests
- myTS.addTest(new GreetingTest("testGreetingInAnyLanguage"));
- myTS.addTest(new PublisherTest("testOneSubscriberReceivesAMessage"));
- myTS.addTest(new BankSystemTest("testTheTruth"));
- myTS.addTest(new BankSystemTest("testTransferSameCurrency"));
- myTS.addTest(new BankSystemTest("testTransferDifferentCurrency"));
- myTS.addTest(new BankSystemTest("testTransferInsufficientFunds"));
-
- // mock in composition
- // If you don't want to subclass mock (mainly because you want to subclass another class)
- // you can use mock in composition
- //
- myTS.addTest(new MockTest("testSuccess_forAClassUsingMockInComposition_whereExpectedCallsEqualActualCalls_shouldReturnTrue"));
- myTS.addTest(new MockTest("testSuccess_forAClassUsingMockInComposition_whereExpectedCallsDoNotEqualActualCalls_shouldReturnFalse"));
-
- myTS.addTest( new MockTest("testSuccess_whenMoreMethodsAreCalledThanExpected_shouldReturnFalse"));
- myTS.addTest( new MockTest("testSuccess_whenNoMethodsCalledButAtLeastOneExpected_shouldReturnFalse"));
- myTS.addTest( new MockTest("testSuccess_whenExpectedCallsEqualActualCalls_shouldReturnTrue"));
- myTS.addTest( new MockTest("testSuccess_whenExpectedCallsWithExpectedArgsEqualActualCallsWithActualArgs_shouldReturnTrue"));
- myTS.addTest( new MockTest("testSuccess_whenExpectedArgDoesNotEqualActualArg_shouldReturnFalse"));
- myTS.addTest( new MockTest("testSuccess_whenExpected2ndArgDoesNotEqualActual2ndArg_shouldReturnFalse"));
- myTS.addTest( new MockTest("testWillReturn_shouldReturnValueDefinedByTest"));
- myTS.addTest( new MockTest("testWillReturn_shouldReturnTheObjectForTheMethodWithTheExpectedArgs"));
- myTS.addTest( new MockTest("testWillThrow_shouldThrowErrorObjectDefinedByTest"));
- myTS.addTest( new MockTest("testSuccess_whenExpectedMethodIsCalledMultipleTimesWithAtLeastOneUnexpectedArg_shouldFail"));
- myTS.addTest( new MockTest("testSuccess_whenMethodCalledTwiceWithSameExpectedArg_shouldReturnTrue"));
- myTS.addTest( new MockTest("testSuccess_whenMethodNameCalledIsDifferentThanMethodNameExpected_shouldReturnFalse"));
- myTS.addTest( new MockTest("testSuccess_whenMethodNameCalledWithSameArgsButDifferentNameAsMethodExpected_shouldReturnFalse"));
- myTS.addTest( new MockTest("testSuccess_whenLessArgsArePassedThanExpected_shouldReturnFalse"));
- myTS.addTest( new MockTest("testSuccess_whenErrorExpectedAndMethodsCalledAsExpected_shouldReturnTrue"));
- return myTS;
- }
- public function testTheTruth():void{
- assertTrue(true);
- }
+ public static function suite():TestSuite
+ {
+ var testSuite:TestSuite = new TestSuite();
+ testSuite.addTest(new AllTests("testTheTruth"));
+ testSuite.addTest(new GreetingTest("testGreetingInAnyLanguage"));
+ testSuite.addTest(new PublisherTest("testOneSubscriberReceivesAMessage"));
+ testSuite.addTest(new BankSystemTest("testTheTruth"));
+ testSuite.addTest(new BankSystemTest("testTransferSameCurrency"));
+ testSuite.addTest(new BankSystemTest("testTransferDifferentCurrency"));
+ testSuite.addTest(new BankSystemTest("testTransferInsufficientFunds"));
+ testSuite.addTest(MockTest.suite());
+ testSuite.addTest(MockInCompositionTest.suite());
+ return testSuite;
+ }
+
+ public function testTheTruth():void{
+ assertTrue(true);
+ }
+
+
+
}
}
View
2  org/mock4as/Mock.as
@@ -82,7 +82,7 @@ package org.mock4as
}
}
- protected function expectedReturnFor(methodName:String="Depricated"):Object
+ public function expectedReturnFor(methodName:String="Depricated"):Object
{
return currentReturnValue;
}
View
62 org/mock4as/MockTest.as
@@ -1,11 +1,11 @@
package org.mock4as
{
import flexunit.framework.TestCase;
+ import flexunit.framework.TestSuite;
import org.mock4as.samples.MockSomeInterface;
import org.mock4as.samples.greeting.Greeting;
import org.mock4as.samples.greeting.ITranslator;
- import org.mock4as.samples.mockInComposition.MockInComposition;
public class MockTest extends TestCase
{
@@ -17,6 +17,46 @@ package org.mock4as
public function MockTest(methodName : String){
super(methodName);
}
+
+ public static function suite():TestSuite
+ {
+ var testSuite:TestSuite = new TestSuite();
+
+ // test negative scenarios
+ testSuite.addTest(new MockTest("testWrongMethodName"));
+ testSuite.addTest(new MockTest("testWrongFirstArg"));
+ testSuite.addTest(new MockTest("testWrongSecondArg"));
+ testSuite.addTest(new MockTest("testWrongThirdArg"));
+ testSuite.addTest(new MockTest("testWrongArgNumberLessArgs"));
+ testSuite.addTest(new MockTest("testMethodInvocationMoreTimesThanExpected"));
+ testSuite.addTest(new MockTest("testMethodInvocationLessTimesThanExpected"));
+
+ testSuite.addTest(new MockTest("testFailsIfMethodNeverCalled"));
+ testSuite.addTest(new MockTest("testFailsIfMoreMethodsAreCalledThanExpected"));
+ // teest positive scenario
+ testSuite.addTest(new MockTest("testSuccessMethodInvocation"));
+ // mock in composition
+ // If you don't want to subclass mock (mainly because you want to subclass another class)
+ // you can use mock in composition
+ //
+ testSuite.addTest( new MockTest("testSuccess_whenMoreMethodsAreCalledThanExpected_shouldReturnFalse"));
+ testSuite.addTest( new MockTest("testSuccess_whenNoMethodsCalledButAtLeastOneExpected_shouldReturnFalse"));
+ testSuite.addTest( new MockTest("testSuccess_whenExpectedCallsEqualActualCalls_shouldReturnTrue"));
+ testSuite.addTest( new MockTest("testSuccess_whenExpectedCallsWithExpectedArgsEqualActualCallsWithActualArgs_shouldReturnTrue"));
+ testSuite.addTest( new MockTest("testSuccess_whenExpectedArgDoesNotEqualActualArg_shouldReturnFalse"));
+ testSuite.addTest( new MockTest("testSuccess_whenExpected2ndArgDoesNotEqualActual2ndArg_shouldReturnFalse"));
+ testSuite.addTest( new MockTest("testWillReturn_shouldReturnValueDefinedByTest"));
+ testSuite.addTest( new MockTest("testWillReturn_shouldReturnTheObjectForTheMethodWithTheExpectedArgs"));
+ testSuite.addTest( new MockTest("testWillThrow_shouldThrowErrorObjectDefinedByTest"));
+ testSuite.addTest( new MockTest("testSuccess_whenExpectedMethodIsCalledMultipleTimesWithAtLeastOneUnexpectedArg_shouldFail"));
+ testSuite.addTest( new MockTest("testSuccess_whenMethodCalledTwiceWithSameExpectedArg_shouldReturnTrue"));
+ testSuite.addTest( new MockTest("testSuccess_whenMethodNameCalledIsDifferentThanMethodNameExpected_shouldReturnFalse"));
+ testSuite.addTest( new MockTest("testSuccess_whenMethodNameCalledWithSameArgsButDifferentNameAsMethodExpected_shouldReturnFalse"));
+ testSuite.addTest( new MockTest("testSuccess_whenLessArgsArePassedThanExpected_shouldReturnFalse"));
+ testSuite.addTest( new MockTest("testSuccess_whenErrorExpectedAndMethodsCalledAsExpected_shouldReturnTrue"));
+ return testSuite;
+ }
+
public function testFailsIfMethodNeverCalled():void
{
@@ -149,27 +189,7 @@ package org.mock4as
assertFalse(mock.success());
}
- public function testSuccess_forAClassUsingMockInComposition_whereExpectedCallsEqualActualCalls_shouldReturnTrue():void
- {
- var classWithMockInComposition:MockInComposition = new MockInComposition();
- var someStringArg:String = "someStringArg";
- classWithMockInComposition.expects("someMethod").times(1).withArg(someStringArg);
- classWithMockInComposition.someMethod(someStringArg);
- classWithMockInComposition.verify();
- assertTrue(classWithMockInComposition.errorMessage(), classWithMockInComposition.success());
- }
- public function testSuccess_forAClassUsingMockInComposition_whereExpectedCallsDoNotEqualActualCalls_shouldReturnFalse():void
- {
- var classWithMockInComposition:MockInComposition = new MockInComposition();
- var someStringArg:String = "someStringArg";
- classWithMockInComposition.expects("someMethod").times(1).withArg(someStringArg);
- // In this case, we never call the method on the mock
- // but we are expecting someMethod to get called once with someStringArg
- // so success should return false
- classWithMockInComposition.verify();
- assertFalse(classWithMockInComposition.errorMessage(), classWithMockInComposition.success());
- }
public function testSuccess_whenMoreMethodsAreCalledThanExpected_shouldReturnFalse():void
View
26 org/mock4as/samples/mockInComposition/MockInComposition.as
@@ -1,8 +1,9 @@
package org.mock4as.samples.mockInComposition
{
import org.mock4as.Mock;
+ import org.mock4as.samples.ISomeInterface;
- public class MockInComposition extends ClassWeWantToSubclass
+ public class MockInComposition extends ClassWeWantToSubclass implements ISomeInterface
{
private var mock:Mock;
@@ -18,6 +19,29 @@ package org.mock4as.samples.mockInComposition
super.someMethod(inSomeStringArg);
}
+ public function doSomething():void
+ {
+ mock.record("doSomething");
+ }
+ public function anotherMethodWithNoArgs():void
+ {
+ mock.record("anotherMethodWithNoArgs");
+ }
+ public function doSomethingElse(someStringArg:String):void
+ {
+ mock.record("doSomethingElse", someStringArg);
+ }
+
+ public function doSomethingWith2Args(firstArg:String, secondArg:XML):void
+ {
+ mock.record("doSomethingWith2Args", firstArg, secondArg);
+ }
+ public function doSomethingAndReturnXML(inNodeName:String):XML
+ {
+ mock.record("doSomethingAndReturnXML", inNodeName);
+ return mock.expectedReturnFor() as XML;
+ }
+
/*
* If you want to use mock in composition, you will need to support the mock methods below
View
224 org/mock4as/samples/mockInComposition/test/MockInCompositionTest.as
@@ -0,0 +1,224 @@
+package org.mock4as.samples.mockInComposition.test
+{
+ import flexunit.framework.TestCase;
+ import flexunit.framework.TestSuite;
+
+ import org.mock4as.samples.mockInComposition.MockInComposition;
+
+ public class MockInCompositionTest extends TestCase
+ {
+ public function MockInCompositionTest(methodName:String=null)
+ {
+ super(methodName);
+ }
+
+ public static function suite():TestSuite
+ {
+ var testSuite:TestSuite = new TestSuite();
+ testSuite.addTest(new MockInCompositionTest("testSuccess_whereExpectedCallsEqualActualCalls_shouldReturnTrue"));
+ testSuite.addTest(new MockInCompositionTest("testSuccess_whereExpectedCallsDoNotEqualActualCalls_shouldReturnFalse"));
+
+ testSuite.addTest( new MockInCompositionTest("testSuccess_whenMoreMethodsAreCalledThanExpected_shouldReturnFalse"));
+ testSuite.addTest( new MockInCompositionTest("testSuccess_whenNoMethodsCalledButAtLeastOneExpected_shouldReturnFalse"));
+ testSuite.addTest( new MockInCompositionTest("testSuccess_whenExpectedCallsEqualActualCalls_shouldReturnTrue"));
+ testSuite.addTest( new MockInCompositionTest("testSuccess_whenExpectedCallsWithExpectedArgsEqualActualCallsWithActualArgs_shouldReturnTrue"));
+ testSuite.addTest( new MockInCompositionTest("testSuccess_whenExpectedArgDoesNotEqualActualArg_shouldReturnFalse"));
+ testSuite.addTest( new MockInCompositionTest("testSuccess_whenExpected2ndArgDoesNotEqualActual2ndArg_shouldReturnFalse"));
+ testSuite.addTest( new MockInCompositionTest("testWillReturn_shouldReturnValueDefinedByTest"));
+ testSuite.addTest( new MockInCompositionTest("testWillReturn_shouldReturnTheObjectForTheMethodWithTheExpectedArgs"));
+ testSuite.addTest( new MockInCompositionTest("testWillThrow_shouldThrowErrorObjectDefinedByTest"));
+ testSuite.addTest( new MockInCompositionTest("testSuccess_whenExpectedMethodIsCalledMultipleTimesWithAtLeastOneUnexpectedArg_shouldFail"));
+ testSuite.addTest( new MockInCompositionTest("testSuccess_whenMethodCalledTwiceWithSameExpectedArg_shouldReturnTrue"));
+ testSuite.addTest( new MockInCompositionTest("testSuccess_whenMethodNameCalledIsDifferentThanMethodNameExpected_shouldReturnFalse"));
+ testSuite.addTest( new MockInCompositionTest("testSuccess_whenMethodNameCalledWithSameArgsButDifferentNameAsMethodExpected_shouldReturnFalse"));
+ testSuite.addTest( new MockInCompositionTest("testSuccess_whenLessArgsArePassedThanExpected_shouldReturnFalse"));
+ testSuite.addTest( new MockInCompositionTest("testSuccess_whenErrorExpectedAndMethodsCalledAsExpected_shouldReturnTrue"));
+ return testSuite;
+ }
+
+ public function testSuccess_whereExpectedCallsEqualActualCalls_shouldReturnTrue():void
+ {
+ var classWithMockInComposition:MockInComposition = new MockInComposition();
+ var someStringArg:String = "someStringArg";
+ classWithMockInComposition.expects("someMethod").times(1).withArg(someStringArg);
+ classWithMockInComposition.someMethod(someStringArg);
+ classWithMockInComposition.verify();
+ assertTrue(classWithMockInComposition.errorMessage(), classWithMockInComposition.success());
+ }
+
+ public function testSuccess_whereExpectedCallsDoNotEqualActualCalls_shouldReturnFalse():void
+ {
+ var classWithMockInComposition:MockInComposition = new MockInComposition();
+ var someStringArg:String = "someStringArg";
+ classWithMockInComposition.expects("someMethod").times(1).withArg(someStringArg);
+ // In this case, we never call the method on the mock
+ // but we are expecting someMethod to get called once with someStringArg
+ // so success should return false
+ classWithMockInComposition.verify();
+ assertFalse(classWithMockInComposition.errorMessage(), classWithMockInComposition.success());
+ }
+
+ public function testSuccess_whenMoreMethodsAreCalledThanExpected_shouldReturnFalse():void
+ {
+ var mockInComposition:MockInComposition = new MockInComposition();
+ mockInComposition.expects("doSomething").times(1);
+ mockInComposition.doSomething();
+ mockInComposition.doSomethingElse("someString");
+ assertFalse(mockInComposition.errorMessage(), mockInComposition.success());
+ }
+
+ public function testSuccess_whenNoMethodsCalledButAtLeastOneExpected_shouldReturnFalse():void
+ {
+ var mockInComposition:MockInComposition = new MockInComposition();
+ mockInComposition.expects("doSomething").times(1);
+ assertFalse(mockInComposition.errorMessage(), mockInComposition.success());
+ }
+
+ public function testSuccess_whenExpectedCallsEqualActualCalls_shouldReturnTrue():void
+ {
+ var mockInComposition:MockInComposition = new MockInComposition();
+ mockInComposition.expects("doSomething").times(1);
+ mockInComposition.doSomething();
+ assertTrue(mockInComposition.errorMessage(), mockInComposition.success());
+ }
+
+ public function testSuccess_whenExpectedCallsWithExpectedArgsEqualActualCallsWithActualArgs_shouldReturnTrue():void
+ {
+ var mockInComposition:MockInComposition = new MockInComposition();
+ var someStringArg:String = "someStringArg";
+ mockInComposition.expects("doSomethingElse").times(1).withArg(someStringArg);
+ mockInComposition.doSomethingElse(someStringArg);
+ assertTrue(mockInComposition.errorMessage(), mockInComposition.success());
+ }
+
+ public function testSuccess_whenExpectedArgDoesNotEqualActualArg_shouldReturnFalse():void
+ {
+ var mockInComposition:MockInComposition = new MockInComposition();
+ var someStringArg:String = "someStringArg";
+ mockInComposition.expects("doSomethingElse").times(1).withArg("someOtherStringArg");
+ mockInComposition.doSomethingElse(someStringArg);
+ assertFalse(mockInComposition.errorMessage(), mockInComposition.success());
+ }
+
+ public function testSuccess_whenExpected2ndArgDoesNotEqualActual2ndArg_shouldReturnFalse():void
+ {
+ var mockInComposition:MockInComposition = new MockInComposition();
+ var someStringArg:String = "someStringArg";
+ var someUnexpectedStringArg:String = "someUnexpectedStringArg";
+ var someXMLArg:XML = <TEST>test</TEST>;
+ var someUnexpectedXMLArg:XML = <UNEXPECTED/>;
+ mockInComposition.expects("doSomethingWith2Args").times(1).withArgs(someStringArg, someXMLArg);
+ mockInComposition.doSomethingWith2Args(someUnexpectedStringArg, someUnexpectedXMLArg);
+ assertFalse(mockInComposition.errorMessage(), mockInComposition.success());
+ }
+
+
+ public function testWillReturn_shouldReturnValueDefinedByTest():void
+ {
+ var mockInComposition:MockInComposition = new MockInComposition();
+ var someNodeName:String = "someNodeName";
+ var expectedXMLReturnValue:XML = <TEST>test</TEST>;
+ mockInComposition.expects("doSomethingAndReturnXML").withArg(someNodeName).willReturn(expectedXMLReturnValue);
+ var actualXMLReturned:XML = mockInComposition.doSomethingAndReturnXML(someNodeName);
+ assertEquals("Expecting "+expectedXMLReturnValue+" but was: "+actualXMLReturned, expectedXMLReturnValue, actualXMLReturned);
+ }
+
+ public function testWillReturn_shouldReturnTheObjectForTheMethodWithTheExpectedArgs():void
+ {
+ var mockInComposition:MockInComposition = new MockInComposition();
+ var firstNodeName:String = "firstNodeName";
+ var secondNodeName:String = "secondNodeName";
+ var expectedXMLForFirstNodeName:XML = <TEST>firstNodeName</TEST>;
+ var expectedXMLForSecondNodeName:XML = <TEST>secondNodeName</TEST>
+ mockInComposition.expects("doSomethingAndReturnXML").withArg(firstNodeName).willReturn(expectedXMLForFirstNodeName);
+ mockInComposition.expects("doSomethingAndReturnXML").withArg(secondNodeName).willReturn(expectedXMLForSecondNodeName);
+ var actualXMLReturnedForFirstNodeName:XML = mockInComposition.doSomethingAndReturnXML(firstNodeName);
+ var actualXMLReturnedForSecondNodeName:XML = mockInComposition.doSomethingAndReturnXML(secondNodeName);
+ assertEquals("", expectedXMLForFirstNodeName, actualXMLReturnedForFirstNodeName);
+ assertEquals("", expectedXMLForSecondNodeName, actualXMLReturnedForSecondNodeName);
+ }
+
+ public function testWillThrow_shouldThrowErrorObjectDefinedByTest():void
+ {
+ var mockInComposition:MockInComposition = new MockInComposition();
+ var someNodeName:String = "someNodeName";
+ var expectedMessage:String = "Mock message thrown.";
+ mockInComposition.expects("doSomething").willThrow(new Error(expectedMessage));
+ try
+ {
+ mockInComposition.doSomething();
+ }
+ catch (e:Error)
+ {
+ assertEquals("Expecting "+expectedMessage+" but was: "+e.message, expectedMessage, e.message);
+ return;
+ }
+ fail("Expecting error to be thrown but none was thrown.");
+ }
+
+ public function testSuccess_whenExpectedMethodIsCalledMultipleTimesWithAtLeastOneUnexpectedArg_shouldFail():void
+ {
+ var mockInComposition:MockInComposition = new MockInComposition();
+ var firstArgValue:String = "firstArgValue";
+ var secondArgValue:String = "secondArgValue";
+ mockInComposition.expects("doSomethingElse").times(1).withArg(firstArgValue);
+ mockInComposition.expects("doSomethingElse").times(1).withArg(secondArgValue);
+ mockInComposition.doSomethingElse(firstArgValue);
+ mockInComposition.doSomethingElse("someUnexpectedArg");
+ assertFalse("mockInComposition.success() should fail because the second time we called the method we passed an unexpected arg", mockInComposition.success());
+ }
+
+ public function testSuccess_whenMethodCalledTwiceWithSameExpectedArg_shouldReturnTrue():void
+ {
+ var mockInComposition:MockInComposition = new MockInComposition();
+ var firstArgValue:String = "firstArgValue";
+ var secondArgValue:String = "secondArgValue";
+ mockInComposition.expects("doSomethingElse").times(2).withArg(firstArgValue);
+ mockInComposition.doSomethingElse(firstArgValue);
+ mockInComposition.doSomethingElse(firstArgValue);
+ assertTrue(mockInComposition.errorMessage(), mockInComposition.success());
+ }
+
+ public function testSuccess_whenMethodNameCalledIsDifferentThanMethodNameExpected_shouldReturnFalse():void
+ {
+ var mockInComposition:MockInComposition = new MockInComposition();
+ mockInComposition.expects("doSomething").times(1);
+ mockInComposition.anotherMethodWithNoArgs();
+ assertFalse(mockInComposition.errorMessage(), mockInComposition.success());
+ }
+
+ public function testSuccess_whenMethodNameCalledWithSameArgsButDifferentNameAsMethodExpected_shouldReturnFalse():void
+ {
+ var mockInComposition:MockInComposition = new MockInComposition();
+ var someStringArg:String = "someStringArg";
+ mockInComposition.expects("doSomethingElse").times(1).withArg(someStringArg);
+ mockInComposition.doSomethingAndReturnXML("someStringArg");
+ assertFalse(mockInComposition.errorMessage(), mockInComposition.success());
+ }
+
+ public function testSuccess_whenLessArgsArePassedThanExpected_shouldReturnFalse():void
+ {
+ var mockInComposition:MockInComposition = new MockInComposition();
+ var someStringArg:String = "someStringArg";
+ mockInComposition.expects("doSomethingAndReturnXML").times(1);
+ mockInComposition.doSomethingAndReturnXML("someStringArg");
+ assertFalse(mockInComposition.errorMessage(), mockInComposition.success());
+ }
+
+ public function testSuccess_whenErrorExpectedAndMethodsCalledAsExpected_shouldReturnTrue():void
+ {
+ var mockInComposition:MockInComposition = new MockInComposition();
+ mockInComposition.expects("doSomething").times(1).willThrow(new Error("customError"));
+ try
+ {
+ mockInComposition.doSomething();
+ fail("expecting error but none was thrown");
+ }
+ catch (e:Error)
+ {
+ assertTrue(mockInComposition.errorMessage(), mockInComposition.success());
+ }
+ }
+
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.