Static Public Member Functions | |
static boolean | assertTrue (boolean booleanCond, String stringCond) |
static void | main (String[] args) |
An assertion class, that enables programmers to make certain affirmations about things that have to be true in the code. If an assertion is broken, this means that there is a bad error in the code. Often, assertions are used in to assure that the parameters of a function call are correct, e.g. if a non-null parameter has been passed.
,
,
static boolean cern.gp.util.Assertion.assertTrue | ( | boolean | booleanCond, | |
String | stringCond | |||
) | [static] |
Assert a function to assert a certain property of the code. If the asserted property is false, the Assertion is violated and an RuntimeException is thrown.
For example, assert that str
is non-null:
<blockquote>
void myFunction(String str) { Assert.assertTrue(str != null, "str != null"); } </pre</blockquote>
Example: make sure min <= max: <blockquote>
boolean compare(int min, int max) { Assert.assertTrue(min <= max, "min <= max"); }</blockquote>
Example: make sure that num is greater or equal 0:
<blockquote>
double squareRoot(double num) { Assert.assertTrue(num >= 0, "num >= 0"); } </pre</blockquote>
booleanCond | the condition expressed as a boolean | |
stringCond | the same condition, given as a String. This is used to fill in the error message in the Exception that is launched if the Assertion is violated. |
RuntimeException | if the Assertion is violated. The message in the
exception is the string in the stringCond parameter.
|
References cern.gp.util.IAssert.doAssert().
Referenced by cern.gp.util.Assertion.main().
static void cern.gp.util.Assertion.main | ( | String[] | args | ) | [static] |
The main program for the Assert class
args | The command line arguments |
References cern.gp.util.Assertion.assertTrue().