org.deduced.utilities
Class AssertUtilities

java.lang.Object
  extended by org.deduced.utilities.AssertUtilities

public final class AssertUtilities
extends java.lang.Object

Title: AssertUtility

Description: AssertUtility offers a list of static method similar to unit test. The key difference being that the checks performed by AssertUtility are meant to be executed at run time. Developers must configure the logger to be notified on assertion failures and handle them as they want.

Author:
Steve McDUff

Field Summary
private static boolean ARE_ASSERTIONS_IGNORED
          ignore assertion flag
private static java.lang.String EMPTY_STRING
          default string
static java.util.logging.Logger LOGGER
          assertion logger
 
Constructor Summary
AssertUtilities()
           
 
Method Summary
static void assertEquals(boolean expected, boolean actual)
          Asserts that two boolean values are equal.
static void assertEquals(byte expected, byte actual)
          Asserts that two bytes are equal.
static void assertEquals(char expected, char actual)
          Asserts that two chars are equal.
static void assertEquals(double expected, double actual, double delta)
          Asserts that two doubles are equal concerning a delta.
static void assertEquals(float expected, float actual, float delta)
          Asserts that two floats are equal concerning a delta.
static void assertEquals(int expected, int actual)
          Asserts that two integers are equal.
static void assertEquals(long expected, long actual)
          Asserts that two longs are equal.
static void assertEquals(java.lang.Object expected, java.lang.Object actual)
          Asserts that two objects are equal.
static void assertEquals(short expected, short actual)
          Asserts that two shorts are equal.
static void assertEquals(java.lang.String message, boolean expected, boolean actual)
          Asserts that two boolean values are equal.
static void assertEquals(java.lang.String message, byte expected, byte actual)
          Asserts that two bytes are equal.
static void assertEquals(java.lang.String message, char expected, char actual)
          Asserts that two chars are equal.
static void assertEquals(java.lang.String message, double expected, double actual, double delta)
          Asserts that two doubles are equal concerning a delta.
static void assertEquals(java.lang.String message, float expected, float actual, float delta)
          Asserts that two floats are equal concerning a delta.
static void assertEquals(java.lang.String message, int expected, int actual)
          Asserts that two integers are equal.
static void assertEquals(java.lang.String message, long expected, long actual)
          Asserts that two longs are equal.
static void assertEquals(java.lang.String message, java.lang.Object expected, java.lang.Object actual)
          Asserts that two objects are equal.
static void assertEquals(java.lang.String message, short expected, short actual)
          Asserts that two shorts are equal.
static void assertEquals(java.lang.String expected, java.lang.String actual)
          Asserts that two Strings are equal.
static void assertEquals(java.lang.String message, java.lang.String expected, java.lang.String actual)
          Asserts that two Strings are equal.
static void assertFalse(boolean condition)
          Asserts that a condition is false.
static void assertFalse(java.lang.String message, boolean condition)
          Asserts that a condition is false.
static void assertNotNull(java.lang.Object object)
          Asserts that an object isn't null.
static void assertNotNull(java.lang.String message, java.lang.Object object)
          Asserts that an object isn't null.
static void assertNotSame(java.lang.Object expected, java.lang.Object actual)
          Asserts that two objects refer to the same object.
static void assertNotSame(java.lang.String message, java.lang.Object expected, java.lang.Object actual)
          Asserts that two objects refer to the same object.
static void assertNull(java.lang.Object object)
          Asserts that an object is null.
static void assertNull(java.lang.String message, java.lang.Object object)
          Asserts that an object is null.
static void assertSame(java.lang.Object expected, java.lang.Object actual)
          Asserts that two objects refer to the same object.
static void assertSame(java.lang.String message, java.lang.Object expected, java.lang.Object actual)
          Asserts that two objects refer to the same object.
static void assertTrue(boolean isOk)
          assertion check
static void assertTrue(java.lang.String message, boolean isOk)
          assertion check
static void exception(java.lang.String message, java.lang.Throwable ex)
          notify an unexpected exception
static void exception(java.lang.Throwable ex)
          notify an unexpected exception
static void fail()
          report an assertion failure
static void fail(java.lang.String message)
          report an assertion failure
private static void failNotEquals(java.lang.String message, java.lang.Object expected, java.lang.Object actual)
          report a failure because objects should have been the equal
private static void failNotSame(java.lang.String message, java.lang.Object expected, java.lang.Object actual)
          report a failure because objects should have been the same
private static void failSame(java.lang.String message)
          report a failure because objects shouldn't have been the same
static java.lang.String format(java.lang.String message, java.lang.Object expected, java.lang.Object actual)
          format a string to indicate the error condition
