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 19 /** 20 * Information holder and examiner of a assertTypeOf call. 21 * 22 * @author Martin Heidegger. 23 */ 24 class org.as2lib.test.unit.info.AssertTypeOfInfo extends AbstractAssertInfo { 25 26 /** Internal holder of the variable value. */ 27 private var val; 28 29 /** Internal holder of the type value. */ 30 private var type:String; 31 32 /** 33 * Constructs a new AssertTypeOfInfo. 34 * 35 * @param message Message if the assertion fails. 36 * @param val Value to be checked. 37 * @param type Type of the value 38 */ 39 public function AssertTypeOfInfo(message:String, val, type:String) { 40 super(message); 41 this.val = val; 42 this.type = type; 43 } 44 45 /** 46 * Overriding of @see AbstractAssertInfo#execute 47 * 48 * @return True if the execution fails. 49 */ 50 public function execute(Void):Boolean { 51 return(typeof val != type); 52 } 53 54 /** 55 * Implementation of @see AbstractAssertInfo#getFailureMessage 56 * 57 * @return Message on failure 58 */ 59 private function getFailureMessage(Void):String { 60 var result:String = "assertTypeOf failed"; 61 if(hasMessage()) { 62 result += " with message: "+message; 63 } 64 result += "!\n" 65 + (typeof val) + "(typeof '"+val.toString()+"') != "+type; 66 return result; 67 } 68 69 70 /** 71 * Implementation of @see AbstractAssertInfo#getSuccessMessage 72 * 73 * @return Message on success 74 */ 75 private function getSuccessMessage(Void):String { 76 return ("assertTypeOf executed. (typeof '"+val.toString()+"') == "+type+"."); 77 } 78 }