|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.tc.util.Assert
public class Assert
A general purpose assertion utility. By default it is on, but you can disable the throwing of exceptions by giving the system property "tcassert" a value of 'false'.
Constructor Summary | |
---|---|
Assert()
|
Method Summary | |
---|---|
static void |
assertConsistentCollection(java.util.Collection collection,
java.lang.Class elementClass,
boolean allowNullElements)
Assert that all items in collection are of type elementClass, also if !allowNullElements, check that all items in the collection are non-null. |
static void |
assertContainsElement(java.lang.Object[] objectArray,
java.lang.Object requiredElement)
Tests for equality using the == operator, not Object.equals(Object) . |
static void |
assertDoesNotContainsElement(java.lang.Object[] objectArray,
java.lang.Object element)
|
static void |
assertEquals(boolean expected,
boolean actual)
Assert expected and actual values are equal |
static void |
assertEquals(byte[] expected,
byte[] actual)
Assert expected and actual values are equal or both null |
static void |
assertEquals(double expected,
double actual)
Assert expected and actual values are equal |
static void |
assertEquals(double expected,
double actual,
double epsilon)
Assert expected and actual values are equal within epsilon |
static void |
assertEquals(int expected,
int actual)
Assert expected and actual values are equal |
static void |
assertEquals(long expected,
long actual)
Assert expected and actual values are equal |
static void |
assertEquals(java.lang.Object msg,
int expected,
int actual)
Assert expected and actual values are equal and return what as a message |
static void |
assertEquals(java.lang.Object expected,
java.lang.Object actual)
Assert expected and actual values are equal or both null |
static void |
assertEquals(java.lang.Object msg,
java.lang.Object expected,
java.lang.Object actual)
|
static void |
assertFalse(boolean expr)
Evaluate the boolean exception and throw an assertion error if true |
static void |
assertFalse(java.lang.Object message,
boolean expr)
Evaluate the boolean exception and throw an assertion error if true |
static void |
assertNoBlankElements(java.lang.String[] array)
Validate that the given array of strings contains no nulls or empty strings |
static void |
assertNoNullElements(java.lang.Object[] array)
Validate that the given (1 dimensional) array of references contains no nulls |
static void |
assertNotBlank(java.lang.Object what,
java.lang.String s)
Validate that s is not blank and throw what as a message |
static void |
assertNotBlank(java.lang.String s)
Validate that s is not blank |
static void |
assertNotEmpty(java.lang.Object what,
java.lang.String s)
Validate that s is not null or empty and throw what as a message |
static void |
assertNotEmpty(java.lang.String s)
Validate that s is not null or empty |
static void |
assertNotNull(java.lang.Object o)
If o is null, throw assertion error |
static void |
assertNotNull(java.lang.Object what,
java.lang.Object o)
If o is null, throw assertion error with message what |
static void |
assertNull(java.lang.Object o)
If o is non-null, throw assertion error |
static void |
assertNull(java.lang.Object what,
java.lang.Object o)
If o is non-null, throw assertion error |
static void |
assertSame(java.lang.Object lhs,
java.lang.Object rhs)
Validate that lhs and rhs are identical object references or both are null |
static void |
assertTrue(boolean expr)
Evaluate the boolean exception and throw an assertion error if false |
static void |
assertTrue(java.lang.Object message,
boolean expr)
Evaluate the boolean exception and throw an assertion error if false |
static void |
eval(boolean expr)
Evaluate the boolean exception and throw an assertion error if false |
static void |
eval(java.lang.Object message,
boolean expr)
Evaluate the boolean exception and throw an assertion error if false |
static void |
fail()
Throw assertion error with generic message |
static void |
fail(java.lang.String message)
Throw assertion error with specified message |
static TCAssertionError |
failure(java.lang.Object message)
This returns an exception, instead of throwing one, so that you can do (e.g.):
public Object foo() { throw Assert.failure("doesn't work"); }
or whatever. |
static TCAssertionError |
failure(java.lang.Object message,
java.lang.Throwable t)
This returns an exception, instead of throwing one, so that you can do (e.g.):
public Object foo() { throw Assert.failure("doesn't work"); }
or whatever. |
static void |
inv(boolean v)
Assert invariant |
static void |
post(boolean v)
Assert postcondition |
static void |
pre(boolean v)
Assert precondition |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Assert()
Method Detail |
---|
public static TCAssertionError failure(java.lang.Object message, java.lang.Throwable t)
public Object foo() { throw Assert.failure("doesn't work"); }
or whatever. If this just threw the exception itself, the compiler would complain (above) that there's no value
being returned.
message
- The message to put in the assertion errort
- The exception to wrap
public static TCAssertionError failure(java.lang.Object message)
public Object foo() { throw Assert.failure("doesn't work"); }
or whatever. If this just threw the exception itself, the compiler would complain (above) that there's no value
being returned.
message
- The message to put in the assertion error
public static void eval(boolean expr)
expr
- Expressionpublic static void eval(java.lang.Object message, boolean expr)
expr
- Expressionmessage
- Message for assertion error if falsepublic static void assertTrue(boolean expr)
expr
- Expressionpublic static void assertTrue(java.lang.Object message, boolean expr)
expr
- Expressionmessage
- Message for assertion error if falsepublic static void assertFalse(boolean expr)
expr
- Expressionmessage
- Message for assertion error if truepublic static void assertFalse(java.lang.Object message, boolean expr)
expr
- Expressionmessage
- Message for assertion error if truepublic static void assertNull(java.lang.Object o)
o
- Objectpublic static void assertNull(java.lang.Object what, java.lang.Object o)
o
- Objectwhat
- Message for errorpublic static void assertNotNull(java.lang.Object what, java.lang.Object o)
o
- Objectwhat
- Message for errorpublic static void assertNotNull(java.lang.Object o)
o
- Objectpublic static void assertNoNullElements(java.lang.Object[] array)
array
- Arraypublic static void assertNoBlankElements(java.lang.String[] array)
array
- Array of stringspublic static void assertNotEmpty(java.lang.Object what, java.lang.String s)
s
- Stringwhat
- Messagepublic static void assertNotEmpty(java.lang.String s)
s
- Stringpublic static void assertNotBlank(java.lang.Object what, java.lang.String s)
s
- Stringwhat
- Messagepublic static void assertNotBlank(java.lang.String s)
s
- Stringpublic static void assertSame(java.lang.Object lhs, java.lang.Object rhs)
lhs
- Left hand siderhs
- Right hand sidepublic static void assertEquals(int expected, int actual)
expected
- Expected valueactual
- Actual valuepublic static void assertEquals(long expected, long actual)
expected
- Expected valueactual
- Actual valuepublic static void assertEquals(java.lang.Object msg, int expected, int actual)
expected
- Expected valueactual
- Actual valuemsg
- Message, should be non-nullpublic static void assertEquals(double expected, double actual)
expected
- Expected valueactual
- Actual valuepublic static void assertEquals(double expected, double actual, double epsilon)
expected
- Expected valueactual
- Actual valueepsilon
- Maximum allowed difference between expected and actualpublic static void assertEquals(boolean expected, boolean actual)
expected
- Expected valueactual
- Actual valuepublic static void assertEquals(byte[] expected, byte[] actual)
expected
- Expected valueactual
- Actual valuepublic static void assertEquals(java.lang.Object expected, java.lang.Object actual)
expected
- Expected valueactual
- Actual valuepublic static void assertEquals(java.lang.Object msg, java.lang.Object expected, java.lang.Object actual)
public static void assertConsistentCollection(java.util.Collection collection, java.lang.Class elementClass, boolean allowNullElements)
collection
- The collectionelementClass
- The expected super type of all items in collectionallowNullElements
- Flag for whether null elements are allowed or notpublic static void assertContainsElement(java.lang.Object[] objectArray, java.lang.Object requiredElement)
==
operator, not Object.equals(Object)
.
null
is a valid element.
objectArray
- Array of objectsrequiredElement
- Must be in objectArraypublic static void assertDoesNotContainsElement(java.lang.Object[] objectArray, java.lang.Object element)
public static void fail()
public static void fail(java.lang.String message)
message
- Messagepublic static void pre(boolean v)
v
- Preconditionpublic static void post(boolean v)
v
- Postconditionpublic static void inv(boolean v)
v
- Invariant
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |