Static Public Member Functions

cern.gp.util.Assertion Class Reference

List of all members.

Static Public Member Functions

static boolean assertTrue (boolean booleanCond, String stringCond)
static void main (String[] args)

Detailed Description

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.

Author:
Vito Baggiolini
Version:
Revision:
1.2

,

Date:
2006/09/25 08:52:36

,

Author:
acaproni

Member Function Documentation

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> 
 
Parameters:
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.
Exceptions:
RuntimeException if the Assertion is violated. The message in the exception is the string in the stringCond parameter.
Returns:
the condition, which in this implementation is always true (a RuntimeException is thrown on false condition)

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

Parameters:
args The command line arguments

References cern.gp.util.Assertion.assertTrue().


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Enumerations Properties