org.osesb.validationbeans
Class Assertions

java.lang.Object
  extended by org.osesb.validationbeans.Assertions

public class Assertions
extends java.lang.Object

A static-only Class with assertion methods that can be used by ValidationBeans to validate data.

Usage:

Assertion methods do not return a result. If the assertion fails, an AssertionException is thrown with a programmer-defined message.

Since:
Version .9

Field Summary
protected static java.lang.String thisClassName
          The full name of this class.
 
Constructor Summary
Assertions()
           
 
Method Summary
static void assertDateAfter(java.lang.String message, java.util.Date date1, java.util.Date date2)
          Asserts that date1 is after date2.
static void assertDateAfterOrEqual(java.lang.String message, java.util.Date date1, java.util.Date date2)
          Asserts that date1 is after or equal to date2.
static void assertDateBefore(java.lang.String message, java.util.Date date1, java.util.Date date2)
          Asserts that date1 is before date2.
static void assertDateBeforeOrEqual(java.lang.String message, java.util.Date date1, java.util.Date date2)
          Asserts that date1 is before or equal to date2.
static void assertDateBetweenExclusive(java.lang.String message, java.util.Date dateTimeToTest, java.util.Date startDate, java.util.Date endDate)
          Asserts that a date is between a startDate and an endDate (exclusive).
static void assertDateBetweenInclusive(java.lang.String message, java.util.Date dateTimeToTest, java.util.Date startDate, java.util.Date endDate)
          Asserts that a date is between a startDate and an endDate (inclusive).
static void assertDatesEqual(java.lang.String message, java.util.Date expected, java.util.Date actual)
          Asserts that two Dates are equal.
static void assertEquals(java.lang.String message, double expected, double actual)
          Asserts that two double primitives are equal.
static void assertEquals(java.lang.String message, float expected, float actual)
          Asserts that two float primitives are equal.
static void assertEquals(java.lang.String message, int expected, int actual)
          Asserts that two int primitives 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 assertFalse(java.lang.String message, boolean condition)
          Asserts that a condition is false.
static void assertNotNull(java.lang.String message, java.lang.Object object)
          Asserts that an object isn't null.
static void assertNull(java.lang.String message, java.lang.Object object)
          Asserts that an object is null.
static void assertStringNotEmpty(java.lang.String message, java.lang.String string)
          Asserts that a String is not null and has a length() > 0.
static void assertTrue(java.lang.String message, boolean condition)
          Asserts that a condition is true.
protected static int compareDates(java.util.Date date1, java.util.Date date2)
          Compares two dates.
protected static java.lang.String constructComparisonMessage(java.lang.String message, java.lang.Object expected, java.lang.Object actual)
          Returns a new AssertionException message for comparisons with 'expected vs.
static void main(java.lang.String[] args)
          main() for testing and sandboxing.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

thisClassName

protected static java.lang.String thisClassName
The full name of this class.

Constructor Detail

Assertions

public Assertions()
Method Detail

assertTrue

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

Parameters:
message - A programmer-defined AssertionException message.
condition - The condition to test.
Throws:
AssertionException

assertFalse

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

Parameters:
message - A programmer-defined AssertionException message.
condition - The condition to test.
Throws:
AssertionException

assertNotNull

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

Parameters:
message - A programmer-defined AssertionException message.
object - The Object to Object test.
Throws:
AssertionException - if the object is null.

assertStringNotEmpty

public static void assertStringNotEmpty(java.lang.String message,
                                        java.lang.String string)
                                 throws AssertionException
Asserts that a String is not null and has a length() > 0.

Parameters:
message - A programmer-defined AssertionException message.
string - The String to test.
Throws:
AssertionException - if the String is null or has a length() == 0.

assertNull

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

Parameters:
message - A programmer-defined AssertionException message.
object - The Object to test.
Throws:
AssertionException - if the object isn't null.

assertEquals

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

Parameters:
message - A programmer-defined AssertionException message.
expected - The Object whose value is expected.
actual - The Object whose value is tested.
Throws:
AssertionException - if the actual Object's value does not equal the expected Object's value.
java.lang.Exception - if the expected and actual Objects cannot be compared either because one does not implement Comparable or because the expected and actual Objects have different ancestry.

assertEquals

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

Parameters:
message - A programmer-defined AssertionException message.
expected - The expected int value.
actual - The int value to test against.
Throws:
AssertionException - if the actual int value does not equal the expected int value.

assertEquals

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

Parameters:
message - A programmer-defined AssertionException message.
expected - The expected double value.
actual - The double value to test against.
Throws:
AssertionException - if the actual double value does not equal the expected double value.

assertEquals

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

Parameters:
message - A programmer-defined AssertionException message.
expected - The expected float value.
actual - The float value to test against.
Throws:
AssertionException - if the actual float value does not equal the expected float value.

constructComparisonMessage

