org.jcoderz.commons.util
Class Assert

java.lang.Object
  extended by org.jcoderz.commons.util.Assert

public final class Assert
extends Object

Utility class for assertions.

Author:
Andreas Mandel

Method Summary
static void assertEquals(String message, int expected, int actual)
          Asserts that two integers are equal.
static void assertEquals(String message, Object expected, Object actual)
          Asserts that two objects are equal.
static void assertTrue(String message, boolean condition)
          Asserts that a condition is true.
static void fail(String message)
          Can be called if an assertion already failed.
static void fail(String message, Throwable ex)
          Can be called if an exception is unexpectedly caught.
static void notNull(Object parameter, String argumentName)
          Asserts that an object isn't null.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

notNull

public static void notNull(Object parameter,
                           String argumentName)
Asserts that an object isn't null. If it is a null reference an ArgumentMalformedException is thrown with a appropriate message.

Parameters:
parameter - object to be tested against null.
argumentName - name of the provided argument within the used interface.

assertEquals

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

Parameters:
message - The message for the condition. This message is used in the exception if the integers are not equal.
expected - the expected integer.
actual - the actual integer.
Throws:
AssertionFailedException - if the two objects are not equal.

assertEquals

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

Parameters:
message - The message for the condition. This message is used in the exception if the objects are not equal.
expected - the expected object.
actual - the actual object.
Throws:
AssertionFailedException - if the two objects are not equal.

assertTrue

public static void assertTrue(String message,
                              boolean condition)
                       throws AssertionFailedException
Asserts that a condition is true. If it isn't it throws an AssertionFailedException with the given message.

Parameters:
message - The message for the condition. This message is used in the exception if the condition is false.
condition - the condition to test.
Throws:
AssertionFailedException - if the condition is false.

fail

public static void fail(String message)
                 throws AssertionFailedException
Can be called if an assertion already failed. This can be used at code positions that should never be reached at all. It throws an AssertionFailedException with the given message.

Parameters:
message - The message to be used in the exception.
Throws:
AssertionFailedException - always.

fail

public static void fail(String message,
                        Throwable ex)
                 throws AssertionFailedException
Can be called if an exception is unexpectedly caught. This can be used at catch blocks that should never be reached at all. It throws an AssertionFailedException with the given nested exception.

Parameters:
message - The message to be used in the exception.
ex - the exception that was not expected
Throws:
AssertionFailedException - always.


Copyright 2007 The jCoderZ Project.