com.arsdigita.util
Class Assert

java.lang.Object
  extended bycom.arsdigita.util.Assert

public class Assert
extends Object

Utility functions for assertions.

The static methods in this class provide a standard way of asserting certain conditions.

Though it is not right now, this class should be final. Do not subclass it. In a future revision of this software, this class will be made final.

Version:
$Id: //core-platform/dev/src/com/arsdigita/util/Assert.java#22 $
Author:
David Lutterkort <dlutter@redhat.com>, Uday Mathur, Justin Ross <jross@redhat.com>

Field Summary
static boolean ASSERT_ON
          Deprecated. in favor of isEnabled()
static String versionId
           
 
Constructor Summary
Assert()
           
 
Method Summary
static void assertEquals(int expected, int actual)
          Deprecated. Use truth(boolean, String) instead
static void assertEquals(int expected, int actual, String expectedLabel, String actualLabel)
          Deprecated. Use truth(boolean, String) instead
static void assertEquals(Object expected, Object actual)
          Deprecated. Use equal(Object,Object) instead
static void assertEquals(Object expected, Object actual, String expectedLabel, String actualLabel)
          Verify that two values are equal (according to their equals method, unless expected is null, then according to ==).
static void assertLocked(Lockable l)
          Deprecated. Use locked(Lockable) instead
static void assertNotEmpty(String s)
          Deprecated. with no replacement
static void assertNotEmpty(String s, String label)
          Deprecated. with no replacement
static void assertNotLocked(Lockable l)
          Deprecated. Use unlocked(Lockable) instead
static void assertNotNull(Object o)
          Deprecated. Use exists(Object,Class) instead
static void assertNotNull(Object o, String label)
          Deprecated. Use exists(Object,Class) instead
static void assertTrue(boolean cond)
          Deprecated. Use truth(boolean, String) instead
static void assertTrue(boolean cond, String msg)
          Deprecated. Use truth(boolean,String) instead
static void equal(Object value1, Object value2)
          Verifies that two values are equal (according to their equals method, unless value1 is null, then according to ==).
static void equal(Object value1, Object value2, String message)
          Verifies that two values are equal (according to their equals method, unless value1 is null, then according to ==).
static void exists(Object object)
          Asserts that an object is not null.
static void exists(Object object, Class clacc)
          Asserts that an object is not null.
static void fail()
          Throws an error.
static void fail(String message)
          Throws an error.
static void falsity(boolean condition)
          Asserts that an arbitrary condition is false and throws an error if the condition is true.
static void falsity(boolean condition, String message)
          Asserts that an arbitrary condition is false and throws an error if the condition is true.
static boolean isAssertEnabled()
          Deprecated. Use isEnabled() instead
static boolean isAssertOn()
          Deprecated. Use isEnabled() instead
static boolean isEnabled()
          Tells whether asserts are turned on.
static void locked(Lockable lockable)
          Verifies that Lockable is locked and throws an error if it is not.
static void truth(boolean condition)
          Asserts that an arbitrary condition is true and throws an error with message message if the condition is false.
static void truth(boolean condition, String message)
          Asserts that an arbitrary condition is true and throws an error with message message if the condition is false.
static void unequal(Object value1, Object value2)
          Verifies that two values are not equal (according to their equals method, unless value1 is null, then according to ==).
static void unlocked(Lockable lockable)
          Verifies that lockable is not locked and throws an error if it is.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

versionId

public static final String versionId
See Also:
Constant Field Values

ASSERT_ON

public static final boolean ASSERT_ON
Deprecated. in favor of isEnabled()

See Also:
Constant Field Values
Constructor Detail

Assert

public Assert()
Method Detail

isEnabled

public static final boolean isEnabled()
Tells whether asserts are turned on. Use this to wrap code that should be optimized away if assertions are disabled. By default, assertions are disabled


fail

public static final void fail(String message)
Throws an error.

Parameters:
message - A String describing the failure condition
Throws:
AssertionError

fail

public static final void fail()
Throws an error.

Throws:
AssertionError

truth

public static final void truth(boolean condition,
                               String message)
Asserts that an arbitrary condition is true and throws an error with message message if the condition is false.

Parameters:
condition - The condition asserted
message - An error message
Throws:
AssertionError - if the condition is false

truth

public static final void truth(boolean condition)
Asserts that an arbitrary condition is true and throws an error with message message if the condition is false.

Parameters:
condition - The condition asserted
Throws:
AssertionError - if the condition is false

falsity

public static final void falsity(boolean condition,
                                 String message)
Asserts that an arbitrary condition is false and throws an error if the condition is true.

Parameters:
condition - The condition asserted
message - An error message
Throws:
AssertionError - if the condition is false

falsity

public static final void falsity(boolean condition)
Asserts that an arbitrary condition is false and throws an error if the condition is true.

Parameters:
condition - The condition asserted
Throws:
AssertionError - if the condition is false

exists

public static final void exists(Object object,
                                Class clacc)
Asserts that an object is not null.

