er.extensions
Class ERXAssert
java.lang.Object
er.extensions.ERXAssert
- public class ERXAssert
- extends Object
Provides flexible and powerful assertion. Is modeled a bit like log4j in that you can have multiple asserters that can have different behavior. In particular, each can be disabled, set to logging mode or set to raise an exception. Also you can set your own failure handler.
In WebObjects.properties, you can have:
ERXAssert.instances=RAISE
ERXAssert.instances.com.somepackage=LOG
ERXAssert.instances.com.somepackage.someclass=RAISE
In your code's static initialization, you can write:
private static ERXAssert Assert = ERXAssert.getAssert(Foo.class);
private static ERXAssert Pre = ERXAssert.PRE;
private static ERXAssert Post = ERXAssert.POST;
And finally, in your methods, you call it via:
Pre.notNull(someObject);
Assert.notNull("someObject" ,someObject);
Post.notNull(someObject);
or you can use the supplied assertors directly
ERXAssert.DURING.notNull("someObject", someObject);
Most of this code is derived from Jonathan "Wolf" Rentzsch's JAssert, which can be found here:
http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/redshed/JAssert/
Method Summary |
void |
fail(String message)
|
void |
fail(String message,
String supplement)
|
ERXAssert.FailureHandler |
failureHandler()
|
static ERXAssert |
getAssert(Class c)
|
static ERXAssert |
getAssert(String name)
|
static ERXAssert |
getAssert(String prefix,
Class c)
|
protected static String |
getLevel(ERXAssert value)
|
void |
greaterThan(double value1,
double value2)
|
void |
greaterThan(int value1,
int value2)
|
void |
greaterThan(long value1,
long value2)
|
void |
greaterThanOrEqual(double value1,
double value2)
|
void |
greaterThanOrEqual(int value1,
int value2)
|
void |
greaterThanOrEqual(long value1,
long value2)
|
void |
isEmpty(String value)
|
void |
isEqual(double value1,
double value2)
|
void |
isEqual(int value1,
int value2)
|
void |
isEqual(long value1,
long value2)
|
void |
isEqual(Object value1,
Object value2)
|
void |
isEqual(String message,
int value1,
int value2)
|
void |
isEqual(String message,
Object value1,
Object value2)
|
void |
isFalse(boolean value)
|
void |
isFalse(String message,
boolean value)
|
void |
isNegative(double value)
|
void |
isNegative(int value)
|
void |
isNegative(long value)
|
void |
isNull(Object value)
|
void |
isNull(String message,
Object value)
|
void |
isPositive(double value)
|
void |
isPositive(int value)
|
void |
isPositive(long value)
|
void |
isTrue(boolean value)
|
void |
isTrue(String message,
boolean value)
|
void |
isZero(double value)
|
void |
isZero(int value)
|
void |
isZero(long value)
|
void |
lessThan(double value1,
double value2)
|
void |
lessThan(int value1,
int value2)
|
void |
lessThan(long value1,
long value2)
|
void |
lessThanOrEqual(double value1,
double value2)
|
void |
lessThanOrEqual(int value1,
int value2)
|
void |
lessThanOrEqual(long value1,
long value2)
|
String |
name()
|
void |
notEmpty(String value)
|
void |
notEqual(double value1,
double value2)
|
void |
notEqual(int value1,
int value2)
|
void |
notEqual(long value1,
long value2)
|
void |
notEqual(Object value1,
Object value2)
|
void |
notNegative(double value)
|
void |
notNegative(int value)
|
void |
notNegative(long value)
|
void |
notNull(Object value)
|
void |
notNull(String message,
Object value)
|
void |
notPositive(double value)
|
void |
notPositive(int value)
|
void |
notPositive(long value)
|
void |
notZero(double value)
|
void |
notZero(int value)
|
void |
notZero(long value)
|
void |
setFailureHandler(ERXAssert.FailureHandler handler)
|
static void |
setHandlerForLevel(ERXAssert.FailureHandler object,
String level)
|
protected static void |
setLevel(ERXAssert value)
|
void |
unknownSwitchCase(int value)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
DURING
public static ERXAssert DURING
PRE
public static ERXAssert PRE
POST
public static ERXAssert POST
_name
protected String _name
_failureHandler
protected ERXAssert.FailureHandler _failureHandler
getAssert
public static ERXAssert getAssert(String name)
getLevel
protected static String getLevel(ERXAssert value)
setHandlerForLevel
public static void setHandlerForLevel(ERXAssert.FailureHandler object,
String level)
setLevel
protected static void setLevel(ERXAssert value)
getAssert
public static ERXAssert getAssert(Class c)
getAssert
public static ERXAssert getAssert(String prefix,
Class c)
isTrue
public void isTrue(boolean value)
isTrue
public void isTrue(String message,
boolean value)
isFalse
public void isFalse(boolean value)
isFalse
public void isFalse(String message,
boolean value)
isNull
public void isNull(Object value)
isNull
public void isNull(String message,
Object value)
notNull
public void notNull(Object value)
notNull
public void notNull(String message,
Object value)
isEmpty
public void isEmpty(String value)
notEmpty
public void notEmpty(String value)
isZero
public void isZero(int value)
isZero
public void isZero(long value)
isZero
public void isZero(double value)
notZero
public void notZero(int value)
notZero
public void notZero(long value)
notZero
public void notZero(double value)
isNegative
public void isNegative(int value)
isNegative
public void isNegative(long value)
isNegative
public void isNegative(double value)
notNegative
public void notNegative(int value)
notNegative
public void notNegative(long value)
notNegative
public void notNegative(double value)
isPositive
public void isPositive(int value)
isPositive
public void isPositive(long value)
isPositive
public void isPositive(double value)
notPositive
public void notPositive(int value)
notPositive
public void notPositive(long value)
notPositive
public void notPositive(double value)
isEqual
public void isEqual(int value1,
int value2)
isEqual
public void isEqual(String message,
int value1,
int value2)
isEqual
public void isEqual(long value1,
long value2)
isEqual
public void isEqual(double value1,
double value2)
isEqual
public void isEqual(Object value1,
Object value2)
isEqual
public void isEqual(String message,
Object value1,
Object value2)
notEqual
public void notEqual(int value1,
int value2)
notEqual
public void notEqual(long value1,
long value2)
notEqual
public void notEqual(double value1,
double value2)
notEqual
public void notEqual(Object value1,
Object value2)
lessThan
public void lessThan(int value1,
int value2)
lessThan
public void lessThan(long value1,
long value2)
lessThan
public void lessThan(double value1,
double value2)
lessThanOrEqual
public void lessThanOrEqual(int value1,
int value2)
lessThanOrEqual
public void lessThanOrEqual(long value1,
long value2)
lessThanOrEqual
public void lessThanOrEqual(double value1,
double value2)
greaterThan
public void greaterThan(int value1,
int value2)
greaterThan
public void greaterThan(long value1,
long value2)
greaterThan
public void greaterThan(double value1,
double value2)
greaterThanOrEqual
public void greaterThanOrEqual(int value1,
int value2)
greaterThanOrEqual
public void greaterThanOrEqual(long value1,
long value2)
greaterThanOrEqual
public void greaterThanOrEqual(double value1,
double value2)
unknownSwitchCase
public void unknownSwitchCase(int value)
name
public String name()
failureHandler
public ERXAssert.FailureHandler failureHandler()
setFailureHandler
public void setFailureHandler(ERXAssert.FailureHandler handler)
fail
public void fail(String message)
fail
public void fail(String message,
String supplement)
Copyright © 2002 – 2004 Project Wonder.