package com.atlassian.bitbucket.test.filters;

import org.junit.runner.Description;
import org.junit.runner.manipulation.Filter;
import org.junit.runners.model.TestClass;

import java.lang.annotation.Annotation;

public abstract class AnnotationBasedFilter extends Filter {

    private final TestClass testClass;

    public AnnotationBasedFilter(TestClass testClass) {
        this.testClass = testClass;
    }

    protected <T extends Annotation> T getAnnotation(Class<T> clazz, Description description) {
        T annotation = description.getAnnotation(clazz);
        return annotation == null ? testClass.getJavaClass().getAnnotation(clazz) : annotation;
    }

}
