PIRL

PIRL.Utilities
Class Checker

java.lang.Object
  extended by PIRL.Utilities.Checker

public class Checker
extends Object

A Checker is used to compare expected against obtained results for unit testing.

A set of Check methods compares an expected argument value with an obtained argument value for equality. When the arguments match the word "PASS" is printed, otherwise the word "FAIL" is printed. This is followed by ": " and the description String that very briefly identifies what was checked (i.e. the unit test that occured). The obtained value will then be printed following " - " if the Show_Obtained flag is enabled. If the comparison does not match, or the Check is Verbose, the expected and obtained arguments are printed on the next two lines following an "====> expected: " and "====> obtained: " prefix.

Check methods are provided for integer, floating point, boolean and char values as well as String and generic Object values. String values are printed enclosed in double quotes (") and char values are listed enclosed in single quotes (').

The total number of checks performed (Checks_Total), and the number in which the comparison matched (Checks_Passed), is accumulated by each Check method.

Version:
1.6
Author:
Bradford Castalia

Field Summary
 int Checks_Passed
          Total number of Checks where expected matched obtained.
 int Checks_Total
          Total number of Checks performed.
static String ID
           
 boolean Show_Obtained
          Set to true to always show the obtained value.
 boolean Verbose
          Set to true to always show both the expected and obtained values.
 
Constructor Summary
Checker()
           
 
Method Summary
 boolean Check(boolean passed)
          Updates the check accounting.
 boolean Check(String description, boolean expected, boolean obtained)
          Checks boolean values.
 boolean Check(String description, char expected, char obtained)
          Checks char values.
 boolean Check(String description, double expected, double obtained)
          Checks floating point values.
 boolean Check(String description, Exception expected, Exception obtained)
          Checks Exceptions.
 boolean Check(String description, long expected, long obtained)
          Checks integer values.
 boolean Check(String description, Object expected, Object obtained)
          Checks Objects.
 boolean Check(String description, String expected, String obtained)
          Checks String values.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ID

public static final String ID
See Also:
Constant Field Values

Checks_Total

public int Checks_Total
Total number of Checks performed.


Checks_Passed

public int Checks_Passed
Total number of Checks where expected matched obtained.


Verbose

public boolean Verbose
Set to true to always show both the expected and obtained values.

Default is false;


Show_Obtained

public boolean Show_Obtained
Set to true to always show the obtained value.

Default is false;

Constructor Detail

Checker

public Checker()
Method Detail

Check

public boolean Check(String description,
                     long expected,
                     long obtained)
Checks integer values.

Parameters:
description - A brief description of what was checked.
expected - The expected value.
obtained - The obtained value.
Returns:
true if expected equals obtained; false otherwise.

Check

public boolean Check(String description,
                     double expected,
                     double obtained)
Checks floating point values.

Parameters:
description - A brief description of what was checked.
expected - The expected value.
obtained - The obtained value.
Returns:
true if expected equals obtained; false otherwise.

Check

public boolean Check(String description,
                     boolean expected,
                     boolean obtained)
Checks boolean values.

Parameters:
description - A brief description of what was checked.
expected - The expected value.
obtained - The obtained value.
Returns:
true if expected equals obtained; false otherwise.

Check

public boolean Check(String description,
                     char expected,
                     char obtained)
Checks char values.

Parameters:
description - A brief description of what was checked.
expected - The expected value.
obtained - The obtained value.
Returns:
true if expected equals obtained; false otherwise.

Check

public boolean Check(String description,
                     String expected,
                     String obtained)
Checks String values.

Parameters:
description - A brief description of what was checked.
expected - The expected value.
obtained - The obtained value.
Returns:
true if expected equals obtained; false otherwise.

Check

public boolean Check(String description,
                     Exception expected,
                     Exception obtained)
Checks Exceptions.

If both the excpected and obtained exception are null they are equal. If both are non-null the class of each are checked for equality. If only one exception is null they are not equal.

Parameters:
description - A brief description of what was checked.
expected - The expected Exception.
obtained - The obtained Exception.
Returns:
true if expected equals obtained; false otherwise.

Check

public boolean Check(String description,
                     Object expected,
                     Object obtained)
Checks Objects.

If both objects are null they are equal. N.B.: The Object.equals(Object) method is used to compare a non-null expected Object with the obtained object, which may not be what is expected since this comparison is only true if both arguments are the same Object reference.

Parameters:
description - A brief description of what was checked.
expected - The expected Object.
obtained - The obtained Object.
Returns:
true if expected equals obtained; false otherwise.

Check

public boolean Check(boolean passed)
Updates the check accounting.

The Checks_Total accumulator is incremented. The Checks_Passed accumulator is incremented if passed is true.

Parameters:
passed - true if the external test passed; false otherwise.
Returns:
The passed value.

PIRL

Copyright (C) \ 2003-2009 Bradford Castalia, University of Arizona