Package h07.util

Class Assertions

    • Field Detail

      • UNBOUNDED

        public static final String[] UNBOUNDED
        Array with the type name of Object representing a unbounded type parameter
      • MODIFIER_METHODS

        private static final Map<Integer,​Object[]> MODIFIER_METHODS
        A map of modifier constants (Modifier) and Object, where the first element is the boolean method to check whether a class or member has that modifier and the second is the adjective to use in the error message of an exception, should one be thrown.
    • Constructor Detail

      • Assertions

        public Assertions()
    • Method Detail

      • assertHasModifiers

        public static void assertHasModifiers​(Member member,
                                              Integer... modifiers)
        Assert that the given member has the specified modifiers.

        Calls assertHasModifiers(Member, String, Integer...) with null as error message (default error message)
        Parameters:
        member - the member to check the modifiers of
        modifiers - a list of modifiers (constants of Modifier)
        Throws:
        IllegalArgumentException - if a value does not correspond to a modifier
      • assertHasModifiers

        public static void assertHasModifiers​(Member member,
                                              String errorMsg,
                                              Integer... modifiers)
        Assert that the given member has the specified modifiers.
        Parameters:
        member - the member to check the modifiers of
        modifiers - a list of modifiers (constants of Modifier)
        errorMsg - the error message to pass to AssertionError
        Throws:
        IllegalArgumentException - if a value does not correspond to a modifier
      • assertHasModifiers

        public static void assertHasModifiers​(Class<?> c,
                                              Integer... modifiers)
        Assert that the given class has the specified modifiers.

        Calls assertHasModifiers(Class, String, Integer...) with null as error message (default error message)
        Parameters:
        c - the member to check the modifiers of
        modifiers - a list of modifiers (constants of Modifier)
      • assertHasModifiers

        public static void assertHasModifiers​(Class<?> c,
                                              String errorMsg,
                                              Integer... modifiers)
        Assert that the given class has the specified modifiers.
        Parameters:
        c - the member to check the modifiers of
        errorMsg - the error message to pass to AssertionError
        modifiers - a list of modifiers (constants of Modifier)
      • assertDoesNotHaveModifiers

        public static void assertDoesNotHaveModifiers​(Member member,
                                                      String errorMsg,
                                                      Integer... modifiers)
        Assert that the given member does not have the specified modifiers.
        Parameters:
        member - the member to check the modifiers of
        modifiers - a list of modifiers (constants of Modifier)
        errorMsg - the error message to pass to AssertionError
        Throws:
        IllegalArgumentException - if a value does not correspond to a modifier
      • assertDoesNotHaveModifiers

        public static void assertDoesNotHaveModifiers​(Class<?> c,
                                                      Integer... modifiers)
        Assert that the given class does not have the specified modifiers.

        Calls assertDoesNotHaveModifiers(Class, String, Integer...) with null as error message (default error message)
        Parameters:
        c - the member to check the modifiers of
        modifiers - a list of modifiers (constants of Modifier)
      • assertDoesNotHaveModifiers

        public static void assertDoesNotHaveModifiers​(Class<?> c,
                                                      String errorMsg,
                                                      Integer... modifiers)
        Assert that the given class does not have the specified modifiers.
        Parameters:
        c - the member to check the modifiers of
        errorMsg - the error message to pass to AssertionError
        modifiers - a list of modifiers (constants of Modifier)
      • assertIsGeneric

        public static void assertIsGeneric​(Class<?> c,
                                           Assertions.TypeParameter... expectedTypeParameters)
        Assert that the given class is generic and its type parameters have the given bounds
        Parameters:
        c - the class to check
        expectedTypeParameters - an array of expected type parameters and their bounds
      • assertNotGeneric

        public static void assertNotGeneric​(Class<?> c)
        Assert that the given class is not generic
        Parameters:
        c - the class to check
      • assertType

        public static void assertType​(Field field,
                                      String typeName)
        Assert that the given field has the type typeName
        Parameters:
        field - the field to check
        typeName - the type (type name)
      • assertReturnType

        public static void assertReturnType​(Method method,
                                            String typeName)
        Assert that the given method has the return type typeName
        Parameters:
        method - the method to check
        typeName - the return type (type name)
      • assertImplements

        public static void assertImplements​(Class<?> c,
                                            String... interfaces)
        Assert that a class implements all given interfaces
        Parameters:
        c - the class to check
        interfaces - the interfaces the class has to implement (type name)
      • arrayContains

        private static boolean arrayContains​(Object needle,
                                             Object[] stack)
        Checks whether an array of objects contains a given object.
        Parameters:
        needle - the object to search for
        stack - the array to search in
        Returns:
        true, if the object was found in the array, false otherwise