momeunit.framework
Class Assert

java.lang.Object
  extended by momeunit.framework.Assert
Direct Known Subclasses:
TestCase

public class Assert
extends Object

A collection of static assert methods. A TestCase base class. If assertion fails AssertionFailedError with descriptive message is thrown.

Note In this package there is no ComparisonFailure class. The processing of compared strings contained in this class is optimized and moved to the respective assert methods.

Version:
1.1.2
Author:
Sergio Morozov

Constructor Summary
protected Assert()
          Protect constructor since it is a static only class
 
Method Summary
static void assertEquals(boolean expected, boolean actual)
          Asserts that two booleans 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 ints are equal.
static void assertEquals(long expected, long actual)
          Asserts that two longs are equal.
static void assertEquals(Object expected, Object actual)
          Asserts that two objects are equal.
static void assertEquals(short expected, short actual)
          Asserts that two shorts are equal.
static void assertEquals(String message, boolean expected, boolean actual)
          Asserts that two booleans are equal.
static void assertEquals(String message, byte expected, byte actual)
          Asserts that two bytes are equal.
static void assertEquals(String message, char expected, char actual)
          Asserts that two chars are equal.
static void assertEquals(String message, double expected, double actual, double delta)
          Asserts that two doubles are equal concerning a delta.
static void assertEquals(String message, float expected, float actual, float delta)
          Asserts that two floats are equal concerning a delta.
static void assertEquals(String message, int expected, int actual)
          Asserts that two ints are equal.
static void assertEquals(String message, long expected, long actual)
          Asserts that two longs are equal.
static void assertEquals(String message, Object expected, Object actual)
          Asserts that two objects are equal.
static void assertEquals(String message, short expected, short actual)
          Asserts that two shorts are equal.
static void assertEquals(String expected, String actual)
          Asserts that two Strings are equal.
static void assertEquals(String message, String expected, String actual)
          Asserts that two Strings are equal.
static void assertFalse(boolean condition)
          Asserts that a given condition is false.
static void assertFalse(String message, boolean condition)
          Asserts that a given condition is false.
static void assertNotNull(Object object)
          Asserts that an object isn't null.
static void assertNotNull(String message, Object object)
          Asserts that an object isn't null.
static void assertNotSame(Object expected, Object actual)
          Asserts that two objects don't refer to the same object.
static void assertNotSame(String message, Object expected, Object actual)
          Asserts that two objects don't refer to the same object.
static void assertNull(Object object)
          Asserts that an object is null.
static void assertNull(String message, Object object)
          Asserts that an object is null.
static void assertSame(Object expected, Object actual)
          Asserts that two objects refer to the same object.
static void assertSame(String message, Object expected, Object actual)
          Asserts that two objects refer to the same object.
static void assertTrue(boolean condition)
          Asserts that a given condition is true.
static void assertTrue(String message, boolean condition)
          Asserts that a given condition is true.
static void fail()
          Fails a test with no message.
static void fail(String message)
          Fails a test with a given message.
(package private) static String format(String message, Object expected, Object actual)
          Returns the formatted message based on specified message and compared objects.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Assert

protected Assert()
Protect constructor since it is a static only class

Since:
1.0
Method Detail

assertTrue

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

Parameters:
message - descriptive message of failure.
condition - condition to check.
Since:
1.0

assertTrue

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

Parameters:
condition - condition to check.
Since:
1.0

assertFalse

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

Parameters:
message - descriptive message of failure.
condition - condition to check.
Since:
1.0

assertFalse

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

Parameters:
condition - condition to check.
Since:
1.0

fail

public static void fail(String message)
Fails a test with a given message.

Parameters:
message - descriptive message of failure.
Since:
1.0

fail

public static void fail()
Fails a test with no message.

Since:
1.0

assertEquals

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

Parameters:
message - descriptive message of failure.
expected - expected object to be tested.
actual - actual object to be tested.
Since:
1.0

assertEquals

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

Parameters:
expected - expected object to be tested.
actual - actual object to be tested.
Since:
1.0

assertEquals

public static void assertEquals(String message,
                                String expected,
                                String actual)
Asserts that two Strings are equal. If they are not throws an AssertionFailedError with given message and arguments. Compared strings are processed so, that just different parts of them are visible with respective "..." suffixes and prefixes.

Parameters:
message - descriptive message of failure.
expected - expected String to be tested.
actual - actual String to be tested.
Since:
1.0

assertEquals

public static void assertEquals(String expected,
                                String actual)
Asserts that two Strings are equal. If they are not an AssertionFailedError is thrown and arguments. Compared strings are processed so, that just different parts of them are visible with respective "..." suffixes and prefixes.

