net.sourceforge.groboutils.junit.v1
Class AssertTestFactory

java.lang.Object
  extended bynet.sourceforge.groboutils.junit.v1.AssertTestFactory

public class AssertTestFactory
extends java.lang.Object

A factory that creates test instances for the standard set of assert methods. The created test instances should have their setName() method invoked to properly set the name of the test. Alternatively, the factory instance can have the name set so that all tests will have the same name.

To support JUnit 3.8 functionality, but remain backwards compatible with earlier JUnit libraries, the names for the JUnit 3.8 methods will be allowed, but they will call JUnit 3.7 compatible methods.

As of Dec 8, 2002, the factory can uniquely (per instance) name each generated test via an index. This can help traceability in identifying each created test. Alternatively, the user can set the factory's name before invoking a create method.

Since:
July 26, 2002
Version:
$Date: 2003/02/10 22:52:19 $
Author:
Matt Albrecht groboclown@users.sourceforge.net

Nested Class Summary
static class AssertTestFactory.InnerTest
          Inner test instance which specializes in generating a message with the test's instance's specific name.
 
Constructor Summary
AssertTestFactory()
          Creates a new factory that can generate assertions as independent test objects.
AssertTestFactory(java.lang.String name)
          Creates a new factory with a specific name for each generated test, but will not add an index to each generated test's name.
AssertTestFactory(java.lang.String name, boolean useIndexWithName)
          Creates a new factory with a specific name for each generated test, and can optionally add an index to each generated test's name.
 
Method Summary
 AssertTestFactory.InnerTest createAssertEquals(boolean expected, boolean actual)
          Asserts that two booleans are equal.
 AssertTestFactory.InnerTest createAssertEquals(byte expected, byte actual)
          Asserts that two bytes are equal.
 AssertTestFactory.InnerTest createAssertEquals(char expected, char actual)
          Asserts that two chars are equal.
 AssertTestFactory.InnerTest createAssertEquals(double expected, double actual, double delta)
          Asserts that two doubles are equal concerning a delta.
 AssertTestFactory.InnerTest createAssertEquals(float expected, float actual, float delta)
          Asserts that two floats are equal concerning a delta.
 AssertTestFactory.InnerTest createAssertEquals(int expected, int actual)
          Asserts that two ints are equal.
 AssertTestFactory.InnerTest createAssertEquals(long expected, long actual)
          Asserts that two longs are equal.
 AssertTestFactory.InnerTest createAssertEquals(java.lang.Object expected, java.lang.Object actual)
          Asserts that two objects are equal.
 AssertTestFactory.InnerTest createAssertEquals(short expected, short actual)
          Asserts that two shorts are equal.
 AssertTestFactory.InnerTest createAssertEquals(java.lang.String message, boolean expected, boolean actual)
          Asserts that two booleans are equal.
 AssertTestFactory.InnerTest createAssertEquals(java.lang.String message, byte expected, byte actual)
          Asserts that two bytes are equal.
 AssertTestFactory.InnerTest createAssertEquals(java.lang.String message, char expected, char actual)
          Asserts that two chars are equal.
 AssertTestFactory.InnerTest createAssertEquals(java.lang.String message, double expected, double actual, double delta)
          Asserts that two doubles are equal concerning a delta.
 AssertTestFactory.InnerTest createAssertEquals(java.lang.String message, float expected, float actual, float delta)
          Asserts that two floats are equal concerning a delta.
 AssertTestFactory.InnerTest createAssertEquals(java.lang.String message, int expected, int actual)
          Asserts that two ints are equal.
 AssertTestFactory.InnerTest createAssertEquals(java.lang.String message, long expected, long actual)
          Asserts that two longs are equal.
 AssertTestFactory.InnerTest createAssertEquals(java.lang.String message, java.lang.Object expected, java.lang.Object actual)
          Asserts that two objects are equal.
 AssertTestFactory.InnerTest createAssertEquals(java.lang.String message, short expected, short actual)
          Asserts that two shorts are equal.
 AssertTestFactory.InnerTest createAssertEquals(java.lang.String expected, java.lang.String actual)
          Asserts that two objects are equal.
 AssertTestFactory.InnerTest createAssertEquals(java.lang.String message, java.lang.String expected, java.lang.String actual)
          Asserts that two objects are equal.
 AssertTestFactory.InnerTest createAssertFalse(boolean condition)
          Asserts that a condition is true.
 AssertTestFactory.InnerTest createAssertFalse(java.lang.String message, boolean condition)
          Asserts that a condition is false.
 AssertTestFactory.InnerTest createAssertNotNull(java.lang.Object object)
          Asserts that an object isn't null.
 AssertTestFactory.InnerTest createAssertNotNull(java.lang.String message, java.lang.Object object)
          Asserts that an object isn't null.
 AssertTestFactory.InnerTest createAssertNotSame(java.lang.Object expected, java.lang.Object actual)
          Asserts that two objects refer to the same object.
 AssertTestFactory.InnerTest createAssertNotSame(java.lang.String message, java.lang.Object expected, java.lang.Object actual)
          Asserts that two objects refer to the same object.
 AssertTestFactory.InnerTest createAssertNull(java.lang.Object object)
          Asserts that an object is null.
 AssertTestFactory.InnerTest createAssertNull(java.lang.String message, java.lang.Object object)
          Asserts that an object is null.
 AssertTestFactory.InnerTest createAssertSame(java.lang.Object expected, java.lang.Object actual)
          Asserts that two objects refer to the same object.
 AssertTestFactory.InnerTest createAssertSame(java.lang.String message, java.lang.Object expected, java.lang.Object actual)
          Asserts that two objects refer to the same object.
 AssertTestFactory.InnerTest createAssertTrue(boolean condition)
          Asserts that a condition is true.
 AssertTestFactory.InnerTest createAssertTrue(java.lang.String message, boolean condition)
          Asserts that a condition is true.
 AssertTestFactory.InnerTest createFail()
          Fails a test with no message.
 AssertTestFactory.InnerTest createFail(java.lang.String message)
          Fails a test with the given message.
 java.lang.String getName()
          Returns the default test name.
 boolean getUseIndexWithName()
          Returns whether each generated test will add a unique (for this instance) index to the test's name.
 void setName(java.lang.String name)
          Sets the default test name.
 void setUseIndexWithName(boolean useIndexWithName)
          Sets whether each generated test will add a unique (for this instance) index to the test's name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AssertTestFactory

public AssertTestFactory()
Creates a new factory that can generate assertions as independent test objects.


AssertTestFactory

public AssertTestFactory(java.lang.String name)
Creates a new factory with a specific name for each generated test, but will not add an index to each generated test's name.

Parameters:
name - default name shared by all generated assertion tests.

AssertTestFactory

public AssertTestFactory(java.lang.String name,
                         boolean useIndexWithName)
Creates a new factory with a specific name for each generated test, and can optionally add an index to each generated test's name.

Parameters:
name - default name shared by all generated assertion tests.
useIndexWithName - true if indecies will be appended to each generated test's name, or false if they will use the passed-in name exactly.
Since:
08-Dec-2002
Method Detail

setName

public void setName(java.lang.String name)
Sets the default test name. This will not reset the generated index.

Parameters:
name - default name shared by all generated assertion tests.

getName

public java.lang.String getName()
Returns the default test name. If the name has never been set, then this will return null.

Returns:
default name shared by all generated assertion tests.

setUseIndexWithName

public void setUseIndexWithName(boolean useIndexWithName)
Sets whether each generated test will add a unique (for this instance) index to the test's name. Reseting this value will not affect the index's value.

Parameters:
useIndexWithName - true if indecies will be appended to each generated test's name, or false if they will use the passed-in name exactly.
Since:
08-Dec-2002

getUseIndexWithName

public boolean getUseIndexWithName()
Returns whether each generated test will add a unique (for this instance) index to the test's name.

Returns:
true if an index is appended to the name, or false if the test's name is exactly the factory's name.
Since:
08-Dec-2002

createAssertTrue

public AssertTestFactory.InnerTest createAssertTrue(java.lang.String message,
                                                    boolean condition)
Asserts that a condition is true. If it isn't it throws an AssertionFailedError with the given message.

Parameters:
message - message that describes what failed if the assertion fails.
condition - boolean to check for failure

createAssertTrue

public AssertTestFactory.InnerTest createAssertTrue(boolean condition)
Asserts that a condition is true. If it isn't it throws an AssertionFailedError.

Parameters:
condition - boolean to check for failure

createAssertFalse

