Class Predicates


  • public class Predicates
    extends Object
    Common predicates for architecture tests.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static com.tngtech.archunit.base.DescribedPredicate<com.tngtech.archunit.core.domain.JavaClass> areDirectlyAnnotatedWithAtLeastOneOf​(Class<? extends Annotation>... annotations)  
      static com.tngtech.archunit.base.DescribedPredicate<com.tngtech.archunit.core.domain.JavaField> areFieldOfType​(Class<?> clazz, com.tngtech.archunit.core.domain.JavaModifier... modifiers)
      Tests that the given field is of the given type clazz and has given modifiers.
      static com.tngtech.archunit.base.DescribedPredicate<com.tngtech.archunit.core.domain.JavaField> arePublicFinalOfType​(Class<?> clazz)
      Tests that the given field is public final and not static and of the given type clazz .
      static com.tngtech.archunit.base.DescribedPredicate<com.tngtech.archunit.core.domain.JavaField> arePublicFinalOfTypeWithAnnotation​(Class<?> clazz, Class<? extends Annotation> annotationType)
      Tests that the given field is public final and of the given type clazz with exactly the given annotationType.
      static com.tngtech.archunit.base.DescribedPredicate<com.tngtech.archunit.core.domain.JavaField> arePublicStaticFinalAssignableTo​(Class<?> clazz)
      Tests that the given field is public static final and is assignable to the given type clazz .
      static com.tngtech.archunit.base.DescribedPredicate<com.tngtech.archunit.core.domain.JavaField> arePublicStaticFinalOfType​(Class<?> clazz)
      Tests that the given field is public static final and of the given type clazz .
      static com.tngtech.archunit.base.DescribedPredicate<com.tngtech.archunit.core.domain.JavaField> arePublicStaticFinalOfTypeWithAnnotation​(Class<?> clazz, Class<? extends Annotation> annotationType)
      Tests that the given field is public static final and of the given type clazz with exactly the given annotationType.
      static com.tngtech.archunit.base.DescribedPredicate<com.tngtech.archunit.core.domain.JavaField> arePublicStaticOfType​(Class<?> clazz)
      Tests that the given field is public static and of the given type clazz .
      static com.tngtech.archunit.base.DescribedPredicate<com.tngtech.archunit.core.domain.JavaField> areStaticFinalOfTypeWithAnnotation​(Class<?> clazz, Class<? extends Annotation> annotationType)
      Tests that the given field is static final and of the given type clazz with exactly the given annotationType.
      static com.tngtech.archunit.base.DescribedPredicate<com.tngtech.archunit.core.domain.JavaClass> containAnyFieldsInClassHierarchyThat​(com.tngtech.archunit.base.DescribedPredicate<? super com.tngtech.archunit.core.domain.JavaField> predicate)  
      static <T> com.tngtech.archunit.base.DescribedPredicate<T> exactlyOneOf​(com.tngtech.archunit.base.DescribedPredicate<? super T>... other)
      Returns a DescribedPredicate that returns true if one and only one of the given predicates match.
    • Method Detail

      • areDirectlyAnnotatedWithAtLeastOneOf

        @SafeVarargs
        public static com.tngtech.archunit.base.DescribedPredicate<com.tngtech.archunit.core.domain.JavaClass> areDirectlyAnnotatedWithAtLeastOneOf​(Class<? extends Annotation>... annotations)
      • containAnyFieldsInClassHierarchyThat

        public static com.tngtech.archunit.base.DescribedPredicate<com.tngtech.archunit.core.domain.JavaClass> containAnyFieldsInClassHierarchyThat​(com.tngtech.archunit.base.DescribedPredicate<? super com.tngtech.archunit.core.domain.JavaField> predicate)
        Returns:
        A DescribedPredicate returning true, if and only if the predicate JavaField could be found in the JavaClass.
      • arePublicStaticOfType

        public static com.tngtech.archunit.base.DescribedPredicate<com.tngtech.archunit.core.domain.JavaField> arePublicStaticOfType​(Class<?> clazz)
        Tests that the given field is public static and of the given type clazz .

        Attention: changing the description will add a rule into the stored.rules.

      • areFieldOfType

        public static com.tngtech.archunit.base.DescribedPredicate<com.tngtech.archunit.core.domain.JavaField> areFieldOfType​(Class<?> clazz,
                                                                                                                              com.tngtech.archunit.core.domain.JavaModifier... modifiers)
        Tests that the given field is of the given type clazz and has given modifiers.

        Attention: changing the description will add a rule into the stored.rules.

      • arePublicFinalOfType

        public static com.tngtech.archunit.base.DescribedPredicate<com.tngtech.archunit.core.domain.JavaField> arePublicFinalOfType​(Class<?> clazz)
        Tests that the given field is public final and not static and of the given type clazz .
      • arePublicStaticFinalAssignableTo

        public static com.tngtech.archunit.base.DescribedPredicate<com.tngtech.archunit.core.domain.JavaField> arePublicStaticFinalAssignableTo​(Class<?> clazz)
        Tests that the given field is public static final and is assignable to the given type clazz .
      • arePublicStaticFinalOfType

        public static com.tngtech.archunit.base.DescribedPredicate<com.tngtech.archunit.core.domain.JavaField> arePublicStaticFinalOfType​(Class<?> clazz)
        Tests that the given field is public static final and of the given type clazz .
      • arePublicFinalOfTypeWithAnnotation

        public static com.tngtech.archunit.base.DescribedPredicate<com.tngtech.archunit.core.domain.JavaField> arePublicFinalOfTypeWithAnnotation​(Class<?> clazz,
                                                                                                                                                  Class<? extends Annotation> annotationType)
        Tests that the given field is public final and of the given type clazz with exactly the given annotationType.
      • arePublicStaticFinalOfTypeWithAnnotation

        public static com.tngtech.archunit.base.DescribedPredicate<com.tngtech.archunit.core.domain.JavaField> arePublicStaticFinalOfTypeWithAnnotation​(Class<?> clazz,
                                                                                                                                                        Class<? extends Annotation> annotationType)
        Tests that the given field is public static final and of the given type clazz with exactly the given annotationType.
      • areStaticFinalOfTypeWithAnnotation

        public static com.tngtech.archunit.base.DescribedPredicate<com.tngtech.archunit.core.domain.JavaField> areStaticFinalOfTypeWithAnnotation​(Class<?> clazz,
                                                                                                                                                  Class<? extends Annotation> annotationType)
        Tests that the given field is static final and of the given type clazz with exactly the given annotationType. It doesn't matter if public, private or protected.
      • exactlyOneOf

        @SafeVarargs
        public static <T> com.tngtech.archunit.base.DescribedPredicate<T> exactlyOneOf​(com.tngtech.archunit.base.DescribedPredicate<? super T>... other)
        Returns a DescribedPredicate that returns true if one and only one of the given predicates match.