Example usage for java.lang Class getAnnotationsByType

List of usage examples for java.lang Class getAnnotationsByType

Introduction

In this page you can find the example usage for java.lang Class getAnnotationsByType.

Prototype

@Override
public <A extends Annotation> A[] getAnnotationsByType(Class<A> annotationClass) 

Source Link

Usage

From source file:org.apache.tinkerpop.gremlin.AbstractGremlinSuite.java

private void registerOptOuts(final Class<? extends Graph> klass) throws InitializationError {
    final Graph.OptOut[] optOuts = klass.getAnnotationsByType(Graph.OptOut.class);

    if (optOuts != null && optOuts.length > 0) {
        // validate annotation - test class and reason must be set
        if (!Arrays.stream(optOuts).allMatch(
                ignore -> ignore.test() != null && ignore.reason() != null && !ignore.reason().isEmpty()))
            throw new InitializationError(
                    "Check @IgnoreTest annotations - all must have a 'test' and 'reason' set");

        try {/*from   w ww .j  av  a 2  s .  c om*/
            filter(new OptOutTestFilter(optOuts));
        } catch (NoTestsRemainException ex) {
            throw new InitializationError(ex);
        }
    }
}

From source file:org.apache.tinkerpop.gremlin.AbstractGremlinSuite.java

public static void validateOptInAndOutAnnotationsOnGraph(final Class<? extends Graph> klass)
        throws InitializationError {
    // sometimes test names change and since they are String representations they can easily break if a test
    // is renamed. this test will validate such things.  it is not possible to @OptOut of this test.
    final Graph.OptOut[] optOuts = klass.getAnnotationsByType(Graph.OptOut.class);
    for (Graph.OptOut optOut : optOuts) {
        final Class testClass;
        try {//from   w  w w  .  ja v  a  2 s  . c om
            testClass = Class.forName(optOut.test());
        } catch (Exception ex) {
            throw new InitializationError(String.format(
                    "Invalid @OptOut on Graph instance.  Could not instantiate test class (it may have been renamed): %s",
                    optOut.test()));
        }

        if (!optOut.method().equals("*")
                && !Arrays.stream(testClass.getMethods()).anyMatch(m -> m.getName().equals(optOut.method())))
            throw new InitializationError(String.format(
                    "Invalid @OptOut on Graph instance.  Could not match @OptOut test name %s on test class %s (it may have been renamed)",
                    optOut.method(), optOut.test()));
    }
}

From source file:org.failearly.dataset.internal.generator.GeneratorTestBase.java

/**
 * Returns the actually annotation (at index) from the {@code testFixtureClass}.
 *//*from  w w w. ja v  a 2s  . c  om*/
private GA resolveDeclaredAnnotations(Class<?> testFixtureClass, int index) {
    annotationInstance = testFixtureClass.getAnnotationsByType(generatorAnnotationClass)[index];
    return annotationInstance;
}

From source file:org.keycloak.testsuite.arquillian.AppServerTestEnricher.java

public static List<String> getAppServerQualifiers(Class testClass) {
    Class<?> annotatedClass = getNearestSuperclassWithAppServerAnnotation(testClass);

    if (annotatedClass == null)
        return null; // no @AppServerContainer annotation --> no adapter test

    AppServerContainer[] appServerContainers = annotatedClass.getAnnotationsByType(AppServerContainer.class);

    List<String> appServerQualifiers = new ArrayList<>();
    for (AppServerContainer appServerContainer : appServerContainers) {
        appServerQualifiers.add(appServerContainer.value());
    }//from www.j  a v a2s .c  om
    return appServerQualifiers;
}