Wednesday, May 13, 2009

FlexUnit assertNotEquals

why is there an assertEquals and no assertNotEquals in FlexUnit ?
there may be a reasonable explanation, but anyway I needed it, so here it is in case someone searches for that

here is my AssertWithNotEquals.as :

package flexunit.framework
{
public class AssertWithNotEquals extends Assert
{
public static function assertNotEquals(...rest):void
{
if ( rest.length == 3 ){
failEquals( rest[0], rest[1], rest[2] );
}else{
failEquals( "", rest[0], rest[1] );
}
}

private static function failEquals( message:String, expected:Object, actual:Object ):void
{
if ( expected == actual )
{
if ( message.length > 0 ) message = message + " - ";
throw new AssertionFailedError( message + " expected not to be the same, but was <" + actual + ">" );
}
}
}
}