Parameters:
object - The object that must not be null
clacc - The Class of parameter object
Throws:
AssertionError - if the object is null

exists

public static final void exists(Object object)
Asserts that an object is not null.

Parameters:
object - The object that must not be null
Throws:
AssertionError - if the object is null

locked

public static final void locked(Lockable lockable)
Verifies that Lockable is locked and throws an error if it is not.

Parameters:
lockable - The object that must be locked
See Also:
Lockable

unlocked

public static final void unlocked(Lockable lockable)
Verifies that lockable is not locked and throws an error if it is.

Parameters:
lockable - The object that must not be locked
See Also:
Lockable

equal

public static final void equal(Object value1,
                               Object value2)
Verifies that two values are equal (according to their equals method, unless value1 is null, then according to ==).

Parameters:
value1 - The first value to be compared
value2 - The second
Throws:
AssertionError - if the arguments are unequal

equal

public static final void equal(Object value1,
                               Object value2,
                               String message)
Verifies that two values are equal (according to their equals method, unless value1 is null, then according to ==).

Parameters:
value1 - The first value to be compared
value2 - The second
Throws:
AssertionError - if the arguments are unequal

unequal

public static final void unequal(Object value1,
                                 Object value2)
Verifies that two values are not equal (according to their equals method, unless value1 is null, then according to ==).

Parameters:
value1 - The first value to be compared
value2 - The second
Throws:
AssertionError - if the arguments are unequal

isAssertOn

public static final boolean isAssertOn()
Deprecated. Use isEnabled() instead

Indicates state of the ASSERT_ON flag.


isAssertEnabled

public static final boolean isAssertEnabled()
Deprecated. Use isEnabled() instead

Tells whether asserts are turned on. Use this to wrap code that should be optimized away if asserts are disabled.


assertTrue

public static final void assertTrue(boolean cond)
Deprecated. Use truth(boolean, String) instead

Assert that an arbitrary condition is true, and throw an exception if the condition is false.

Parameters:
cond - condition to assert
Throws:
IllegalStateException - condition was false

assertTrue

public static final void assertTrue(boolean cond,
                                    String msg)
Deprecated. Use truth(boolean,String) instead

Assert that an arbitrary condition is true, and throw an exception with message msg if the condition is false.

Parameters:
cond - condition to assert
msg - failure message
Throws:
IllegalStateException - condition was false

assertNotNull

public static final void assertNotNull(Object o)
Deprecated. Use exists(Object,Class) instead

Verify that a parameter is not null and throw a runtime exception if so.


assertNotNull

public static final void assertNotNull(Object o,
                                       String label)
Deprecated. Use exists(Object,Class) instead

Verify that a parameter is not null and throw a runtime exception if so.


assertNotEmpty

public static final void assertNotEmpty(String s)
Deprecated. with no replacement

Verify that a string is not empty and throw a runtime exception if so. A parameter is considered empty if it is null, or if it does not contain any characters that are non-whitespace.


assertNotEmpty

public static final void assertNotEmpty(String s,
                                        String label)
Deprecated. with no replacement

Verify that a string is not empty and throw a runtime exception if so. A parameter is considered empty if it is null, or if it does not contain any characters that are non-whitespace.


assertEquals

public static final void assertEquals(Object expected,
                                      Object actual)
Deprecated. Use equal(Object,Object) instead

Verify that two values are equal (according to their equals method, unless expected is null, then according to ==).

Parameters:
expected - Expected value.
actual - Actual value.
Throws:
IllegalStateException - condition was false

assertEquals

public static final void assertEquals(Object expected,
                                      Object actual,
                                      String expectedLabel,
                                      String actualLabel)
Verify that two values are equal (according to their equals method, unless expected is null, then according to ==).

Parameters:
expected - Expected value.
actual - Actual value.
expectedLabel - Label for first (generally expected) value.
actualLabel - Label for second (generally actual) value.
Throws:
IllegalStateException - condition was false

assertEquals

public static final void assertEquals(int expected,
                                      int actual)
Deprecated. Use truth(boolean, String) instead

Verify that two values are equal.

Parameters:
expected - Expected value.
actual - Actual value.
Throws:
IllegalStateException - condition was false

assertEquals

public static final void assertEquals(int expected,
                                      int actual,
                                      String expectedLabel,
                                      String actualLabel)
Deprecated. Use truth(boolean, String) instead

Verify that two values are equal.

Parameters:
expected - Expected value.
actual - Actual value.
expectedLabel - Label for first (generally expected) value.
actualLabel - Label for second (generally actual) value.
Throws:
IllegalStateException - condition was false

assertLocked

public static void assertLocked(Lockable l)
Deprecated. Use locked(Lockable) instead

Verify that the model is locked and throw a runtime exception if it is not locked.


assertNotLocked

public static void assertNotLocked(Lockable l)
Deprecated. Use unlocked(Lockable) instead

Verify that the model is locked and throw a runtime exception if it is locked.



Copyright (c) 2004 Red Hat, Inc. Corporation. All Rights Reserved. Generated at July 21 2004:2337 UTC