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.7, October 4, 2023
Author:
Werner Keil
  • Field Details

  • Method Details

    • testSerializable

      public static void testSerializable(String section, Class<?> type)
      Tests the given object being Serializable.
      Parameters:
      section - the section of the spec under test
      type - the type to be checked.
      Throws:
      TCKValidationException - if the test fails.
    • testSerializable

      public static void testSerializable(String section, Object o)
      Tests the given object being (effectively) serializable by serializing it.
      Parameters:
      section - the section of the spec under test
      o - the object to be checked.
      Throws:
      TCKValidationException - if test fails.
    • testSerializableOpt

      public static boolean testSerializableOpt(String section, Class type)
      Test for serializable (optional recommendation), writes a warning if not given.
      Parameters:
      section - the section of the spec under test
      type - the type to be checked.
      Returns:
      true, if the type is probably serializable.
    • testSerializableOpt

      public static boolean testSerializableOpt(String section, Object instance)
      Test for serializable (optional recommendation), writes a warning if not given.
      Parameters:
      section - the section of the spec under test
      instance - the object to be checked.
      Returns:
      true, if the instance is probably serializable.
    • testImplementsInterface

      public static void testImplementsInterface(String section, Class<?> type, Class<?> iface)
      Tests the given class implements a given interface.
      Parameters:
      section - the section of the spec under test
      type - the type to be checked.
      iface - the interface to be checked for. Triggers Assert#fail if test fails.
    • testComparable

      public static void testComparable(String section, Class<?> type)
      Tests if the given type is Comparable.
      Parameters:
      section - the section of the spec under test
      type - 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 specification
      type - the type to be checked.
      returnType - the expected return type
      name - the name of the method
      paramTypes - 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 specification
      type - the data type
      trySuperclassFirst - if tht super class if available should be tested first
      returnType - the expected return type
      name - the name of the method
      paramTypes - 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 test
      type - the type to be checked.
      name - the method name
      hasParameters - the method has parameters.
      Throws:
      TCKValidationException - if test fails.
    • testHasPublicMethod

      public static void testHasPublicMethod(String section, Class<?> type, String name)
      Parameters:
      section - the section of the specification
      type - the data type
      name - 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 test
      type - the type to be checked.
      returnType - the method return type.
      name - the method name
      paramTypes - the parameter types.
      Throws:
      TCKValidationException - if test fails.
    • assertValue

      Checks the returned value, when calling a given method.
      Parameters:
      section - the section of the spec under test
      value - the expected value
      methodName - the target method name
      instance - 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

      public static void testImmutable(String section, Class<?> type)
      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 test
      type - the type to be checked.
      Throws:
      TCKValidationException - if test fails.
    • testImmutableOpt

      public static boolean testImmutableOpt(String section, Class type)
      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 test
      type - the type to be checked.
      Returns:
      true, if the instance is probably immutable.