Search in sources :

Example 1 with AnnotatedElementDeclaration

use of org.freud.analysed.javasource.AnnotatedElementDeclaration in project freud by LMAX-Exchange.

the class AnnotatedElementDeclarationMatchers method hasDeclaredAnnotation.

public FreudExtendedMatcher<T> hasDeclaredAnnotation(final String annotationName, final Matcher<String> defaultValueMatcher) {
    return new FreudExtendedMatcher<T>() {

        @Override
        protected boolean matchesSafely(final AnnotatedElementDeclaration toBeAnalysed) {
            for (Annotation declaredAnnotation : toBeAnalysed.getDeclaredAnnotations()) {
                if (annotationName.equals(declaredAnnotation.getName())) {
                    return defaultValueMatcher.matches(declaredAnnotation.getDefaultParameter());
                }
            }
            return false;
        }

        @Override
        public String toString() {
            Description description = new StringDescription();
            description.appendText("HasDeclaredAnnotation(").appendText(annotationName);
            defaultValueMatcher.describeTo(description);
            description.appendText(")");
            return description.toString();
        }

        @Override
        public void describeTo(Description description) {
            description.appendText(toString());
        }
    };
}
Also used : Description(org.hamcrest.Description) StringDescription(org.hamcrest.StringDescription) AnnotatedElementDeclaration(org.freud.analysed.javasource.AnnotatedElementDeclaration) StringDescription(org.hamcrest.StringDescription) FreudExtendedMatcher(org.freud.java.matcher.FreudExtendedMatcher) Annotation(org.freud.analysed.javasource.Annotation)

Aggregations

AnnotatedElementDeclaration (org.freud.analysed.javasource.AnnotatedElementDeclaration)1 Annotation (org.freud.analysed.javasource.Annotation)1 FreudExtendedMatcher (org.freud.java.matcher.FreudExtendedMatcher)1 Description (org.hamcrest.Description)1 StringDescription (org.hamcrest.StringDescription)1