1*cdf0e10cSrcweir /* 2*cdf0e10cSrcweir * ************************************************************************ 3*cdf0e10cSrcweir * 4*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5*cdf0e10cSrcweir * 6*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 7*cdf0e10cSrcweir * 8*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 9*cdf0e10cSrcweir * 10*cdf0e10cSrcweir * This file is part of OpenOffice.org. 11*cdf0e10cSrcweir * 12*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 13*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 14*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 15*cdf0e10cSrcweir * 16*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 17*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 18*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 20*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 21*cdf0e10cSrcweir * 22*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 23*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 24*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 25*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 26*cdf0e10cSrcweir * 27*cdf0e10cSrcweir * *********************************************************************** 28*cdf0e10cSrcweir */ 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir package complexlib; 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir import java.lang.reflect.InvocationTargetException; 33*cdf0e10cSrcweir import java.lang.reflect.Method; 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir /** 36*cdf0e10cSrcweir * 37*cdf0e10cSrcweir * @author ll93751 38*cdf0e10cSrcweir * 39*cdf0e10cSrcweir * I have removed the assure(...) functions from ComplexTestCase due to the fact now I can 40*cdf0e10cSrcweir * use the functions every where and don't need to be a ComplexTestCase any longer. 41*cdf0e10cSrcweir */ 42*cdf0e10cSrcweir public class Assurance 43*cdf0e10cSrcweir { 44*cdf0e10cSrcweir public static final boolean CONTINUE = true; 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir /** State of the current test method **/ 47*cdf0e10cSrcweir protected boolean state = true; 48*cdf0e10cSrcweir 49*cdf0e10cSrcweir /** The message if the test did fail **/ 50*cdf0e10cSrcweir protected String message = null; 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir /** 54*cdf0e10cSrcweir * Assure that s is true. 55*cdf0e10cSrcweir * This function generates "Assure failed." as standard message. 56*cdf0e10cSrcweir * @param s The condition that should be true. 57*cdf0e10cSrcweir */ 58*cdf0e10cSrcweir protected void assure(boolean s) { 59*cdf0e10cSrcweir assure("Assure failed.", s, false); 60*cdf0e10cSrcweir } 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir /** 63*cdf0e10cSrcweir * Assure that s is true. 64*cdf0e10cSrcweir * The given message will be only evaluated, if s is false. 65*cdf0e10cSrcweir * @param msg The message that is evaluated. 66*cdf0e10cSrcweir * @param s The condition that should be true. 67*cdf0e10cSrcweir */ 68*cdf0e10cSrcweir protected void assure(String msg, boolean s) { 69*cdf0e10cSrcweir assure(msg, s, false); 70*cdf0e10cSrcweir } 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir /** 73*cdf0e10cSrcweir * Assure that two boolean values are equal 74*cdf0e10cSrcweir * @param expected specifies the expected boolean value 75*cdf0e10cSrcweir * @param actual specifies the actual boolean value 76*cdf0e10cSrcweir */ 77*cdf0e10cSrcweir protected void assureEquals( boolean expected, boolean actual ) { 78*cdf0e10cSrcweir assureEquals( "Equality test failed", expected, new Boolean( actual ), false ); 79*cdf0e10cSrcweir } 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir /** 82*cdf0e10cSrcweir * Assure that two boolean values are equal 83*cdf0e10cSrcweir * @param message the message to print when the equality test fails 84*cdf0e10cSrcweir * @param expected specifies the expected boolean value 85*cdf0e10cSrcweir * @param actual specifies the actual boolean value 86*cdf0e10cSrcweir */ 87*cdf0e10cSrcweir protected void assureEquals( String message, boolean expected, boolean actual ) { 88*cdf0e10cSrcweir assureEquals( message, expected, actual, false ); 89*cdf0e10cSrcweir } 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir /** 92*cdf0e10cSrcweir * Assure that two byte values are equal 93*cdf0e10cSrcweir * @param expected specifies the expected byte value 94*cdf0e10cSrcweir * @param actual specifies the actual byte value 95*cdf0e10cSrcweir */ 96*cdf0e10cSrcweir protected void assureEquals( byte expected, byte actual ) { 97*cdf0e10cSrcweir assureEquals( "Equality test failed", new Byte( expected ), new Byte( actual ), false ); 98*cdf0e10cSrcweir } 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir /** 101*cdf0e10cSrcweir * Assure that two byte values are equal 102*cdf0e10cSrcweir * @param message the message to print when the equality test fails 103*cdf0e10cSrcweir * @param expected specifies the expected byte value 104*cdf0e10cSrcweir * @param actual specifies the actual byte value 105*cdf0e10cSrcweir */ 106*cdf0e10cSrcweir protected void assureEquals( String message, byte expected, byte actual ) { 107*cdf0e10cSrcweir assureEquals( message, new Byte( expected ), new Byte( actual ), false ); 108*cdf0e10cSrcweir } 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir /** 111*cdf0e10cSrcweir * Assure that two double values are equal 112*cdf0e10cSrcweir * @param expected specifies the expected double value 113*cdf0e10cSrcweir * @param actual specifies the actual double value 114*cdf0e10cSrcweir */ 115*cdf0e10cSrcweir protected void assureEquals( double expected, double actual ) { 116*cdf0e10cSrcweir assureEquals( "Equality test failed", new Double( expected ), new Double( actual ), false ); 117*cdf0e10cSrcweir } 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir /** 120*cdf0e10cSrcweir * Assure that two double values are equal 121*cdf0e10cSrcweir * @param message the message to print when the equality test fails 122*cdf0e10cSrcweir * @param expected specifies the expected double value 123*cdf0e10cSrcweir * @param actual specifies the actual double value 124*cdf0e10cSrcweir */ 125*cdf0e10cSrcweir protected void assureEquals( String message, double expected, double actual ) { 126*cdf0e10cSrcweir assureEquals( message, new Double( expected ), new Double( actual ), false ); 127*cdf0e10cSrcweir } 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir /** 130*cdf0e10cSrcweir * Assure that two float values are equal 131*cdf0e10cSrcweir * @param expected specifies the expected float value 132*cdf0e10cSrcweir * @param actual specifies the actual float value 133*cdf0e10cSrcweir */ 134*cdf0e10cSrcweir protected void assureEquals( float expected, float actual ) { 135*cdf0e10cSrcweir assureEquals( "Equality test failed", new Float( expected ), new Float( actual ), false ); 136*cdf0e10cSrcweir } 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir /** 139*cdf0e10cSrcweir * Assure that two float values are equal 140*cdf0e10cSrcweir * @param message the message to print when the equality test fails 141*cdf0e10cSrcweir * @param expected specifies the expected float value 142*cdf0e10cSrcweir * @param actual specifies the actual float value 143*cdf0e10cSrcweir */ 144*cdf0e10cSrcweir protected void assureEquals( String message, float expected, float actual ) { 145*cdf0e10cSrcweir assureEquals( message, new Float( expected ), new Float( actual ), false ); 146*cdf0e10cSrcweir } 147*cdf0e10cSrcweir 148*cdf0e10cSrcweir /** 149*cdf0e10cSrcweir * Assure that two short values are equal 150*cdf0e10cSrcweir * @param expected specifies the expected short value 151*cdf0e10cSrcweir * @param actual specifies the actual short value 152*cdf0e10cSrcweir */ 153*cdf0e10cSrcweir protected void assureEquals( short expected, short actual ) { 154*cdf0e10cSrcweir assureEquals( "Equality test failed", new Short( expected ), new Short( actual ), false ); 155*cdf0e10cSrcweir } 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir /** 158*cdf0e10cSrcweir * Assure that two short values are equal 159*cdf0e10cSrcweir * @param message the message to print when the equality test fails 160*cdf0e10cSrcweir * @param expected specifies the expected short value 161*cdf0e10cSrcweir * @param actual specifies the actual short value 162*cdf0e10cSrcweir */ 163*cdf0e10cSrcweir protected void assureEquals( String message, short expected, short actual ) { 164*cdf0e10cSrcweir assureEquals( message, new Short( expected ), new Short( actual ), false ); 165*cdf0e10cSrcweir } 166*cdf0e10cSrcweir 167*cdf0e10cSrcweir /** 168*cdf0e10cSrcweir * Assure that two int values are equal 169*cdf0e10cSrcweir * @param expected specifies the expected int value 170*cdf0e10cSrcweir * @param actual specifies the actual int value 171*cdf0e10cSrcweir */ 172*cdf0e10cSrcweir protected void assureEquals( int expected, int actual ) { 173*cdf0e10cSrcweir assureEquals( "Equality test failed", new Integer( expected ), new Integer( actual ), false ); 174*cdf0e10cSrcweir } 175*cdf0e10cSrcweir 176*cdf0e10cSrcweir /** 177*cdf0e10cSrcweir * Assure that two int values are equal 178*cdf0e10cSrcweir * @param message the message to print when the equality test fails 179*cdf0e10cSrcweir * @param expected specifies the expected int value 180*cdf0e10cSrcweir * @param actual specifies the actual int value 181*cdf0e10cSrcweir */ 182*cdf0e10cSrcweir protected void assureEquals( String message, int expected, int actual ) { 183*cdf0e10cSrcweir assureEquals( message, new Integer( expected ), new Integer( actual ), false ); 184*cdf0e10cSrcweir } 185*cdf0e10cSrcweir 186*cdf0e10cSrcweir /** 187*cdf0e10cSrcweir * Assure that two long values are equal 188*cdf0e10cSrcweir * @param expected specifies the expected long value 189*cdf0e10cSrcweir * @param actual specifies the actual long value 190*cdf0e10cSrcweir */ 191*cdf0e10cSrcweir protected void assureEquals( long expected, long actual ) { 192*cdf0e10cSrcweir assureEquals( "Equality test failed", new Long( expected ), new Long( actual ), false ); 193*cdf0e10cSrcweir } 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir /** 196*cdf0e10cSrcweir * Assure that two long values are equal 197*cdf0e10cSrcweir * @param message the message to print when the equality test fails 198*cdf0e10cSrcweir * @param expected specifies the expected long value 199*cdf0e10cSrcweir * @param actual specifies the actual long value 200*cdf0e10cSrcweir */ 201*cdf0e10cSrcweir protected void assureEquals( String message, long expected, long actual ) { 202*cdf0e10cSrcweir assureEquals( message, new Long( expected ), new Long( actual ), false ); 203*cdf0e10cSrcweir } 204*cdf0e10cSrcweir 205*cdf0e10cSrcweir /** 206*cdf0e10cSrcweir * Assure that two string values are equal 207*cdf0e10cSrcweir * @param expected specifies the expected string value 208*cdf0e10cSrcweir * @param actual specifies the actual string value 209*cdf0e10cSrcweir */ 210*cdf0e10cSrcweir protected void assureEquals( String expected, String actual ) { 211*cdf0e10cSrcweir assureEquals( "Equality test failed", expected, actual, false ); 212*cdf0e10cSrcweir } 213*cdf0e10cSrcweir 214*cdf0e10cSrcweir /** 215*cdf0e10cSrcweir * Assure that two string values are equal 216*cdf0e10cSrcweir * @param message the message to print when the equality test fails 217*cdf0e10cSrcweir * @param expected specifies the expected string value 218*cdf0e10cSrcweir * @param actual specifies the actual string value 219*cdf0e10cSrcweir */ 220*cdf0e10cSrcweir protected void assureEquals( String message, String expected, String actual ) { 221*cdf0e10cSrcweir assureEquals( message, expected, actual, false ); 222*cdf0e10cSrcweir } 223*cdf0e10cSrcweir 224*cdf0e10cSrcweir /** 225*cdf0e10cSrcweir * Assure that two object are equal 226*cdf0e10cSrcweir * @param expected specifies the expected object value 227*cdf0e10cSrcweir * @param actual specifies the actual object value 228*cdf0e10cSrcweir */ 229*cdf0e10cSrcweir protected void assureEquals( Object expected, Object actual ) { 230*cdf0e10cSrcweir assureEquals( "Equality test failed", expected, actual, false ); 231*cdf0e10cSrcweir } 232*cdf0e10cSrcweir 233*cdf0e10cSrcweir /** 234*cdf0e10cSrcweir * Assure that two objects are equal 235*cdf0e10cSrcweir * @param message the message to print when the equality test fails 236*cdf0e10cSrcweir * @param expected specifies the expected object value 237*cdf0e10cSrcweir * @param actual specifies the actual object value 238*cdf0e10cSrcweir */ 239*cdf0e10cSrcweir protected void assureEquals( String message, Object expected, Object actual ) { 240*cdf0e10cSrcweir assureEquals( message, expected, actual, false ); 241*cdf0e10cSrcweir } 242*cdf0e10cSrcweir 243*cdf0e10cSrcweir /** 244*cdf0e10cSrcweir * assures the two given sequences are of equal length, and have equal content 245*cdf0e10cSrcweir */ 246*cdf0e10cSrcweir public <T> void assureEquals( String i_message, T[] i_expected, T[] i_actual, boolean i_continue ) 247*cdf0e10cSrcweir { 248*cdf0e10cSrcweir if ( i_expected.length != i_actual.length ) 249*cdf0e10cSrcweir failed( i_message + ": expected element count: " + i_expected.length + ", actual element count: " + i_actual.length ); 250*cdf0e10cSrcweir for ( int i=0; i<i_expected.length; ++i ) 251*cdf0e10cSrcweir { 252*cdf0e10cSrcweir assureEquals( i_message + ": mismatch at element pos " + i, i_expected[i], i_actual[i], i_continue ); 253*cdf0e10cSrcweir } 254*cdf0e10cSrcweir } 255*cdf0e10cSrcweir 256*cdf0e10cSrcweir /** 257*cdf0e10cSrcweir * assures the two given sequences are of equal length, and have equal content 258*cdf0e10cSrcweir */ 259*cdf0e10cSrcweir public <T> void assureEquals( String i_message, T[] i_expected, T[] i_actual ) 260*cdf0e10cSrcweir { 261*cdf0e10cSrcweir assureEquals( i_message, i_expected, i_actual, false ); 262*cdf0e10cSrcweir } 263*cdf0e10cSrcweir 264*cdf0e10cSrcweir /** invokes a given method on a given object, and assures a certain exception is caught 265*cdf0e10cSrcweir * @param _message is the message to print when the check fails 266*cdf0e10cSrcweir * @param _object is the object to invoke the method on 267*cdf0e10cSrcweir * @param _methodName is the name of the method to invoke 268*cdf0e10cSrcweir * @param _methodArgs are the arguments to pass to the method. 269*cdf0e10cSrcweir * @param _argClasses are the classes to assume for the arguments of the methods 270*cdf0e10cSrcweir * @param _expectedExceptionClass is the class of the exception to be caught. If this is null, 271*cdf0e10cSrcweir * it means that <em>no</em> exception must be throw by invoking the method. 272*cdf0e10cSrcweir */ 273*cdf0e10cSrcweir protected void assureException( final String _message, final Object _object, final String _methodName, 274*cdf0e10cSrcweir final Class[] _argClasses, final Object[] _methodArgs, final Class _expectedExceptionClass ) 275*cdf0e10cSrcweir { 276*cdf0e10cSrcweir Class objectClass = _object.getClass(); 277*cdf0e10cSrcweir 278*cdf0e10cSrcweir boolean noExceptionAllowed = ( _expectedExceptionClass == null ); 279*cdf0e10cSrcweir 280*cdf0e10cSrcweir boolean caughtExpected = noExceptionAllowed ? true : false; 281*cdf0e10cSrcweir try 282*cdf0e10cSrcweir { 283*cdf0e10cSrcweir Method method = objectClass.getMethod( _methodName, _argClasses ); 284*cdf0e10cSrcweir method.invoke(_object, _methodArgs ); 285*cdf0e10cSrcweir } 286*cdf0e10cSrcweir catch ( InvocationTargetException e ) 287*cdf0e10cSrcweir { 288*cdf0e10cSrcweir caughtExpected = noExceptionAllowed 289*cdf0e10cSrcweir ? false 290*cdf0e10cSrcweir : ( e.getTargetException().getClass().equals( _expectedExceptionClass ) ); 291*cdf0e10cSrcweir } 292*cdf0e10cSrcweir catch( Exception e ) 293*cdf0e10cSrcweir { 294*cdf0e10cSrcweir caughtExpected = false; 295*cdf0e10cSrcweir } 296*cdf0e10cSrcweir 297*cdf0e10cSrcweir assure( _message, caughtExpected ); 298*cdf0e10cSrcweir } 299*cdf0e10cSrcweir 300*cdf0e10cSrcweir /** invokes a given method on a given object, and assures a certain exception is caught 301*cdf0e10cSrcweir * @param _message is the message to print when the check fails 302*cdf0e10cSrcweir * @param _object is the object to invoke the method on 303*cdf0e10cSrcweir * @param _methodName is the name of the method to invoke 304*cdf0e10cSrcweir * @param _methodArgs are the arguments to pass to the method. Those implicitly define 305*cdf0e10cSrcweir * the classes of the arguments of the method which is called. 306*cdf0e10cSrcweir * @param _expectedExceptionClass is the class of the exception to be caught. If this is null, 307*cdf0e10cSrcweir * it means that <em>no</em> exception must be throw by invoking the method. 308*cdf0e10cSrcweir */ 309*cdf0e10cSrcweir protected void assureException( final String _message, final Object _object, final String _methodName, 310*cdf0e10cSrcweir final Object[] _methodArgs, final Class _expectedExceptionClass ) 311*cdf0e10cSrcweir { 312*cdf0e10cSrcweir Class[] argClasses = new Class[ _methodArgs.length ]; 313*cdf0e10cSrcweir for ( int i=0; i<_methodArgs.length; ++i ) 314*cdf0e10cSrcweir argClasses[i] = _methodArgs[i].getClass(); 315*cdf0e10cSrcweir assureException( _message, _object, _methodName, argClasses, _methodArgs, _expectedExceptionClass ); 316*cdf0e10cSrcweir } 317*cdf0e10cSrcweir 318*cdf0e10cSrcweir /** invokes a given method on a given object, and assures a certain exception is caught 319*cdf0e10cSrcweir * @param _object is the object to invoke the method on 320*cdf0e10cSrcweir * @param _methodName is the name of the method to invoke 321*cdf0e10cSrcweir * @param _methodArgs are the arguments to pass to the method. Those implicitly define 322*cdf0e10cSrcweir * the classes of the arguments of the method which is called. 323*cdf0e10cSrcweir * @param _expectedExceptionClass is the class of the exception to be caught. If this is null, 324*cdf0e10cSrcweir * it means that <em>no</em> exception must be throw by invoking the method. 325*cdf0e10cSrcweir */ 326*cdf0e10cSrcweir protected void assureException( final Object _object, final String _methodName, final Object[] _methodArgs, 327*cdf0e10cSrcweir final Class _expectedExceptionClass ) 328*cdf0e10cSrcweir { 329*cdf0e10cSrcweir assureException( 330*cdf0e10cSrcweir "did not catch the expected exception (" + 331*cdf0e10cSrcweir ( ( _expectedExceptionClass == null ) ? "none" : _expectedExceptionClass.getName() ) + 332*cdf0e10cSrcweir ") while calling " + _object.getClass().getName() + "." + _methodName, 333*cdf0e10cSrcweir _object, _methodName, _methodArgs, _expectedExceptionClass ); 334*cdf0e10cSrcweir } 335*cdf0e10cSrcweir 336*cdf0e10cSrcweir /** invokes a given method on a given object, and assures a certain exception is caught 337*cdf0e10cSrcweir * @param _object is the object to invoke the method on 338*cdf0e10cSrcweir * @param _methodName is the name of the method to invoke 339*cdf0e10cSrcweir * @param _methodArgs are the arguments to pass to the method 340*cdf0e10cSrcweir * @param _argClasses are the classes to assume for the arguments of the methods 341*cdf0e10cSrcweir * @param _expectedExceptionClass is the class of the exception to be caught. If this is null, 342*cdf0e10cSrcweir * it means that <em>no</em> exception must be throw by invoking the method. 343*cdf0e10cSrcweir */ 344*cdf0e10cSrcweir protected void assureException( final Object _object, final String _methodName, final Class[] _argClasses, 345*cdf0e10cSrcweir final Object[] _methodArgs, final Class _expectedExceptionClass ) 346*cdf0e10cSrcweir { 347*cdf0e10cSrcweir assureException( 348*cdf0e10cSrcweir "did not catch the expected exception (" + 349*cdf0e10cSrcweir ( ( _expectedExceptionClass == null ) ? "none" : _expectedExceptionClass.getName() ) + 350*cdf0e10cSrcweir ") while calling " + _object.getClass().getName() + "." + _methodName, 351*cdf0e10cSrcweir _object, _methodName, _argClasses, _methodArgs, _expectedExceptionClass ); 352*cdf0e10cSrcweir } 353*cdf0e10cSrcweir 354*cdf0e10cSrcweir /** 355*cdf0e10cSrcweir * Mark the currently executed method as failed. 356*cdf0e10cSrcweir * This function generates "Test did fail." as standard message. 357*cdf0e10cSrcweir */ 358*cdf0e10cSrcweir protected void failed() { 359*cdf0e10cSrcweir assure("Test did fail.", false, false); 360*cdf0e10cSrcweir } 361*cdf0e10cSrcweir 362*cdf0e10cSrcweir /** 363*cdf0e10cSrcweir * Mark the currently executed method as failed. 364*cdf0e10cSrcweir * with the given message. 365*cdf0e10cSrcweir * @param msg The message of the failure. 366*cdf0e10cSrcweir */ 367*cdf0e10cSrcweir protected void failed(String msg) { 368*cdf0e10cSrcweir assure(msg, false, false); 369*cdf0e10cSrcweir } 370*cdf0e10cSrcweir 371*cdf0e10cSrcweir /** 372*cdf0e10cSrcweir * Assure that s is true. 373*cdf0e10cSrcweir * The given message will be only evaluated, if s is false. 374*cdf0e10cSrcweir * Normally, assure() leaves the current test method, and the next one 375*cdf0e10cSrcweir * is executed. With the parameter 'cont' set to true, the current test 376*cdf0e10cSrcweir * method will continue.<br> 377*cdf0e10cSrcweir * The current method will of course marked as failed. 378*cdf0e10cSrcweir * @param msg The message that is evaluated. 379*cdf0e10cSrcweir * @param s The condition that should be true. 380*cdf0e10cSrcweir * @param cont Continue with test method, even if s is false. 381*cdf0e10cSrcweir */ 382*cdf0e10cSrcweir protected void assure(String msg, boolean s, boolean cont) { 383*cdf0e10cSrcweir state &= s; 384*cdf0e10cSrcweir if (!s) { 385*cdf0e10cSrcweir message += msg + "\r\n"; 386*cdf0e10cSrcweir // log.println(msg); 387*cdf0e10cSrcweir if (!cont) { 388*cdf0e10cSrcweir throw new AssureException(msg); 389*cdf0e10cSrcweir } 390*cdf0e10cSrcweir } 391*cdf0e10cSrcweir } 392*cdf0e10cSrcweir 393*cdf0e10cSrcweir protected void assureEquals( String message, Object expected, Object actual, boolean cont ) { 394*cdf0e10cSrcweir assure( message + " (expected: " + expected.toString() + ", actual: " + actual.toString() + ")", 395*cdf0e10cSrcweir expected.equals( actual ), cont ); 396*cdf0e10cSrcweir } 397*cdf0e10cSrcweir 398*cdf0e10cSrcweir /** 399*cdf0e10cSrcweir * Mark the currently executed method as failed. 400*cdf0e10cSrcweir * with the given message. 401*cdf0e10cSrcweir * The given message will be only evaluated, if s is false. 402*cdf0e10cSrcweir * With the parameter 'cont' set to true, the current test 403*cdf0e10cSrcweir * method will continue.<br> 404*cdf0e10cSrcweir * The current method will of course marked as failed. 405*cdf0e10cSrcweir * @param msg The message that is evaluated. 406*cdf0e10cSrcweir * @param cont Continue with test method, even if s is false. 407*cdf0e10cSrcweir */ 408*cdf0e10cSrcweir protected void failed(String msg, boolean cont) { 409*cdf0e10cSrcweir assure(msg, false, cont); 410*cdf0e10cSrcweir } 411*cdf0e10cSrcweir 412*cdf0e10cSrcweir /** 413*cdf0e10cSrcweir * @deprecated 414*cdf0e10cSrcweir */ 415*cdf0e10cSrcweir // protected void addResult(String message, boolean state) { 416*cdf0e10cSrcweir // String msg = message + " - " + state; 417*cdf0e10cSrcweir // this.state &= state; 418*cdf0e10cSrcweir // this.message += msg + "\r\n"; 419*cdf0e10cSrcweir // log.println(msg); 420*cdf0e10cSrcweir // } 421*cdf0e10cSrcweir 422*cdf0e10cSrcweir public class AssureException extends RuntimeException { 423*cdf0e10cSrcweir 424*cdf0e10cSrcweir public AssureException(String msg) { 425*cdf0e10cSrcweir super(msg); 426*cdf0e10cSrcweir } 427*cdf0e10cSrcweir } 428*cdf0e10cSrcweir } 429