Package dk.netarkivet.testutils
Class ClassAsserts
- java.lang.Object
-
- dk.netarkivet.testutils.ClassAsserts
-
public class ClassAsserts extends Object
Utility class containing various method for making assertions on Class objects.
-
-
Constructor Summary
Constructors Constructor Description ClassAsserts()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
assertEqualsValid(Object o1, Object o2, List excludedFields)
Tests that a class' equals method notice changed fields.static void
assertHasFactoryMethod(Class c)
Tests the class has a static factory method getInstance()static <T> void
assertPrivateConstructor(Class<T> c)
Tests if there are any public constructors.static <T> T
assertSingleton(Class<T> c)
Tests that a class has a static factory method getInstance() and that it acts as a singleton.
-
-
-
Method Detail
-
assertHasFactoryMethod
public static void assertHasFactoryMethod(Class c)
Tests the class has a static factory method getInstance()- Parameters:
c
- the class to test
-
assertSingleton
public static <T> T assertSingleton(Class<T> c)
Tests that a class has a static factory method getInstance() and that it acts as a singleton. NB This method will create an instance of the class. It is your responsibility to clean up after yourself.- Parameters:
c
- the class to test- Returns:
- the singleton
-
assertPrivateConstructor
public static <T> void assertPrivateConstructor(Class<T> c)
Tests if there are any public constructors. Will fail on any public constructor, and simply return otherwise.- Parameters:
c
- A class to test.
-
assertEqualsValid
public static void assertEqualsValid(Object o1, Object o2, List excludedFields) throws IllegalAccessException
Tests that a class' equals method notice changed fields. Also performs some testing of the hashCode method, but not as comprehensive.- Parameters:
o1
- An object to test on.o2
- Another object with all fields to be tested set to different values from o1excludedFields
- A list of field names of fields that should not be included in the test.- Throws:
IllegalAccessException
-
-