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.test.unit.AbstractAssertInfo;
    18  import org.as2lib.util.StringUtil;
    19  
    20  /**
    21   * Information holder and examiner of a assertNotSame call.
    22   * 
    23   * @author Martin Heidegger.
    24   */
    25  class org.as2lib.test.unit.info.AssertNotSameInfo extends AbstractAssertInfo {
    26  	
    27  	/** Internal holder of the variable value. */
    28  	private var val;
    29  	
    30  	/** Internal holder of the value to compare. */
    31  	private var compareTo;
    32  	
    33  	/**
    34  	 * Constructs a new AssertNotSameInfo.
    35  	 * 
    36  	 * @param message Message if the assertion fails.
    37  	 * @param val Value to be compared.
    38  	 * @param compareTo Value to be compared with.
    39  	 */
    40  	public function AssertNotSameInfo(message:String, val, compareTo) {
    41  		super(message);
    42  		this.val = val;
    43  		this.compareTo = compareTo;
    44  	}
    45  	
    46  	/**
    47  	 * Overriding of @see AbstractAssertInfo#execute
    48  	 * 
    49  	 * @return True if the execution fails.
    50  	 */
    51  	public function execute(Void):Boolean {
    52  		return(val === compareTo);
    53  	}
    54  	
    55  	/**
    56  	 * Implementation of @see AbstractAssertInfo#getFailureMessage
    57  	 * 
    58  	 * @return Message on failure
    59  	 */
    60  	private function getFailureMessage(Void):String {
    61  		var result:String = "assertNotSame failed";
    62  		if(hasMessage()) {
    63  			result += " with message: "+message;
    64  		}
    65  		var valStr:String;
    66  		try {
    67  			valStr = val.toString();
    68  		} catch (e) {
    69  			valStr = "[object Object]";
    70  		}
    71  		var compareToStr:String; 
    72  		try {
    73  			compareToStr = compareTo.toString();
    74  		} catch (e) {
    75  			compareToStr = "[object Object]";
    76  		}
    77  		result += "!\n"+StringUtil.addSpaceIndent(valStr+" === "+compareToStr, 2);
    78  		return result;
    79  	}
    80  	
    81  	/**
    82  	 * Implementation of @see AbstractAssertInfo#getSuccessMessage
    83  	 * 
    84  	 * @return Message on success
    85  	 */
    86  	private function getSuccessMessage(Void):String {
    87  		return ("assertEquals executed. "+val+" !== "+compareTo+".");
    88  	}
    89  }