1  /**
     2   * Copyright the original author or authors.
     3   * 
     4   * Licensed under the MOZILLA PUBLIC LICENSE, Version 1.1 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   * 
     8   *      http://www.mozilla.org/MPL/MPL-1.1.html
     9   * 
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16   
    17  import org.as2lib.core.BasicClass;
    18  import org.as2lib.test.unit.ExecutionInfo;
    19  import org.as2lib.env.except.AbstractOperationException;
    20  
    21  /**
    22   * Implementation of @see ExecutionInfo as basis for all AssertInformations.
    23   * 
    24   * @autor Martin Heidegger
    25   */
    26  class org.as2lib.test.unit.AbstractAssertInfo extends BasicClass implements ExecutionInfo {
    27  	
    28  	/** True if the execution has failed. */
    29  	private var failed:Boolean;
    30  	
    31  	/** True if the assertion has been executed. */
    32  	private var executed:Boolean;
    33  	
    34  	/** Message applied to the assertion. */
    35  	private var message:String;
    36  	
    37  	/**
    38  	 * Constructs a new AbstractAssertInfo.
    39  	 * 
    40  	 * @param message Message for the AssertInformation.
    41  	 */
    42  	public function AbstractAssertInfo(message:String) {
    43  		this.message = message;
    44  		executed = false;
    45  		failed = false;
    46  	}
    47  	
    48  	/**
    49  	 * @return true if the assertion failed.
    50  	 */
    51  	public function isFailed(Void):Boolean {
    52  		if(!executed) {
    53  			failed = execute();
    54  			executed = true;
    55  		}
    56  		return failed;
    57  	}
    58  	
    59  	/**
    60  	 * Template method to be overwritten. This will be called by the first
    61  	 * time if isFailed() was executed.
    62  	 * 
    63  	 * Note: The method failes by standard.
    64  	 *
    65  	 * @return true if the execution failed, false if it didn't.
    66  	 */
    67  	private function execute(Void):Boolean {
    68  		return true;
    69  	}
    70  	
    71  	/**
    72  	 * Information getter if a message has been applied to the information.
    73  	 * 
    74  	 * Only for internal use. It applies in all/most extended classes.
    75  	 * 
    76  	 * @return true if a message has been applied to the infromation.
    77  	 */
    78  	private function hasMessage(Void):Boolean {
    79  		return(message.length > 0);
    80  	}
    81  	
    82  	
    83  	/**
    84  	 * @return The message if the assertion doesn't fail.
    85  	 */
    86  	private function getFailureMessage(Void):String {
    87  		throw new AbstractOperationException("getFailureMessage() is ment to be extended.", this, arguments);
    88  		return "";
    89  	}
    90  	
    91  	/**
    92  	 * @return The message if the assertion doesn't fail.
    93  	 */
    94  	private function getSuccessMessage(Void):String {
    95  		throw new AbstractOperationException("getSuccessMessage() is ment to be extended.", this, arguments);
    96  		return "";
    97  	}
    98  	
    99  	/**
   100  	 * Returns the message to the assertion.
   101  	 * If this assertion failed it should return the errorinfo, else the successinfo.
   102  	 * 
   103  	 * @return Message to the assertion.
   104  	 */
   105  	public function getMessage(Void):String {
   106  		if(isFailed()) {
   107  			return getFailureMessage();
   108  		} else {
   109  			return getSuccessMessage();
   110  		}
   111  	}
   112  }