All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.fluentlenium.utils.AnnotationUtil Maven / Gradle / Ivy

package org.fluentlenium.utils;

import org.fluentlenium.adapter.exception.AnnotationNotFoundException;
import org.fluentlenium.adapter.exception.MethodNotFoundException;

import java.lang.annotation.Annotation;

public final class AnnotationUtil {

    private AnnotationUtil() {
    }

    public static  T getClassAnnotationForClass(
            Class annotation, Class classFromThread) {
        T definedAnnotation = classFromThread.getAnnotation(annotation);

        if (definedAnnotation == null) {
            throw new AnnotationNotFoundException();
        }

        return definedAnnotation;
    }

    public static   T getMethodAnnotationForMethod(
            Class annotation, Class classFromThread, String methodNameFromThread) {
        T definedAnnotation;
        try {
            definedAnnotation = classFromThread.getDeclaredMethod(methodNameFromThread)
                    .getAnnotation(annotation);
        } catch (NoSuchMethodException e) {
            throw new MethodNotFoundException(e);
        }

        if (definedAnnotation == null) {
            throw new AnnotationNotFoundException();
        }

        return definedAnnotation;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy