X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=common%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fso%2Fopenpojo%2Frules%2FHasAnnotationPropertyWithValueMatcher.java;h=8a47299c737f717286babdc0a2078dfdd75ca164;hb=f47919f1fe367b612fa9c96d34c59f01a541e882;hp=f76a27cce2d66223c45796aaf943b6676a585e58;hpb=54452b80a1cf4d22ef750bc1377f8c1b05431d57;p=so.git diff --git a/common/src/main/java/org/onap/so/openpojo/rules/HasAnnotationPropertyWithValueMatcher.java b/common/src/main/java/org/onap/so/openpojo/rules/HasAnnotationPropertyWithValueMatcher.java index f76a27cce2..8a47299c73 100644 --- a/common/src/main/java/org/onap/so/openpojo/rules/HasAnnotationPropertyWithValueMatcher.java +++ b/common/src/main/java/org/onap/so/openpojo/rules/HasAnnotationPropertyWithValueMatcher.java @@ -25,56 +25,59 @@ package org.onap.so.openpojo.rules; import java.lang.annotation.Annotation; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; - import org.hamcrest.Description; import org.hamcrest.Matcher; import org.hamcrest.TypeSafeDiagnosingMatcher; - import com.openpojo.reflection.PojoField; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class HasAnnotationPropertyWithValueMatcher extends TypeSafeDiagnosingMatcher { - private Logger logger = LoggerFactory.getLogger(HasAnnotationPropertyWithValueMatcher.class); - private final String attribute; - private final Matcher annotationMatcher; - private final Class annotationClass; - public HasAnnotationPropertyWithValueMatcher(Class clazz, String attribute, final Matcher annotationMatcher) { - this.attribute = attribute; - this.annotationMatcher = annotationMatcher; - this.annotationClass = clazz; - } + private Logger logger = LoggerFactory.getLogger(HasAnnotationPropertyWithValueMatcher.class); + private final String attribute; + private final Matcher annotationMatcher; + private final Class annotationClass; + + public HasAnnotationPropertyWithValueMatcher(Class clazz, String attribute, + final Matcher annotationMatcher) { + this.attribute = attribute; + this.annotationMatcher = annotationMatcher; + this.annotationClass = clazz; + } - @Override - protected boolean matchesSafely(T obj, final Description mismatchDescription) { - final PojoField temp = (PojoField)obj; - final Method method; - try { - Annotation a = temp.getAnnotation(this.annotationClass); - if (a == null) { - mismatchDescription.appendText("does not have annotation ").appendText(this.annotationClass.getSimpleName()); - return false; - } - method = a.getClass().getMethod(attribute); - final Object result = method.invoke(a); - if (!this.annotationMatcher.matches(result)) { - this.annotationMatcher.describeMismatch(result, mismatchDescription); - return false; - } - } catch (NoSuchMethodException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { - mismatchDescription.appendText("does not have property ").appendText(attribute); - logger.debug("Error occured", e); - return false; - } - return true; - } + @Override + protected boolean matchesSafely(T obj, final Description mismatchDescription) { + final PojoField temp = (PojoField) obj; + final Method method; + try { + Annotation a = temp.getAnnotation(this.annotationClass); + if (a == null) { + mismatchDescription.appendText("does not have annotation ") + .appendText(this.annotationClass.getSimpleName()); + return false; + } + method = a.getClass().getMethod(attribute); + final Object result = method.invoke(a); + if (!this.annotationMatcher.matches(result)) { + this.annotationMatcher.describeMismatch(result, mismatchDescription); + return false; + } + } catch (NoSuchMethodException | IllegalAccessException | IllegalArgumentException + | InvocationTargetException e) { + mismatchDescription.appendText("does not have property ").appendText(attribute); + logger.debug("Error occured", e); + return false; + } + return true; + } - @Override - public void describeTo(final Description description) { - // Intentionally left blank. - } + @Override + public void describeTo(final Description description) { + // Intentionally left blank. + } - public static Matcher hasAnnotationPropertyWithValue(Class clazz, String attribute, final Matcher annotationMatcher) { - return new HasAnnotationPropertyWithValueMatcher(clazz, attribute, annotationMatcher); - } + public static Matcher hasAnnotationPropertyWithValue(Class clazz, + String attribute, final Matcher annotationMatcher) { + return new HasAnnotationPropertyWithValueMatcher(clazz, attribute, annotationMatcher); + } }