Class 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
    • Method Detail

      • testSerializable

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

        public static void testImmutable​(String section,
                                         Class<?> type)
        Tests the given class being serializable.
        Parameters:
        section - the section of the spec under test
        type - the type to be checked.
        Throws:
        TCKValidationException - if 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.
      • 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.
      • 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.
      • testImmutableOpt

        public static boolean testImmutableOpt​(String section,
                                               Class type)
        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.
      • 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.