io.nuun.kernel.api.assertions
Class AssertUtils

java.lang.Object
  extended by io.nuun.kernel.api.assertions.AssertUtils

public class AssertUtils
extends Object

Provides assertions commonly used by Nuun plugins.


Nested Class Summary
static class AssertUtils.AnnotationCopy
           
 
Constructor Summary
AssertUtils()
           
 
Method Summary
static
<A extends Annotation>
A
annotationProxyOf(Class<A> annotationModelType, Annotation annotationClone)
           
static void assertInterface(Class<? extends Object> candidate)
          Asserts that the given class is an interface.
static void assertionIllegalArgument(boolean asserted, String message)
          Asserts that the given parameter is true, otherwise throws an IllegalArgumentException.
static void assertionNullPointer(boolean asserted, String message)
          Asserts that the given parameter is true, otherwise throws an NullPointerException.
static void assertIsClass(Class<? extends Object> candidate)
          Asserts that the class is not an interface.
static void assertLegal(Object underAssertion, String message)
          Asserts that the given parameter is not null, otherwise throws an IllegalArgumentException.
static void assertNotNull(Object underAssertion, String message)
          Asserts that the given parameter is not null, otherwise throws an NullPointerException.
static boolean hasAnnotationDeep(Class<?> memberDeclaringClass, Class<? extends Annotation> candidate)
          Indicates if a class or at least one of its annotations is annotated by a given annotation.
static boolean hasAnnotationDeepRegex(Class<?> memberDeclaringClass, String metaAnnotationRegex)
          Indicates if the class name or at least the name of one of its annotations matches the regex.
static boolean isClass(Class<? extends Object> candidate)
          Indicates if the class is not an interface.
static boolean isEquivalent(Class<? extends Annotation> original, Class<? extends Annotation> copy)
           
static boolean isInterface(Class<? extends Object> candidate)
          Indicates if the given class is an interface.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AssertUtils

public AssertUtils()
Method Detail

isInterface

public static boolean isInterface(Class<? extends Object> candidate)
Indicates if the given class is an interface.

Parameters:
candidate - the class to check
Returns:
true if the class is an interface, false otherwise

assertInterface

public static void assertInterface(Class<? extends Object> candidate)
Asserts that the given class is an interface.

Parameters:
candidate - the class to check
Throws:
IllegalArgumentException - if the assertion is not satisfied

isClass

public static boolean isClass(Class<? extends Object> candidate)
Indicates if the class is not an interface.

Parameters:
candidate - the class to check
Returns:
true if class is not an interface, false otherwise

assertIsClass

public static void assertIsClass(Class<? extends Object> candidate)
Asserts that the class is not an interface.

Parameters:
candidate - the class to check
Throws:
IllegalArgumentException - if the assertion is not satisfied

hasAnnotationDeep

public static boolean hasAnnotationDeep(Class<?> memberDeclaringClass,
                                        Class<? extends Annotation> candidate)
Indicates if a class or at least one of its annotations is annotated by a given annotation.

Notice that the classes with a package name starting with "java.lang" will be ignored.

Parameters:
memberDeclaringClass - the class to check
candidate - the annotation to find
Returns:
true if the annotation is found, false otherwise

hasAnnotationDeepRegex

public static boolean hasAnnotationDeepRegex(Class<?> memberDeclaringClass,
                                             String metaAnnotationRegex)
Indicates if the class name or at least the name of one of its annotations matches the regex.

Notice that the classes with a package name starting with "java.lang" will be ignored.

Parameters:
memberDeclaringClass - the class to check
metaAnnotationRegex - the regex to match
Returns:
true if the regex matches, false otherwise

isEquivalent

public static boolean isEquivalent(Class<? extends Annotation> original,
                                   Class<? extends Annotation> copy)

annotationProxyOf

public static <A extends Annotation> A annotationProxyOf(Class<A> annotationModelType,
                                                         Annotation annotationClone)

assertionIllegalArgument

public static void assertionIllegalArgument(boolean asserted,
                                            String message)
Asserts that the given parameter is true, otherwise throws an IllegalArgumentException.

Parameters:
asserted - the assertion result
message - the error message
Throws:
IllegalArgumentException - if asserted is false

assertionNullPointer

public static void assertionNullPointer(boolean asserted,
                                        String message)
Asserts that the given parameter is true, otherwise throws an NullPointerException.

Parameters:
asserted - the assertion result
message - the error message
Throws:
NullPointerException - if asserted is false

assertLegal

public static void assertLegal(Object underAssertion,
                               String message)
Asserts that the given parameter is not null, otherwise throws an IllegalArgumentException.

Parameters:
underAssertion - the object to check
message - the error message
Throws:
IllegalArgumentException - if asserted is null

assertNotNull

public static void assertNotNull(Object underAssertion,
                                 String message)
Asserts that the given parameter is not null, otherwise throws an NullPointerException.

Parameters:
underAssertion - the object to check
message - the error message
Throws:
NullPointerException - if asserted is null


Copyright © 2012-2015. All Rights Reserved.