|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjunit.framework.Assert
junit.framework.TestCase
junit.com.mcdermottroe.exemplar.ExemplarTestCase<T>
junit.com.mcdermottroe.exemplar.NormalClassTestCase<T>
T - The type of the class being tested.public abstract class NormalClassTestCase<T extends Copyable<T> & Comparable<T>>
Base class for JUnit tests that test classes which produce "normal" classes. That includes all classes that are not abstract, exceptions or utility classes.
| Field Summary | |
|---|---|
protected boolean |
allowPublicStaticMembers
Flag to set if we allow 'public static final' members in the tested class. |
protected boolean |
ignoreHashCodeTests
Flag to set if we don't want to run any tests on the Object.hashCode() method of the Object. |
private List<T> |
sampleObjects
A selection of sample Objects which can be used within the
tests. |
| Fields inherited from class junit.com.mcdermottroe.exemplar.ExemplarTestCase |
|---|
DELIBERATE_PASS, testedClass, TMP |
| Constructor Summary | |
|---|---|
NormalClassTestCase()
|
|
| Method Summary | |
|---|---|
protected void |
addSample(T sample)
Add a sample to the collection of sample objects. |
private boolean |
hasEquals()
Test whether or not the tested class implements an Object.equals(Object) method. |
private boolean |
hasHashCode()
Test whether or not the tested class implements a Object.hashCode() method. |
private boolean |
hasToString()
Test whether or not the tested class implements a Object.toString() method. |
protected List<T> |
samples()
Provide a List of sample objects to operate on. |
void |
setUp()
Set up the JUnit test. |
void |
testAllConstructorsNonPrivate()
This test ensures that there are no private constructors declared. |
void |
testAllFieldsPrivateOrProtectedOrPublicStaticFinal()
All fields must be either 'private', 'protected' or (if allowed by the allowPublicStaticMembers flag) 'public
static final'. |
void |
testCompareToConsistentWithEquals()
Test to ensure that a.compareTo(b) == 0 implies a.equals(b). |
void |
testCompareToNullThrowsNPE()
Test that Comparable.compareTo(Object) throws a NullPointerException when given null as its parameter. |
void |
testCompareToSignsConsistent()
Test that: Integer.signum(a.compareTo(b)) == -Integer.signum(b.compareTo(a)) as required by the contract of Comparable.compareTo(Object). |
void |
testCompareToTransitive()
Test to ensure that: (a.compareTo(b) op 0 && b.compareTo(c) op 0) implies a.compareTo(c) op 0. |
void |
testCopyable()
This ensures that it is possible to call Copyable.getCopy() and
not have an exception thrown. |
void |
testEqualsConsistent()
Methods implementing Object.equals(Object) are required to be
consistent. |
void |
testEqualsNullFalse()
Every call to equals where the parameter is null must return false. |
void |
testEqualsNullPointerException()
Test equals with an object which is not of the same type. |
void |
testEqualsReflexive()
Methods implementing Object.equals(Object) are required to be
reflexive. |
void |
testEqualsSymmetric()
Methods implementing Object.equals(Object) are required to be
symmetric. |
void |
testEqualsTransitive()
Methods implementing Object.equals(Object) are required to be
transitive. |
void |
testGetCopyProducesIdenticalObject()
This ensures that it is possible to call Copyable.getCopy() and
get an object which is equal to, but not the same (referentially) to the
original object. |
void |
testHashCodeConsistentOverTime()
This ensures that the result of Object.hashCode() does not
change over time. |
void |
testHashCodeConsistentWithEquals()
This ensures that where x.equals(y), x.hashCode() == y.hashCode(). |
void |
testImplementsCopyable()
Ensure that all classes are Copyable. |
void |
testSerialization()
Test that all serializable classes serialize and unserialize without apparent loss of information. |
void |
testToStringConsistent()
This ensures that for all non-null Objects x and y,
x.toString().equals(y.toString()) iff x.equals(y). |
| Methods inherited from class junit.com.mcdermottroe.exemplar.ExemplarTestCase |
|---|
getTestedClass, testAllMethodsBeingTested, testCorrectPackage |
| Methods inherited from class junit.framework.TestCase |
|---|
countTestCases, createResult, getName, run, run, runBare, runTest, setName, tearDown, toString |
| Methods inherited from class junit.framework.Assert |
|---|
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail, failNotEquals, failNotSame, failSame, format |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected boolean allowPublicStaticMembers
protected boolean ignoreHashCodeTests
Object.hashCode() method of the Object.
private List<T extends Copyable<T> & Comparable<T>> sampleObjects
Objects which can be used within the
tests. This allows more realistic, but still generalised, testing to be
performed and avoids only testing the no-arg constructor. This List should be initialised in the setUp() method.
| Constructor Detail |
|---|
public NormalClassTestCase()
| Method Detail |
|---|
public void setUp()
throws Exception
setUp in class ExemplarTestCase<T extends Copyable<T> & Comparable<T>>Exception - if TestCase.setUp() throws one.ExemplarTestCase.testedClass,
TestCase.setUp()public void testAllConstructorsNonPrivate()
public void testAllFieldsPrivateOrProtectedOrPublicStaticFinal()
allowPublicStaticMembers flag) 'public
static final'.
public void testHashCodeConsistentOverTime()
Object.hashCode() does not
change over time.
public void testHashCodeConsistentWithEquals()
public void testEqualsReflexive()
Object.equals(Object) are required to be
reflexive. That is, for all non-null reference values x, x.equals(x)
must return true.
public void testEqualsSymmetric()
Object.equals(Object) are required to be
symmetric. That is, for any non-null reference values x and y,
x.equals(y) should return true if and only if y.equals(x) returns
true.
public void testEqualsTransitive()
Object.equals(Object) are required to be
transitive. That is, for any non-null reference values x, y, and z, if
x.equals(y) returns true and y.equals(z) returns true then x.equals(z)
must return true.
public void testEqualsConsistent()
Object.equals(Object) are required to be
consistent. That is, for all non-null reference values x and y,
multiple invocations of x.equals(y) consistently return true or false,
provided no information used in the equals comparisons on the objects
is modified.
public void testEqualsNullFalse()
public void testEqualsNullPointerException()
public void testToStringConsistent()
Objects x and y,
x.toString().equals(y.toString()) iff x.equals(y). This is not required
by the contract of Object.toString() but is an all-round good
idea.
public void testImplementsCopyable()
Copyable.
public void testCopyable()
Copyable.getCopy() and
not have an exception thrown.
public void testGetCopyProducesIdenticalObject()
Copyable.getCopy() and
get an object which is equal to, but not the same (referentially) to the
original object.
public void testCompareToSignsConsistent()
Comparable.compareTo(Object).
public void testCompareToTransitive()
public void testCompareToNullThrowsNPE()
Comparable.compareTo(Object) throws a NullPointerException when given null as its parameter.
public void testCompareToConsistentWithEquals()
public void testSerialization()
protected void addSample(T sample)
throws CopyException
sample - The sample object to add.
CopyException - if copying the sample using Copyable.getCopy() fails.protected List<T> samples()
List of sample objects to operate on.
List of sample objects.private boolean hasEquals()
Object.equals(Object) method.
Object.equals(Object) method, false otherwise.private boolean hasHashCode()
Object.hashCode() method.
Object.hashCode()
method, false otherwise.private boolean hasToString()
Object.toString() method.
Object.toString()
method, false otherwise.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||