public class JGuiraffeTestHelper extends Object
A helper class with functionality that can be used by test classes.
This class contains a set of utility methods that are useful for many test classes. Because of that this functionality was extracted into its own utility class.
Constructor and Description |
---|
JGuiraffeTestHelper() |
Modifier and Type | Method and Description |
---|---|
static void |
checkEquals(Object o1,
Object o2,
boolean expected)
Tests the implementation of
equals() and (partly)
hashCode() . |
static boolean |
collectionEquals(Collection<?> c1,
Collection<?> c2)
Tests whether the specified collections are equal.
|
static Date |
createDate(int year,
int month,
int day)
Helper method for creating a date object based on the given year, month,
and day.
|
static ByteArrayOutputStream |
readStream(InputStream in,
boolean close)
Reads the content of the specified input stream and provides it as byte
array stream.
|
static <T> T |
serialize(T obj)
Helper method for serializing an object.
|
static void |
testTrivialEquals(Object obj)
Helper method for performing some trivial checks of the equals() method
of an object.
|
public static void checkEquals(Object o1, Object o2, boolean expected)
equals()
and (partly)
hashCode()
. The passed in first object is compared with the
second with the expected result. Then it is checked whether equals() is
symmetric. If the expected result is true, the hash codes must
also match.o1
- the first object (must not be null)o2
- the second object (can be null)expected
- the expected result of the comparisonpublic static void testTrivialEquals(Object obj)
obj
- the object to check (must not be nullpublic static ByteArrayOutputStream readStream(InputStream in, boolean close)
close
parameter determines whether the input stream is
to be closed after it was completely read. Occurring exceptions are
re-thrown as runtime exceptions.in
- the input stream to readclose
- a flag whether the stream is to be closedpublic static Date createDate(int year, int month, int day)
Calendar
, populates it
with the given date values, and returns the corresponding Date
.year
- the yearmonth
- the month (note: this is 0-based!)day
- the daypublic static boolean collectionEquals(Collection<?> c1, Collection<?> c2)
c1
- collection 1c2
- collection 2public static <T> T serialize(T obj) throws IOException
T
- the type of the objectobj
- the object to be serializedIOException
- if an IO exception occurs (typically because the
object cannot be serialized)Copyright © 2016 The JGUIraffe Team. All rights reserved.