public class TestCase
extends junit.framework.TestCase
TestCase
, providing some
additional assertions and methods for providing test data for convenience.
All the existing methods of TestCase
are simply delegated
to the superclass.
Some of the methods are concerned with providing random values; these are deterministic in that the random seed is set to a fixed value when the test case is initialised, so a given test should always be working with the same data, though the same call twice in a given test will provide different random data.
Modifier and Type | Field and Description |
---|---|
static short |
IGNORE_ATTRIBUTE_PRESENCE
|
static short |
IGNORE_ATTRIBUTE_VALUE |
static short |
IGNORE_COMMENTS |
static short |
IGNORE_WHITESPACE |
Constructor and Description |
---|
TestCase()
No-arg constructor.
|
TestCase(java.lang.String name)
Constructs a test case with the given name.
|
Modifier and Type | Method and Description |
---|---|
void |
assertArrayEquals(java.lang.Object expected,
java.lang.Object actual)
Asserts that two arrays have exactly the same contents.
|
void |
assertArrayEquals(java.lang.Object expected,
java.lang.Object actual,
double delta)
Asserts that two numeric arrays have the same contents
within a given tolerance.
|
void |
assertArrayEquals(java.lang.String message,
java.lang.Object expected,
java.lang.Object actual)
Asserts that two arrays have exactly the same contents.
|
void |
assertArrayEquals(java.lang.String message,
java.lang.Object expected,
java.lang.Object actual,
double delta)
Asserts that two numeric arrays have the same contents
within a given tolerance.
|
void |
assertArrayNotEquals(java.lang.Object expected,
java.lang.Object actual)
Asserts that two objects are not arrays with the same contents.
|
void |
assertArrayNotEquals(java.lang.Object expected,
java.lang.Object actual,
double delta)
Asserts that two objects are not numeric arrays having the same
contents within a given tolerance.
|
void |
assertArrayNotEquals(java.lang.String message,
java.lang.Object expected,
java.lang.Object actual)
Asserts that two objects are not arrays with the same contents.
|
void |
assertArrayNotEquals(java.lang.String message,
java.lang.Object expected,
java.lang.Object actual,
double delta)
Asserts that two objects are not numeric arrays having the same
contents within a given tolerance.
|
void |
assertDOMEquals(java.io.InputStream s,
org.w3c.dom.Node actual,
java.lang.String context,
int flags)
Asserts that a DOM is equivalent to the DOM read from a given stream.
|
void |
assertDOMEquals(org.w3c.dom.Node expected,
org.w3c.dom.Node actual)
Asserts that two DOMs are equal.
|
void |
assertDOMEquals(org.w3c.dom.Node expected,
org.w3c.dom.Node actual,
java.lang.String context,
int flags)
Asserts that two DOMs are equal.
|
void |
assertDOMEquals(java.lang.String s,
org.w3c.dom.Node n)
Asserts that a DOM is equivalent to the DOM implied by the XML
in a given string.
|
void |
assertDOMEquals(java.lang.String expected,
org.w3c.dom.Node actual,
java.lang.String context,
int flags)
Asserts that a DOM is equivalent to the DOM implied by the XML
in a given string.
|
void |
assertDOMEquals(java.net.URL url,
org.w3c.dom.Node actual)
Asserts that a DOM is equivalent to the XML in a given URL.
|
void |
assertDOMEquals(java.net.URL url,
org.w3c.dom.Node actual,
java.lang.String context,
int flags)
Asserts that a DOM is equivalent to the XML in a given URL.
|
void |
assertEquals(double expected,
double actual)
Asserts that two
double s are exactly equal. |
void |
assertEquals(float expected,
float actual)
Asserts that two
float s are exactly equal. |
void |
assertEquals(java.lang.String message,
double expected,
double actual)
Asserts that two
double s are exactly equal. |
void |
assertEquals(java.lang.String message,
float expected,
float actual)
Asserts that two
float s are exactly equal. |
void |
assertSourceEquals(javax.xml.transform.Source expected,
javax.xml.transform.Source actual,
java.lang.String context,
int flags)
Asserts that two XML
Source objects
represent the same XML Infoset. |
void |
assertValidXML(org.xml.sax.InputSource isrc)
Asserts that the contents of a stream are valid XML.
|
void |
assertValidXML(java.lang.String message,
org.xml.sax.InputSource isrc)
Asserts that the contents of a stream are valid XML.
|
void |
fillCycle(java.lang.Object array,
int min,
int max)
Fills a given array with a regular pattern of integer values.
|
void |
fillCycle(java.lang.Object destArray,
java.lang.Object sourceArray)
Fills a given array with a pattern of values taken from another one.
|
void |
fillRandom(java.lang.Object array,
double min,
double max)
Fills a given array with random numbers between two floating point
values.
|
void |
fillRandom(java.lang.Object array,
int min,
int max)
Fills a given array with random numbers between two integer values.
|
static boolean |
isHeadless()
Tests whether or not a display, keyboard and mouse can in fact
be supported in this environment.
|
countTestCases, createResult, getName, run, run, runBare, runTest, setName, setUp, tearDown, toString
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
public static final short IGNORE_ATTRIBUTE_PRESENCE
public static final short IGNORE_ATTRIBUTE_VALUE
public static final short IGNORE_WHITESPACE
public static final short IGNORE_COMMENTS
public TestCase()
public TestCase(java.lang.String name)
name
- test case namepublic void assertArrayEquals(java.lang.String message, java.lang.Object expected, java.lang.Object actual)
expected
and
actual
must both be array objects whose component types are of the same
class; they must have the same number of elements; and the
ith element of expected
must be `equal' to the
ith element of actual
. `Equality' in this sense
depends on the types of the arrays: if they are arrays of a primitive
type, the primitive values must be equal, and if they are
object arrays equality is assessed using the
Object.equals(java.lang.Object)
method.
In the case of float[]
and double[]
arrays,
elements which both have the value NaN
are taken to match.message
- the message to output if the assertion failsexpected
- the expected array objectactual
- the actual array objectjunit.framework.AssertionFailedError
- if the assertion is untruepublic void assertArrayNotEquals(java.lang.String message, java.lang.Object expected, java.lang.Object actual)
assertArrayEquals(String,Object,Object)
.message
- the message to output if the assertion failsexpected
- the expected array objectactual
- the actual array object,
asserted not to match expected
junit.framework.AssertionFailedError
- if the assertion is untruepublic void assertArrayEquals(java.lang.Object expected, java.lang.Object actual)
expected
and actual
must both be array objects whose component types are of the same
class; they must have the same number of elements; and the
ith element of expected
must be `equal' to the
ith element of actual
. `Equality' in this sense
depends on the types of the arrays: if they are arrays of a primitive
type, the primitive values must be equal, and if they are
object arrays equality is assessed using the
Object.equals(java.lang.Object)
method.
In the case of float[]
and double[]
arrays,
elements which both have the value NaN
are taken to match.expected
- the expected array objectactual
- the actual array objectjunit.framework.AssertionFailedError
- if the assertion is untruepublic void assertArrayNotEquals(java.lang.Object expected, java.lang.Object actual)
assertArrayEquals(Object,Object)
.expected
- the expected array objectactual
- the actual array object,
asserted not to match expected
junit.framework.AssertionFailedError
- if the assertion is untruepublic void assertArrayEquals(java.lang.String message, java.lang.Object expected, java.lang.Object actual, double delta)
expected
and actual
must both be primitive numeric array objects whose
component types are of the same
class; they must have the same number of elements; and the
ith element of expected
must be `equal' to the
ith element of actual
.
Equality in this sense normally means
(abs(expected[i]-actual[i]<delta)
,
but in the case of float[]
and double[]
arrays,
elements which both have the value NaN
are taken to match,
and if the expected element is infinite, then delta
is ignored.
If delta<1
and the arrays are of integer type,
this method does the same as
assertArrayEquals(String,Object,Object)
.
message
- the message to output if the assertion failsexpected
- the array object containing the expected valuesactual
- the array object containing the actual valuesdelta
- the tolerance acceptable between valuesjunit.framework.AssertionFailedError
- if the assertion is untruepublic void assertArrayNotEquals(java.lang.String message, java.lang.Object expected, java.lang.Object actual, double delta)
assertArrayEquals(String,Object,Object,double)
.message
- the message to output if the assertion failsexpected
- the array object containing the expected valuesactual
- the array object containing the actual values,
asserted not to match expected
delta
- the tolerance acceptable between valuesjunit.framework.AssertionFailedError
- if the assertion is untruepublic void assertArrayEquals(java.lang.Object expected, java.lang.Object actual, double delta)
expected
and actual
must both be primitive numeric array objects whose component
types are of the same
class; they must have the same number of elements; and the
ith element of expected
must be `equal' to the
ith element of actual
.
Equality in this sense normally means
(abs(expected[i]-actual[i]<delta)
,
but in the case of float[]
and double[]
arrays,
elements which both have the value NaN
are taken to match,
and if the expected element is infinite, then delta
is ignored.
If delta<1
and the arrays are of integer type,
this method does the same as
assertArrayEquals(Object,Object)
.
expected
- the array object containing the expected valuesactual
- the array object containing the actual valuesdelta
- the tolerance acceptable between valuesjunit.framework.AssertionFailedError
- if the assertion is untruepublic void assertArrayNotEquals(java.lang.Object expected, java.lang.Object actual, double delta)
assertArrayEquals(Object,Object,double)
.expected
- the array object containing the expected valuesactual
- the array object containing the actual values,
asserted not to match expected
delta
- the tolerance acceptable between valuesjunit.framework.AssertionFailedError
- if the assertion is untruepublic void assertEquals(java.lang.String message, float expected, float actual)
float
s are exactly equal.message
- the message to output if the assertion failsexpected
- the expected valueactual
- the actual valuejunit.framework.AssertionFailedError
- if the assertion is untruepublic void assertEquals(float expected, float actual)
float
s are exactly equal.expected
- the expected valueactual
- the actual valuejunit.framework.AssertionFailedError
- if the assertion is untruepublic void assertEquals(java.lang.String message, double expected, double actual)
double
s are exactly equal.message
- the message to output if the assertion failsexpected
- the expected valueactual
- the actual valuejunit.framework.AssertionFailedError
- if the assertion is untruepublic void assertEquals(double expected, double actual)
double
s are exactly equal.expected
- the expected valueactual
- the actual valuejunit.framework.AssertionFailedError
- if the assertion is untruepublic void assertDOMEquals(java.net.URL url, org.w3c.dom.Node actual) throws java.io.IOException, org.xml.sax.SAXException, javax.xml.parsers.ParserConfigurationException
assertDOMEquals(dom, actual, filename, 0)
with
the first argument being the document element of the DOM read
from the URL, and the third argument being the last part
(the `file name') of the URL.url
- pointing to an XML file -- the document element of
this file is the expected valueactual
- the node which is being comparedjava.io.IOException
- if the file cannot be foundorg.xml.sax.SAXException
- if there is a problem parsing the XMLjavax.xml.parsers.ParserConfigurationException
- if the
XML parser cannot be initialisedjunit.framework.AssertionFailedError
- if the assertion is untrueassertDOMEquals(Node,Node,String,int)
public void assertDOMEquals(java.net.URL url, org.w3c.dom.Node actual, java.lang.String context, int flags) throws java.io.IOException, org.xml.sax.SAXException, javax.xml.parsers.ParserConfigurationException
assertDOMEquals(dom, actual, context, flags)
with
the first argument being the document element of the DOM read
from the URL, and the third argument being the last part
(the `file name') of the URL.url
- pointing to an XML file -- the document element of
this file is the expected valueactual
- the node which is being comparedcontext
- a string indicating the context of this; if
null
, it defaults to `string:'flags
- a set of flags controlling the comparison; see
assertDOMEquals(Node,Node,String,int)
java.io.IOException
- if the file cannot be foundorg.xml.sax.SAXException
- if there is a problem parsing the XMLjavax.xml.parsers.ParserConfigurationException
- if the
XML parser cannot be initialisedjunit.framework.AssertionFailedError
- if the assertion is untrueassertDOMEquals(Node,Node,String,int)
public void assertDOMEquals(java.lang.String s, org.w3c.dom.Node n) throws java.io.IOException, org.xml.sax.SAXException, javax.xml.parsers.ParserConfigurationException
java.io.IOException
org.xml.sax.SAXException
javax.xml.parsers.ParserConfigurationException
assertDOMEquals(String,Node,String,int)
public void assertDOMEquals(java.lang.String expected, org.w3c.dom.Node actual, java.lang.String context, int flags) throws java.io.IOException, org.xml.sax.SAXException, javax.xml.parsers.ParserConfigurationException
expected
- a string containing XML -- the document element of
this file is the expected valueactual
- the node which is comparedcontext
- a string indicating the context of this; if
null
, it defaults to `string:'flags
- a set of flags controlling the comparison; see
assertDOMEquals(Node,Node,String,int)
junit.framework.AssertionFailedError
- if the assertion is untruejava.io.IOException
org.xml.sax.SAXException
javax.xml.parsers.ParserConfigurationException
assertDOMEquals(Node,Node,String,int)
public void assertDOMEquals(java.io.InputStream s, org.w3c.dom.Node actual, java.lang.String context, int flags) throws java.io.IOException, org.xml.sax.SAXException, javax.xml.parsers.ParserConfigurationException
s
- a stream from which XML may be read -- the document element of
the resulting DOM is the expected valueactual
- the node which is comparedcontext
- a string indicating the context of this; may be
null
flags
- a set of flags controlling the comparison; see
assertDOMEquals(Node,Node,String,int)
junit.framework.AssertionFailedError
- if the assertion is untruejava.io.IOException
org.xml.sax.SAXException
javax.xml.parsers.ParserConfigurationException
assertDOMEquals(Node,Node,String,int)
public void assertDOMEquals(org.w3c.dom.Node expected, org.w3c.dom.Node actual)
expected
- the Node containing the expected DOMactual
- the Node to be testedjunit.framework.AssertionFailedError
- if the assertion is untrueassertDOMEquals(Node,Node,String,int)
public void assertSourceEquals(javax.xml.transform.Source expected, javax.xml.transform.Source actual, java.lang.String context, int flags)
Source
objects
represent the same XML Infoset. Differences in whitespace and
in comments may optionally be ignored.expected
- the Source object containing the expected infosetactual
- the Source object containing the actual infoset,
asserted to match expected
context
- a string indicating the context of this; may be
null
flags
- a set of flags indicating which node tests to
omit. Passing as zero includes all tests.junit.framework.AssertionFailedError
- if the assertion is untrueassertDOMEquals(Node,Node,String,int)
public void assertDOMEquals(org.w3c.dom.Node expected, org.w3c.dom.Node actual, java.lang.String context, int flags)
If an assertion fails, the method indicates the location by showing in the failure message the location of the mismatched node, so that
AssertionFailedError: .../test.xml:/[1]ndx/[2]data expected: ...indicates that the assertion failed when examining the second child node (which was a
<data>
element) of the first
child of the file test.xml
If the flags
argument is non-zero, it indicates
a set of tests on the DOM to omit. The value is ORed together
from the following constants:
TestCase.IGNORE_ATTRIBUTE_PRESENCE
TestCase.IGNORE_ATTRIBUTE_VALUE
TestCase.IGNORE_WHITESPACE
TestCase.IGNORE_COMMENTS
expected
- the Node containing the expected DOMactual
- the Node to be testedcontext
- a string indicating the context, which will be
used in assertion failure reports. May be nullflags
- a set of flags indicating which node tests to
omit. Passing as zero includes all tests.junit.framework.AssertionFailedError
- if the assertion is untruepublic void assertValidXML(java.lang.String message, org.xml.sax.InputSource isrc) throws java.io.IOException, org.xml.sax.SAXException
Entity resolution is done using an instance of
StarEntityResolver
.
message
- message associated with assertion failureisrc
- input source containing an XML documentjava.io.IOException
- if there is an error reading strm
org.xml.sax.SAXException
- if the document in strm
is badly-formed or invalidpublic void assertValidXML(org.xml.sax.InputSource isrc) throws java.io.IOException, org.xml.sax.SAXException
isrc
- input stream containing an XML documentjava.io.IOException
- if there is an error reading strm
org.xml.sax.SAXException
- if the document in strm
is badly-formed or invalidpublic void fillRandom(java.lang.Object array, double min, double max)
array
- an array of primitives to be filled with
random valuesmin
- the smallest value which will be used
(will be converted to the appropriate primitive type)max
- the largest value which will be used
(will be converted to the appropriate primitive type)java.lang.IllegalArgumentException
- if array
is not an array
of a suitable primitive typepublic void fillRandom(java.lang.Object array, int min, int max)
array
- an array of primitives to be filled with
random valuesmin
- the smallest value which will be used
(will be converted to the appropriate primitive type)max
- the largest value which will be used
(will be converted to the appropriate primitive type)java.lang.IllegalArgumentException
- if array
is not an array
of a suitable primitive typepublic void fillCycle(java.lang.Object array, int min, int max)
min, min+1, min+2 .. max-1, min, min+1, min+2..
and so on.
If the max<min
then the values will start at
min
and keep increasing.
The results might not be as expected if you use a min
and
max
values outside the range
of the numeric type in question.
array
- an array of primitives to be filled with cycling valuesmin
- the first valuemax
- the highest value, or if less than min
an
indication that there is no maximumjava.lang.IllegalArgumentException
- if array
is not an array
of a suitable primitive typepublic void fillCycle(java.lang.Object destArray, java.lang.Object sourceArray)
destArray
is filled up with copies of
sourceArray
.
destArray
and sourceArray
must be arrays of the
same class (but can be different lengths of course).destArray
- array to be filled with itemssourceArray
- array containing source itemspublic static boolean isHeadless()
GraphicsEnvironment.isHeadless()
method in that
this one tries to do some graphics and if it catches a throwable
as a consequence it will return true. The only time that
the GraphicsEnvironment
call returns true in practice
is if you start java with the property
java.awt.headless=true
.true
if graphics type stuff will fail