java.lang.Object
tech.units.tck.util.TestUtils
Test utilities used in the JSR 385 TCK.
- Since:
- 1.0
- Version:
- 2.7, October 4, 2023
- Author:
- Werner Keil
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
Global message for missing TCK Configurationstatic final int
Number of binary prefixesstatic final int
Number of metric (SI) prefixesstatic final int
Number of built-in API prefix typesstatic final String
Name of the system property to override the default output directorystatic final String
Name of the system property to pass the desired profilestatic final String
Name of the system property to override the default report filestatic final String
Name of the system property to set theverbose
flag -
Method Summary
Modifier and TypeMethodDescriptionstatic 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 isComparable
.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) Deprecated.This was never used by the TCK, as immutability is highly recommended, but not enforced.static boolean
testImmutableOpt
(String section, Class type) Deprecated.This was never used by the TCK, as immutability is highly recommended, but not enforced.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 beingSerializable
.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:
-
SYS_PROPERTY_OUTPUT_DIR
Name of the system property to override the default output directory- See Also:
-
SYS_PROPERTY_REPORT_FILE
Name of the system property to override the default report file- See Also:
-
SYS_PROPERTY_VERBOSE
Name of the system property to set theverbose
flag- See Also:
-
NUM_OF_PREFIX_TYPES
Number of built-in API prefix types- See Also:
-
NUM_OF_BINARY_PREFIXES
Number of binary prefixes- See Also:
-
NUM_OF_METRIC_PREFIXES
Number of metric (SI) prefixes- See Also:
-
MSG_NO_TCK_CONFIG
Global message for missing TCK Configuration- See Also:
-
-
Method Details
-
testSerializable
Tests the given object beingSerializable
.- Parameters:
section
- the section of the spec under testtype
- the type to be checked.- Throws:
TCKValidationException
- if the 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.
-
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.
-
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 isComparable
.- Parameters:
section
- the section of the spec under testtype
- the type to be checked.- Throws:
TCKValidationException
- if the test fails.
-
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, InvocationTargetException Checks 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.
-
testImmutable
Deprecated.This was never used by the TCK, as immutability is highly recommended, but not enforced. MutabilityDetector is also incompatible with the Java Platform Module System and not actively developed in recent years.Tests the given class being immutable.- Parameters:
section
- the section of the spec under testtype
- the type to be checked.- Throws:
TCKValidationException
- if test fails.
-
testImmutableOpt
Deprecated.This was never used by the TCK, as immutability is highly recommended, but not enforced. MutabilityDetector is also incompatible with the Java Platform Module System and not actively developed in recent years.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.
-