public AssertTestFactory.InnerTest createAssertFalse(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 - message that describes what failed if the assertion fails.
condition - boolean to check for failure
Since:
30-Oct-2002

createAssertFalse

public AssertTestFactory.InnerTest createAssertFalse(boolean condition)
Asserts that a condition is true. If it isn't it throws an AssertionFailedError.

Parameters:
condition - boolean to check for failure
Since:
30-Oct-2002

createFail

public AssertTestFactory.InnerTest createFail(java.lang.String message)
Fails a test with the given message.

Parameters:
message - message that describes what failed if the assertion fails.

createFail

public AssertTestFactory.InnerTest createFail()
Fails a test with no message.


createAssertEquals

public AssertTestFactory.InnerTest createAssertEquals(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.

Parameters:
message - message that describes what failed if the assertion fails.
expected - value that the test expects to find from the tested code.
actual - actual value generated by tested code.

createAssertEquals

public AssertTestFactory.InnerTest createAssertEquals(java.lang.Object expected,
                                                      java.lang.Object actual)
Asserts that two objects are equal. If they are not an AssertionFailedError is thrown.

Parameters:
expected - value that the test expects to find from the tested code.
actual - actual value generated by tested code.

createAssertEquals

public AssertTestFactory.InnerTest createAssertEquals(java.lang.String message,
                                                      java.lang.String expected,
                                                      java.lang.String actual)
Asserts that two objects are equal. If they are not an AssertionFailedError is thrown.

Parameters:
message - message that describes what failed if the assertion fails.
expected - value that the test expects to find from the tested code.
actual - actual value generated by tested code.
Since:
30-Oct-2002

createAssertEquals

public AssertTestFactory.InnerTest createAssertEquals(java.lang.String expected,
                                                      java.lang.String actual)
Asserts that two objects are equal. If they are not an AssertionFailedError is thrown.

Parameters:
expected - value that the test expects to find from the tested code.
actual - actual value generated by tested code.
Since:
30-Oct-2002

createAssertEquals

public AssertTestFactory.InnerTest createAssertEquals(java.lang.String message,
                                                      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:
message - message that describes what failed if the assertion fails.
expected - value that the test expects to find from the tested code.
actual - actual value generated by tested code.
delta - maximum distance between expected and actual such that the two values are considered equivalent. Necessary since floating-point numbers on computers are approximations of their equivalent values; that is, storing 1.1 may actually be stored as 1.099999999999.

createAssertEquals

public AssertTestFactory.InnerTest createAssertEquals(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 - value that the test expects to find from the tested code.
actual - actual value generated by tested code.
delta - maximum distance between expected and actual such that the two values are considered equivalent. Necessary since floating-point numbers on computers are approximations of their equivalent values; that is, storing 1.1 may actually be stored as 1.099999999999.

createAssertEquals

public AssertTestFactory.InnerTest createAssertEquals(java.lang.String message,
                                                      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:
message - message that describes what failed if the assertion fails.
expected - value that the test expects to find from the tested code.
actual - actual value generated by tested code.
delta - maximum distance between expected and actual such that the two values are considered equivalent. Necessary since floating-point numbers on computers are approximations of their equivalent values; that is, storing 1.1 may actually be stored as 1.099999999999.

createAssertEquals

public AssertTestFactory.InnerTest createAssertEquals(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 - value that the test expects to find from the tested code.
actual - actual value generated by tested code.
delta - maximum distance between expected and actual such that the two values are considered equivalent. Necessary since floating-point numbers on computers are approximations of their equivalent values; that is, storing 1.1 may actually be stored as 1.099999999999.

createAssertEquals

public AssertTestFactory.InnerTest createAssertEquals(java.lang.String message,
                                                      long expected,
                                                      long actual)
Asserts that two longs are equal.

Parameters:
message - message that describes what failed if the assertion fails.
expected - value that the test expects to find from the tested code.
actual - actual value generated by tested code.

createAssertEquals

public AssertTestFactory.InnerTest createAssertEquals(long expected,
                                                      long actual)
Asserts that two longs are equal.

Parameters:
expected - value that the test expects to find from the tested code.
actual - actual value generated by tested code.

createAssertEquals

public AssertTestFactory.InnerTest createAssertEquals(java.lang.String message,
                                                      boolean expected,
                                                      boolean actual)
Asserts that two booleans are equal.

Parameters:
message - message that describes what failed if the assertion fails.
expected - value that the test expects to find from the tested code.
actual - actual value generated by tested code.

createAssertEquals

public AssertTestFactory.InnerTest createAssertEquals(boolean expected,
                                                      boolean actual)
Asserts that two booleans are equal.

Parameters:
expected - value that the test expects to find from the tested code.
actual - actual value generated by tested code.

createAssertEquals

public AssertTestFactory.InnerTest createAssertEquals(java.lang.String message,
                                                      byte expected,
                                                      byte actual)
Asserts that two bytes are equal.

Parameters:
message - message that describes what failed if the assertion fails.
expected - value that the test expects to find from the tested code.
actual - actual value generated by tested code.

createAssertEquals

public AssertTestFactory.InnerTest createAssertEquals(byte expected,
                                                      byte actual)
Asserts that two bytes are equal.

Parameters:
expected - value that the test expects to find from the tested code.
actual - actual value generated by tested code.

createAssertEquals

public AssertTestFactory.InnerTest createAssertEquals(java.lang.String message,
                                                      char expected,
                                                      char actual)
Asserts that two chars are equal.

Parameters:
message - message that describes what failed if the assertion fails.
expected - value that the test expects to find from the tested code.
actual - actual value generated by tested code.

createAssertEquals

public AssertTestFactory.InnerTest createAssertEquals(char expected,
                                                      char actual)
Asserts that two chars are equal.

Parameters:
expected - value that the test expects to find from the tested code.
actual - actual value generated by tested code.

createAssertEquals

public AssertTestFactory.InnerTest createAssertEquals(java.lang.String message,
                                                      short expected,
                                                      short actual)
Asserts that two shorts are equal.

Parameters:
message - message that describes what failed if the assertion fails.
expected - value that the test expects to find from the tested code.
actual - actual value generated by tested code.

createAssertEquals

public AssertTestFactory.InnerTest createAssertEquals(short expected,
                                                      short actual)
Asserts that two shorts are equal.

Parameters:
expected - value that the test expects to find from the tested code.
actual - actual value generated by tested code.

createAssertEquals

public AssertTestFactory.InnerTest createAssertEquals(java.lang.String message,
                                                      int expected,
                                                      int actual)
Asserts that two ints are equal.

Parameters:
message - message that describes what failed if the assertion fails.
expected - value that the test expects to find from the tested code.
actual - actual value generated by tested code.

createAssertEquals

public AssertTestFactory.InnerTest createAssertEquals(int expected,
                                                      int actual)
Asserts that two ints are equal.

Parameters:
expected - value that the test expects to find from the tested code.
actual - actual value generated by tested code.

createAssertNotNull

public AssertTestFactory.InnerTest createAssertNotNull(java.lang.String message,
                                                       java.lang.Object object)
Asserts that an object isn't null.

Parameters:
message - message that describes what failed if the assertion fails.
object - test object that must not be null.

createAssertNotNull

public AssertTestFactory.InnerTest createAssertNotNull(java.lang.Object object)
Asserts that an object isn't null.

Parameters:
object - test object that must not be null.

createAssertNull

public AssertTestFactory.InnerTest createAssertNull(java.lang.String message,
                                                    java.lang.Object object)
Asserts that an object is null.

Parameters:
message - message that describes what failed if the assertion fails.
object - test object that must be null.

createAssertNull

public AssertTestFactory.InnerTest createAssertNull(java.lang.Object object)
Asserts that an object is null.

Parameters:
object - test object that must be null.

createAssertSame

public AssertTestFactory.InnerTest createAssertSame(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.

Parameters:
message - message that describes what failed if the assertion fails.
expected - value that the test expects to find from the tested code.
actual - actual value generated by tested code.

createAssertSame

public AssertTestFactory.InnerTest createAssertSame(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 - value that the test expects to find from the tested code.
actual - actual value generated by tested code.

createAssertNotSame

public AssertTestFactory.InnerTest createAssertNotSame(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.

Parameters:
message - message that describes what failed if the assertion fails.
expected - value that the test expects to not find from the tested code.
actual - actual value generated by tested code.
Since:
30-Oct-2002

createAssertNotSame

public AssertTestFactory.InnerTest createAssertNotSame(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 - value that the test expects to not find from the tested code.
actual - actual value generated by tested code.
Since:
30-Oct-2002


Copyright © 2001-2003 by The GroboUtils Project