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