protected static java.lang.String constructComparisonMessage(java.lang.String message,
                                                             java.lang.Object expected,
                                                             java.lang.Object actual)
Returns a new AssertionException message for comparisons with 'expected vs. actual' text appended to the programmer-defined AssertionException message.

Parameters:
message - A programmer-defined AssertionException message.
expected - The Object whose value is expected.
actual - The Object whose value is tested.
Returns:
A new AssertionException message with 'expected vs. actual' text appended to the programmer-defined AssertionException message.

assertDatesEqual

public static void assertDatesEqual(java.lang.String message,
                                    java.util.Date expected,
                                    java.util.Date actual)
                             throws AssertionException,
                                    java.lang.Exception
Asserts that two Dates are equal. If they are not, an AssertionException is thrown with the given message.

Parameters:
message - A programmer-defined AssertionException message.
expected - The expected Date.
actual - The Date value to test against.
Throws:
AssertionException - if the actual Date does not equal the expected Date.
java.lang.Exception - if an error occurs while computing Dates.

assertDateBefore

public static void assertDateBefore(java.lang.String message,
                                    java.util.Date date1,
                                    java.util.Date date2)
                             throws AssertionException,
                                    java.lang.Exception
Asserts that date1 is before date2. If it is not, an AssertionException is thrown with the given message.

Parameters:
message - A programmer-defined AssertionException message.
date1 - The first date.
date2 - The second date.
Throws:
AssertionException - if date1 is not before date2.
java.lang.Exception - if an error occurs while computing Dates.

assertDateBeforeOrEqual

public static void assertDateBeforeOrEqual(java.lang.String message,
                                           java.util.Date date1,
                                           java.util.Date date2)
                                    throws AssertionException,
                                           java.lang.Exception
Asserts that date1 is before or equal to date2. If it is not, an AssertionException is thrown with the given message.

Parameters:
message - A programmer-defined AssertionException message.
date1 - The first date.
date2 - The second date.
Throws:
AssertionException - if date1 is not before or equal to date2.
java.lang.Exception - if an error occurs while computing Dates.

assertDateAfter

public static void assertDateAfter(java.lang.String message,
                                   java.util.Date date1,
                                   java.util.Date date2)
                            throws AssertionException,
                                   java.lang.Exception
Asserts that date1 is after date2. If it is not, an AssertionException is thrown with the given message.

Parameters:
message - A programmer-defined AssertionException message.
date1 - The first date.
date2 - The second date.
Throws:
AssertionException - if date1 is not after date2.
java.lang.Exception - if an error occurs while computing Dates.

assertDateAfterOrEqual

public static void assertDateAfterOrEqual(java.lang.String message,
                                          java.util.Date date1,
                                          java.util.Date date2)
                                   throws AssertionException,
                                          java.lang.Exception
Asserts that date1 is after or equal to date2. If it is not, an AssertionException is thrown with the given message.

Parameters:
message - A programmer-defined AssertionException message.
date1 - The first date.
date2 - The second date.
Throws:
AssertionException - if date1 is not after or equal to date2.
java.lang.Exception - if an error occurs while computing Dates.

assertDateBetweenExclusive

public static void assertDateBetweenExclusive(java.lang.String message,
                                              java.util.Date dateTimeToTest,
                                              java.util.Date startDate,
                                              java.util.Date endDate)
                                       throws AssertionException,
                                              java.lang.Exception
Asserts that a date is between a startDate and an endDate (exclusive). If it is not, an AssertionException is thrown with the given message.

Parameters:
message - A programmer-defined AssertionException message.
dateTimeToTest - The date to test.
startDate - The start date of the range.
endDate - The end date of the range.
Throws:
AssertionException - if dateTimeToTest is not between a startDate and an endDate (exclusive).
java.lang.Exception - if an error occurs while computing Dates.

assertDateBetweenInclusive

public static void assertDateBetweenInclusive(java.lang.String message,
                                              java.util.Date dateTimeToTest,
                                              java.util.Date startDate,
                                              java.util.Date endDate)
                                       throws AssertionException,
                                              java.lang.Exception
Asserts that a date is between a startDate and an endDate (inclusive). If it is not, an AssertionException is thrown with the given message.

Parameters:
message - A programmer-defined AssertionException message.
dateTimeToTest - The date to test.
startDate - The start date of the range.
endDate - The end date of the range.
Throws:
AssertionException - if dateTimeToTest is not between a startDate and an endDate (inclusive).
java.lang.Exception - if an error occurs while computing Dates.

compareDates

protected static int compareDates(java.util.Date date1,
                                  java.util.Date date2)
                           throws java.lang.Exception
Compares two dates. Used for date/time related Asserts.

Parameters:
date1 -
date2 -
Throws:
java.lang.Exception - if invoked with invalid parameters.

main

public static void main(java.lang.String[] args)
main() for testing and sandboxing.

Parameters:
args - The test data directory.