Parameters:
expected - expected String to be tested.
actual - actual String to be tested.
Since:
1.0

assertEquals

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

Parameters:
message - descriptive message of failure.
expected - expected double to be tested.
actual - actual double to be tested.
delta - precision of comparison.
Since:
1.0

assertEquals

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

Parameters:
expected - expected double to be tested.
actual - actual double to be tested.
delta - precision of comparison.
Since:
1.0

assertEquals

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

Parameters:
message - descriptive message of failure.
expected - expected float to be tested.
actual - actual float to be tested.
delta - precision of comparison.
Since:
1.0

assertEquals

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

Parameters:
expected - float to be tested.
actual - float to be tested.
delta - precision of comparison.
Since:
1.0

assertEquals

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

Parameters:
message - descriptive message of failure.
expected - long to be tested.
actual - long to be tested.
Since:
1.0

assertEquals

public static void assertEquals(long expected,
                                long actual)
Asserts that two longs are equal. If they are not throws an AssertionFailedError.

Parameters:
expected - long to be tested.
actual - long to be tested.
Since:
1.0

assertEquals

public static void assertEquals(String message,
                                boolean expected,
                                boolean actual)
Asserts that two booleans are equal. If they are not throws an AssertionFailedError with the given message.

Parameters:
message - descriptive message of failure.
expected - boolean to be tested.
actual - boolean to be tested.
Since:
1.0

assertEquals

public static void assertEquals(boolean expected,
                                boolean actual)
Asserts that two booleans are equal. If they are not throws an AssertionFailedError.

Parameters:
expected - boolean to be tested.
actual - boolean to be tested.
Since:
1.0

assertEquals

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

Parameters:
message - descriptive message of failure.
expected - byte to be tested.
actual - byte to be tested.
Since:
1.0

assertEquals

public static void assertEquals(byte expected,
                                byte actual)
Asserts that two bytes are equal. If they are not throws an AssertionFailedError.

Parameters:
expected - byte to be tested.
actual - byte to be tested.
Since:
1.0

assertEquals

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

Parameters:
message - descriptive message of failure.
expected - char to be tested.
actual - char to be tested.
Since:
1.0

assertEquals

public static void assertEquals(char expected,
                                char actual)
Asserts that two chars are equal. If they are not throws an AssertionFailedError.

Parameters:
expected - char to be tested.
actual - char to be tested.
Since:
1.0

assertEquals

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

Parameters:
message - descriptive message of failure.
expected - short to be tested.
actual - short to be tested.
Since:
1.0

assertEquals

public static void assertEquals(short expected,
                                short actual)
Asserts that two shorts are equal. If they are not throws an AssertionFailedError.

Parameters:
expected - short to be tested.
actual - short to be tested.
Since:
1.0

assertEquals

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

Parameters:
message - descriptive message of failure.
expected - int to be tested.
actual - int to be tested.
Since:
1.0

assertEquals

public static void assertEquals(int expected,
                                int actual)
Asserts that two ints are equal. If they are not throws an AssertionFailedError.

Parameters:
expected - int to be tested.
actual - int to be tested.
Since:
1.0

assertNotNull

public static void assertNotNull(Object object)
Asserts that an object isn't null. If it is null throws an AssertionFailedError.

Parameters:
object - to test.
Since:
1.0

assertNotNull

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

Parameters:
message - descriptive message of failure.
object - to test.
Since:
1.0

assertNull

public static void assertNull(Object object)
Asserts that an object is null. If it is not null throws an AssertionFailedError.

Parameters:
object - to test.
Since:
1.0

assertNull

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

Parameters:
message - descriptive message of failure.
object - to test.
Since:
1.0

assertSame

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

Parameters:
message - descriptive message of failure.
expected - object to test.
actual - object to test.
Since:
1.0

assertSame

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

Parameters:
expected - object to test.
actual - object to test.
Since:
1.0

assertNotSame

public static void assertNotSame(String message,
                                 Object expected,
                                 Object actual)
Asserts that two objects don't refer to the same object. If they are throws AssertionFailedError with the given message.

Parameters:
message - descriptive message of failure.
expected - object to test.
actual - object to test.
Since:
1.0

assertNotSame

public static void assertNotSame(Object expected,
                                 Object actual)
Asserts that two objects don't refer to the same object. If they are throws AssertionFailedError.

Parameters:
expected - object to test.
actual - object to test.
Since:
1.0

format

static String format(String message,
                     Object expected,
                     Object actual)
Returns the formatted message based on specified message and compared objects.

Parameters:
message - descriotive message.
expected - expected tested object.
actual - actual tested object.
Returns:
the formatted string.
Since:
1.0