static void ignoreAssertions()
          ignore Assertions
static void resetAssertions()
          reset Assertions
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY_STRING

private static final java.lang.String EMPTY_STRING
default string

See Also:
Constant Field Values

LOGGER

public static final java.util.logging.Logger LOGGER
assertion logger


ARE_ASSERTIONS_IGNORED

private static boolean ARE_ASSERTIONS_IGNORED
ignore assertion flag

Constructor Detail

AssertUtilities

public AssertUtilities()
Method Detail

assertTrue

public static void assertTrue(boolean isOk)
assertion check

Parameters:
isOk - is everything ok

fail

public static void fail()
report an assertion failure


assertTrue

public static void assertTrue(java.lang.String message,
                              boolean isOk)
assertion check

Parameters:
isOk - is everything ok
message - the condition check description

fail

public static void fail(java.lang.String message)
report an assertion failure

Parameters:
message - the condition check description

exception

public static void exception(java.lang.Throwable ex)
notify an unexpected exception

Parameters:
ex - the exception

exception

public static void exception(java.lang.String message,
                             java.lang.Throwable ex)
notify an unexpected exception

Parameters:
message - the message to show with the assertion failure
ex - the exception

ignoreAssertions

public static void ignoreAssertions()
ignore Assertions


resetAssertions

public static void resetAssertions()
reset Assertions


assertFalse

public static void assertFalse(java.lang.String message,
                               boolean condition)
Asserts that a condition is false. If it isn't it throws an AssertionFailedError with the given message.

Parameters:
message - the condition check description
condition - value that needs to be false

assertFalse

public static void assertFalse(boolean condition)
Asserts that a condition is false. If it isn't it throws an AssertionFailedError.

Parameters:
condition - value that needs to be false

assertEquals

public static void assertEquals(java.lang.String message,
                                java.lang.Object expected,
                                java.lang.Object actual)
Asserts that two objects are equal. If they are not an AssertionFailedError is thrown with the given message.

Parameters:
message - the condition check description
expected - the expected value
actual - the actual value

assertEquals

public static void assertEquals(java.lang.Object expected,
                                java.lang.Object actual)
Asserts that two objects are equal. If they are not an AssertionFailedError is thrown.

Parameters:
expected - the expected value
actual - the actual value

assertEquals

public static void assertEquals(java.lang.String message,
                                java.lang.String expected,
                                java.lang.String actual)
Asserts that two Strings are equal.

Parameters:
message - the condition check description
expected - the expected value
actual - the actual value

assertEquals

public static void assertEquals(java.lang.String expected,
                                java.lang.String actual)
Asserts that two Strings are equal.

Parameters:
expected - the expected value
actual - the actual value

assertEquals

public static void assertEquals(java.lang.String message,
                                double expected,
                                double actual,
                                double delta)
Asserts that two doubles are equal concerning a delta. If they are not an AssertionFailedError is thrown with the given message. If the expected value is infinity then the delta value is ignored.

Parameters:
message - the condition check description
expected - the expected value
actual - the actual value
delta - allowed value delta between the expected and actual value

assertEquals

public static void assertEquals(double expected,
                                double actual,
                                double delta)
Asserts that two doubles are equal concerning a delta. If the expected value is infinity then the delta value is ignored.

Parameters:
expected - the expected value
actual - the actual value
delta - allowed value delta between the expected and actual value

assertEquals

public static void assertEquals(java.lang.String message,
                                float expected,
                                float actual,
                                float delta)
Asserts that two floats are equal concerning a delta. If they are not an AssertionFailedError is thrown with the given message. If the expected value is infinity then the delta value is ignored.

Parameters:
message - the condition check description
expected - the expected value
actual - the actual value
delta - allowed value delta between the expected and actual value

assertEquals

public static void assertEquals(float expected,
                                float actual,
                                float delta)
Asserts that two floats are equal concerning a delta. If the expected value is infinity then the delta value is ignored.

Parameters:
expected - the expected value
actual - the actual value
delta - allowed value delta between the expected and actual value

assertEquals

public static void assertEquals(java.lang.String message,
                                long expected,
                                long actual)
Asserts that two longs are equal. If they are not an AssertionFailedError is thrown with the given message.

Parameters:
message - the condition check description
expected - the expected value
actual - the actual value

assertEquals

public static void assertEquals(long expected,
                                long actual)
Asserts that two longs are equal.

Parameters:
expected - the expected value
actual - the actual value

assertEquals

public static void assertEquals(java.lang.String message,
                                boolean expected,
                                boolean actual)
Asserts that two boolean values are equal. If they are not an AssertionFailedError is thrown with the given message.

