public class Assertion
extends java.lang.Object
| Constructor and Description |
|---|
Assertion() |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
assertTrue(boolean booleanCond,
java.lang.String stringCond)
Assert a function to assert a certain property of the code.
|
static void |
main(java.lang.String[] args)
The main program for the Assert class
|
public static boolean assertTrue(boolean booleanCond,
java.lang.String stringCond)
For example, assert that str is non-null:
void myFunction(String str) { Assert.assertTrue(str != null, "str != null"); }Example: make sure min <= max:
boolean compare(int min, int max) { Assert.assertTrue(min <= max, "min <= max"); }Example: make sure that num is greater or equal 0:
double squareRoot(double num) { Assert.assertTrue(num >= 0, "num >= 0"); }
booleanCond - the condition expressed as a booleanstringCond - 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.java.lang.RuntimeException - if the Assertion is violated. The message in the
exception is the string in the stringCond parameter.public static void main(java.lang.String[] args)
args - The command line arguments