From 27ddc8e834917c86458f4308739d832e97139335 Mon Sep 17 00:00:00 2001 From: Chris Cranford Date: Tue, 15 Jan 2019 17:27:03 -0500 Subject: [PATCH] HHH-13206 - Fix custom runner properly determine dialect feature checks. --- .../testing/junit4/CustomRunner.java | 27 +++++++++------- .../org/hibernate/testing/junit4/Helper.java | 32 +++++++++++++++++++ 2 files changed, 47 insertions(+), 12 deletions(-) diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/junit4/CustomRunner.java b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/CustomRunner.java index 1e30e0643a..822f8c378b 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/junit4/CustomRunner.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/CustomRunner.java @@ -272,24 +272,27 @@ public class CustomRunner extends BlockJUnit4ClassRunner { } // @RequiresDialectFeature - RequiresDialectFeature requiresDialectFeatureAnn = Helper.locateAnnotation( + final List requiresDialectFeatures = Helper.locateAllAnnotations( RequiresDialectFeature.class, frameworkMethod, getTestClass() ); - if ( requiresDialectFeatureAnn != null ) { - try { - for ( Class checkClass : requiresDialectFeatureAnn.value() ) { - if ( !checkClass.newInstance().isMatch( dialect ) ) { - return buildIgnore( requiresDialectFeatureAnn ); + + if ( !requiresDialectFeatures.isEmpty() ) { + for ( RequiresDialectFeature requiresDialectFeature : requiresDialectFeatures ) { + try { + for ( Class checkClass : requiresDialectFeature.value() ) { + if ( !checkClass.newInstance().isMatch( dialect ) ) { + return buildIgnore( requiresDialectFeature ); + } } } - } - catch (RuntimeException e) { - throw e; - } - catch (Exception e) { - throw new RuntimeException( "Unable to instantiate DialectCheck", e ); + catch (RuntimeException e) { + throw e; + } + catch (Exception e) { + throw new RuntimeException( "Unable to instantiate DialectCheck", e ); + } } } diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/junit4/Helper.java b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/Helper.java index 391d12c8ba..0a80227cbd 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/junit4/Helper.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/Helper.java @@ -75,6 +75,38 @@ public final class Helper { return annotation; } + /** + * Locates the specified annotation both at the method site and class site. + * + * This is useful for situations where you may apply the same annotation at both the method + * and class level and rather than both sites being mutually exclusive, this permits both + * to be returned instead. + * + * @param annotationClass Annotation class + * @param frameworkMethod Test method. + * @param testClass Test class. + * @param Annotation type. + * + * @return Collection of all annotations detected at both method or class level. + */ + public static List locateAllAnnotations( + Class annotationClass, + FrameworkMethod frameworkMethod, + TestClass testClass) { + final List annotations = new LinkedList<>(); + + T annotation = frameworkMethod.getAnnotation( annotationClass ); + if ( annotation != null ) { + annotations.add( annotation ); + } + + annotation = testClass.getJavaClass().getAnnotation( annotationClass ); + if ( annotation != null ) { + annotations.add( annotation ); + } + return annotations; + } + /** * @param singularAnnotationClass Singular annotation class (e.g. {@link org.hibernate.testing.SkipForDialect}). * @param pluralAnnotationClass Plural annotation class (e.g. {@link org.hibernate.testing.SkipForDialects}),