Parameters:
message - the condition check description
expected - the expected value
actual - the actual value

assertEquals

public static void assertEquals(boolean expected,
                                boolean actual)
Asserts that two boolean values are equal.

Parameters:
expected - the expected value
actual - the actual value

assertEquals

public static void assertEquals(java.lang.String message,
                                byte expected,
                                byte actual)
Asserts that two bytes are equal. If they are not an AssertionFailedError is thrown with the given message.

Parameters:
message - the condition check description
expected - the expected value
actual - the actual value

assertEquals

public static void assertEquals(byte expected,
                                byte actual)
Asserts that two bytes are equal.

Parameters:
expected - the expected value
actual - the actual value

assertEquals

public static void assertEquals(java.lang.String message,
                                char expected,
                                char actual)
Asserts that two chars are equal. If they are not an AssertionFailedError is thrown with the given message.

Parameters:
message - the condition check description
expected - the expected value
actual - the actual value

assertEquals

public static void assertEquals(char expected,
                                char actual)
Asserts that two chars are equal.

Parameters:
expected - the expected value
actual - the actual value

assertEquals

public static void assertEquals(java.lang.String message,
                                short expected,
                                short actual)
Asserts that two shorts are equal. If they are not an AssertionFailedError is thrown with the given message.

Parameters:
message - the condition check description
expected - the expected value
actual - the actual value

assertEquals

public static void assertEquals(short expected,
                                short actual)
Asserts that two shorts are equal.

Parameters:
expected - the expected value
actual - the actual value

assertEquals

public static void assertEquals(java.lang.String message,
                                int expected,
                                int actual)
Asserts that two integers are equal. If they are not an AssertionFailedError is thrown with the given message.

Parameters:
message - the condition check description
expected - the expected value
actual - the actual value

assertEquals

public static void assertEquals(int expected,
                                int actual)
Asserts that two integers are equal.

Parameters:
expected - the expected value
actual - the actual value

assertNotNull

public static void assertNotNull(java.lang.Object object)
Asserts that an object isn't null.

Parameters:
object - the object that shouldn't be null

assertNotNull

public static void assertNotNull(java.lang.String message,
                                 java.lang.Object object)
Asserts that an object isn't null. If it is an AssertionFailedError is thrown with the given message.

Parameters:
message - the condition check description
object - the object that shouldn't be null

assertNull

public static void assertNull(java.lang.Object object)
Asserts that an object is null.

Parameters:
object - the object that should be null

assertNull

public static void assertNull(java.lang.String message,
                              java.lang.Object object)
Asserts that an object is null. If it is not an AssertionFailedError is thrown with the given message.

Parameters:
message - the condition check description
object - the object that should be null

assertSame

public static void assertSame(java.lang.String message,
                              java.lang.Object expected,
                              java.lang.Object actual)
Asserts that two objects refer to the same object. If they are not an AssertionFailedError is thrown with the given message.

Parameters:
message - the condition check description
expected - the expected value
actual - the actual value

assertSame

public static void assertSame(java.lang.Object expected,
                              java.lang.Object actual)
Asserts that two objects refer to the same object. If they are not the same an AssertionFailedError is thrown.

Parameters:
expected - the expected value
actual - the actual value

assertNotSame

public static void assertNotSame(java.lang.String message,
                                 java.lang.Object expected,
                                 java.lang.Object actual)
Asserts that two objects refer to the same object. If they are not an AssertionFailedError is thrown with the given message.

Parameters:
message - the condition check description
expected - the expected value
actual - the actual value

assertNotSame

public static void assertNotSame(java.lang.Object expected,
                                 java.lang.Object actual)
Asserts that two objects refer to the same object. If they are not the same an AssertionFailedError is thrown.

Parameters:
expected - the expected value
actual - the actual value

failSame

private static void failSame(java.lang.String message)
report a failure because objects shouldn't have been the same

Parameters:
message - the condition check description

failNotSame

private static void failNotSame(java.lang.String message,
                                java.lang.Object expected,
                                java.lang.Object actual)
report a failure because objects should have been the same

Parameters:
message - the condition check description
expected - the expected value
actual - the actual value

failNotEquals

private static void failNotEquals(java.lang.String message,
                                  java.lang.Object expected,
                                  java.lang.Object actual)
report a failure because objects should have been the equal

Parameters:
message - the condition check description
expected - the expected value
actual - the actual value

format

public static java.lang.String format(java.lang.String message,
                                      java.lang.Object expected,
                                      java.lang.Object actual)
format a string to indicate the error condition

Parameters:
message - the condition check description
expected - the expected value
actual - the actual value
Returns:
the formatted string