Package tech.units.tck.util
Class TestUtils
java.lang.Object
tech.units.tck.util.TestUtils
@Singleton public class TestUtils extends Object
Test utilities used in the JSR 385 TCK.
- Since:
- 1.0
- Version:
- 2.2, November 15, 2020
- Author:
- Werner Keil
-
Field Summary
Fields Modifier and Type Field Description static String
SYS_PROPERTY_OUTPUT_DIR
Name of the system property to override the default output directorystatic String
SYS_PROPERTY_PROFILE
Name of the system property to pass the desired profilestatic String
SYS_PROPERTY_REPORT_FILE
Name of the system property to override the default report filestatic String
SYS_PROPERTY_VERBOSE
Name of the system property to set theverbose
flag -
Method Summary
Modifier and Type Method Description static void
assertValue(String section, Object value, String methodName, Object instance)
Checks the returned value, when calling a given method.static void
testComparable(String section, Class<?> type)
Tests if the given type is comparable.static void
testHasNotPublicMethod(String section, Class<?> type, Class<?> returnType, String name, Class<?>... paramTypes)
Tests if the given type has not a public method with the given signature.static void
testHasPublicMethod(String section, Class<?> type, boolean trySuperclassFirst, Class<?> returnType, String name, Class<?>... paramTypes)
static void
testHasPublicMethod(String section, Class<?> type, Class<?> returnType, String name, Class<?>... paramTypes)
static void
testHasPublicMethod(String section, Class<?> type, String name)
static void
testHasPublicMethod(String section, Class<?> type, String name, boolean hasParameters)
Tests if the given type has a public method with the given signature.static void
testImmutable(String section, Class<?> type)
Tests the given class being serializable.static boolean
testImmutableOpt(String section, Class type)
Test for immutability (optional recommendation), writes a warning if not given.static void
testImplementsInterface(String section, Class<?> type, Class<?> iface)
Tests the given class implements a given interface.static void
testSerializable(String section, Class<?> type)
Tests the given object being (effectively) serializable by serializing it.static void
testSerializable(String section, Object o)
Tests the given object being (effectively) serializable by serializing it.static boolean
testSerializableOpt(String section, Class type)
Test for serializable (optional recommendation), writes a warning if not given.static boolean
testSerializableOpt(String section, Object instance)
Test for serializable (optional recommendation), writes a warning if not given.
-
Field Details
-
SYS_PROPERTY_PROFILE
Name of the system property to pass the desired profile- See Also:
- Constant Field Values
-
SYS_PROPERTY_OUTPUT_DIR
Name of the system property to override the default output directory- See Also:
- Constant Field Values
-
SYS_PROPERTY_REPORT_FILE
Name of the system property to override the default report file- See Also:
- Constant Field Values
-
SYS_PROPERTY_VERBOSE
Name of the system property to set theverbose
flag- See Also:
- Constant Field Values
-
-
Method Details
-
testSerializable
Tests the given object being (effectively) serializable by serializing it.- Parameters:
section
- the section of the spec under testtype
- the type to be checked.- Throws:
TCKValidationException
- if the test fails.
-
testImmutable
Tests the given class being serializable.- Parameters:
section
- the section of the spec under testtype
- the type to be checked.- Throws:
TCKValidationException
- if test fails.
-
testSerializable
Tests the given object being (effectively) serializable by serializing it.- Parameters:
section
- the section of the spec under testo
- the object to be checked.- Throws:
TCKValidationException
- if test fails.
-
testImplementsInterface
Tests the given class implements a given interface.- Parameters:
section
- the section of the spec under testtype
- the type to be checked.iface
- the interface to be checked for. Triggers Assert#fail if test fails.
-
testComparable
Tests if the given type is comparable.- Parameters:
section
- the section of the spec under testtype
- the type to be checked.
-
testHasPublicMethod
public static void testHasPublicMethod(String section, Class<?> type, Class<?> returnType, String name, Class<?>... paramTypes)- Parameters:
section
- the section of the specificationtype
- the type to be checked.returnType
- the expected return typename
- the name of the methodparamTypes
- the types of parameters if available
-
testHasPublicMethod
public static void testHasPublicMethod(String section, Class<?> type, boolean trySuperclassFirst, Class<?> returnType, String name, Class<?>... paramTypes)- Parameters:
section
- the section of the specificationtype
- the data typetrySuperclassFirst
- if tht super class if available should be tested firstreturnType
- the expected return typename
- the name of the methodparamTypes
- types of parameters
-
testHasPublicMethod
public static void testHasPublicMethod(String section, Class<?> type, String name, boolean hasParameters)Tests if the given type has a public method with the given signature.- Parameters:
section
- the section of the spec under testtype
- the type to be checked.name
- the method namehasParameters
- the method has parameters.- Throws:
TCKValidationException
- if test fails.
-
testHasPublicMethod
- Parameters:
section
- the section of the specificationtype
- the data typename
- the name of the method
-
testHasNotPublicMethod
public static void testHasNotPublicMethod(String section, Class<?> type, Class<?> returnType, String name, Class<?>... paramTypes)Tests if the given type has not a public method with the given signature.- Parameters:
section
- the section of the spec under testtype
- the type to be checked.returnType
- the method return type.name
- the method nameparamTypes
- the parameter types.- Throws:
TCKValidationException
- if test fails.
-
assertValue
public static void assertValue(String section, Object value, String methodName, Object instance) throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetExceptionChecks the returned value, when calling a given method.- Parameters:
section
- the section of the spec under testvalue
- the expected valuemethodName
- the target method nameinstance
- the instance to call- Throws:
NoSuchMethodException
- if no method with the given name exists.SecurityException
- if a security problem occurs.IllegalAccessException
- if the method may not be called, e.g. due to security constraints.IllegalArgumentException
- if a wrong or inappropriate argument was provided.InvocationTargetException
- if an exception thrown by an invoked method or constructor.TCKValidationException
- if test fails.
-
testImmutableOpt
Test for immutability (optional recommendation), writes a warning if not given.- Parameters:
section
- the section of the spec under testtype
- the type to be checked.- Returns:
- true, if the instance is probably immutable.
-
testSerializableOpt
Test for serializable (optional recommendation), writes a warning if not given.- Parameters:
section
- the section of the spec under testtype
- the type to be checked.- Returns:
- true, if the type is probably serializable.
-
testSerializableOpt
Test for serializable (optional recommendation), writes a warning if not given.- Parameters:
section
- the section of the spec under testinstance
- the object to be checked.- Returns:
- true, if the instance is probably serializable.
-