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