Class Assert
×News: XavaPro 7.7 released - March 11 · Read more
java.lang.Object
org.openxava.util.Assert
Utility to make asserts.
In most case this asserts verify if the object is null.
There are a variety of methods that throw differents exceptions.
One of the thrown exception is AssertException, but this
is not mandatory.
If some of this methods throw exception this is usually
due to a software error, normally a exception that the
user-programmer has not fullfilled the contract.
The messages does not have to specify the place where
contract is break or which contract is broken. The
trace (that always is printed) indicate the place and
the exception class. In the doc of method that throw the
exception you can obtain more info about it.
The names and behaviour match with JUnit,
the difference is the thrown exceptions.
- Author:
- Javier Paniza
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic final voidVerify argument.static final voidVerify arguments.static final voidVerify arguments.static final voidVerify arguments.static final voidVerify arguments.static final voidVerify arguments.static final voidVerify arguments.static voidassertEquals(double expected, double actual, double delta) Asserts that two doubles are equal.static voidassertEquals(long expected, long actual) Asserts that two longs are equal.static voidassertEquals(Object expected, Object actual) Asserts that two objects are equal.static voidassertEquals(String message, double expected, double actual, double delta) Asserts that two doubles are equal.static voidassertEquals(String message, long expected, long actual) Asserts that two longs are equal.static voidassertEquals(String message, Object expected, Object actual) Asserts that two objects are equal.static voidassertNotNull(Object object) Asserts that an object isn't null.static voidassertNotNull(String message, Object object) Asserts that an object isn't null.static voidassertNull(Object object) Asserts that an object is null.static voidassertNull(String message, Object object) Asserts that an object is null.static voidassertSame(Object expected, Object actual) Asserts that two objects refer to the same object.static voidassertSame(String message, Object expected, Object actual) Asserts that two objects refer to the same object.static voidassertTrue(boolean condition) Asserts that a condition is true.static voidassertTrue(String message, boolean condition) Asserts that a condition is true.static final voidfail()Throws a AssertException and print the trace.static final voidThrows a AssertException and print the trace.
-
Constructor Details
-
Assert
public Assert()
-
-
Method Details
-
arg
Verify argument.- Throws:
IllegalArgumentException- If o == null.
-
arg
Verify arguments.- Throws:
IllegalArgumentException- If o1 == null || o2 == null.
-
arg
Verify arguments.- Throws:
IllegalArgumentException- If o1 == null || o2 == null || o3 == null.
-
arg
Verify arguments.- Throws:
IllegalArgumentException- If o1 == null || o2 == null || o3 == null || o4 == null.
-
arg
-
arg
-
arg
-
assertTrue
Asserts that a condition is true.- Throws:
AssertException- If condition is false
-
assertTrue
public static void assertTrue(boolean condition) Asserts that a condition is true.- Throws:
AssertException- If condition is false
-
assertEquals
public static void assertEquals(double expected, double actual, double delta) Asserts that two doubles are equal.- Parameters:
expected- the expected value of an objectactual- the actual value of an objectdelta- tolerated delta- Throws:
AssertException- If assert is not fulfilled
-
assertEquals
public static void assertEquals(long expected, long actual) Asserts that two longs are equal.- Parameters:
expected- the expected value of an objectactual- the actual value of an object- Throws:
AssertException- If assert is not fulfilled
-
assertEquals
Asserts that two objects are equal.- Parameters:
expected- the expected value of an objectactual- the actual value of an object- Throws:
AssertException- If assert is not fulfilled
-
assertEquals
Asserts that two doubles are equal.- Parameters:
message- the detail message for this assertionexpected- the expected value of an objectactual- the actual value of an objectdelta- tolerated delta- Throws:
AssertException- If assert is not fulfilled
-
assertEquals
Asserts that two longs are equal.- Parameters:
message- the detail message for this assertionexpected- the expected value of an objectactual- the actual value of an object- Throws:
AssertException- If assert is not fulfilled
-
assertEquals
Asserts that two objects are equal. If they are not an AssertionFailedError is thrown.- Parameters:
message- the detail message for this assertionexpected- the expected value of an objectactual- the actual value of an object- Throws:
AssertException- If assert is not fulfilled
-
assertNotNull
Asserts that an object isn't null.- Throws:
AssertException- If assert is not fulfilled
-
assertNotNull
Asserts that an object isn't null.- Throws:
AssertException- If assert is not fulfilled
-
assertNull
Asserts that an object is null.- Throws:
AssertException- If assert is not fulfilled
-
assertNull
Asserts that an object is null.- Throws:
AssertException- If assert is not fulfilled
-
assertSame
Asserts that two objects refer to the same object.- Parameters:
expected- the expected value of an objectactual- the actual value of an object- Throws:
AssertException- If assert is not fulfilled
-
assertSame
Asserts that two objects refer to the same object.- Parameters:
message- the detail message for this assertionexpected- the expected value of an objectactual- the actual value of an object- Throws:
AssertException- If assert is not fulfilled
-
fail
public static final void fail()Throws a AssertException and print the trace. -
fail
Throws a AssertException and print the trace.
-