API Documentation | All Packages | All Classes | Index | Frames No Frames |
ExpectException

Package | org.flexunit.internals.runners.statements
Class | public class ExpectException
Inheritance | ExpectException AsyncStatementBase Object
Implements | IAsyncStatement

The `ExpectException` is a decorator that is responsible for determing whether a specific test method throws an expected exception. Normally, if a test method throws an specific exception, the test will fail; however, if the test is expecting a specific exception and that exception is thrown, the test will be a success. If an exception is expected and is not encountered through the course of running the test, the test will be considered a failure. In order to expect an exception, a test method must include metadata indicating it is expecting an exception. The exception that it is expecting must be in the form of the qualified class name of the exception class.

    	 [Test(expected="org.flexunit.runner.notification.StoppedByUserException")]
    	 public function exceptionTest():void {
    	 	//Test will throw a StoppedByUserException
    	 }

Protected Properties
Hide Inherited Protected Properties
Show Inherited Protected Properties

| Property | Defined By
--- | --- | ---
|  | myToken : AsyncTestToken The AsyncTestToken for the current statment. | AsyncStatementBase
|  | parentToken : AsyncTestToken The AsyncTestToken for the parent of the current statment. | AsyncStatementBase

Public Methods

| Method | Defined By
--- | --- | ---
|  | ExpectException(exceptionName:String, statement:IAsyncStatement) Constructor. | ExpectException
|  | evaluate(parentToken:AsyncTestToken):void Evaluates the object that implements the IAsyncStatement and checks to see if an exception is thrown by that IAsyncStatement. | ExpectException
|  | handleNextExecuteComplete(result:ChildResult):void Determines if the excpetion in the result contains an exception that is of the expected type. | ExpectException
|  | hasExpected(method:FrameworkMethod):String [static] Determine if a method test is expecting an exception by checking its metadata to see if it contains either an "expects" or "expected" string. | ExpectException

Protected Methods
Show Inherited Protected Methods
Show Inherited Protected Methods

| Method | Defined By
--- | --- | ---
|  | sendComplete(error:Error = null):void If the parentToken has not already been alerted that the statement has completed, alert the parent token that the current statement has finished. | AsyncStatementBase

Constructor Detail

ExpectException | () | Constructor

`public function ExpectException(exceptionName:String, statement:IAsyncStatement)`

Constructor.

Parameters

| `exceptionName:String` — The qualified class name of the exception to expect.
| `statement:IAsyncStatement` — The current object that implements `IAsyncStatement` to decorate.

Method Detail

evaluate | () | method

`public function evaluate(parentToken:AsyncTestToken):void`

Evaluates the object that implements the `IAsyncStatement` and checks to see if an exception is thrown by that `IAsyncStatement`. If an exception is thrown, check to see if the error is of the expected type.

Parameters

| `parentToken:AsyncTestToken` — The token to be notified when the check for an exception being thrown has finished.

handleNextExecuteComplete | () | method |

`public function handleNextExecuteComplete(result:ChildResult):void`

Determines if the excpetion in the `result` contains an exception that is of the expected type. If the exception is not of the expected type, an error will be generated that includes the type of error that was encountered. If no exception was thrown, a new error will be created because an excpetion should have been thrown in this instance.

Parameters

| `result:ChildResult` — The `ChildResult` to check to see if there is an error was provided.

hasExpected | () | method |

`public static function hasExpected(method:FrameworkMethod):String`

Determine if a `method` test is expecting an exception by checking its metadata to see if it contains either an "expects" or "expected" string.

Parameters

| `method:FrameworkMethod` — The `FrameworkMethod` to check to see if its expecting an exception.

Returns

| `String` — a String containing the qualified path name of the expected exception if the `method` contains metadata that indicates the method is expecting an exception; otherwise, a value of `null` will be returned.

Thu Apr 10 2014, 08:07 AM +10:00