/** * Determine if the supplied {@code testMethod} is <em>enabled</em> in * the current environment, as specified by the {@link IfProfileValue * @IfProfileValue} annotation, which may be declared on the test * method itself or at the class level. Class-level usage overrides * method-level usage. * <p>Defaults to {@code true} if no {@link IfProfileValue * @IfProfileValue} annotation is declared. * @param profileValueSource the ProfileValueSource to use to determine if * the test is enabled * @param testMethod the test method * @param testClass the test class * @return {@code true} if the test is <em>enabled</em> in the current * environment */ public static boolean isTestEnabledInThisEnvironment(ProfileValueSource profileValueSource, Method testMethod, Class<?> testClass) { IfProfileValue ifProfileValue = AnnotatedElementUtils.findMergedAnnotation(testClass, IfProfileValue.class); boolean classLevelEnabled = isTestEnabledInThisEnvironment(profileValueSource, ifProfileValue); if (classLevelEnabled) { ifProfileValue = AnnotatedElementUtils.findMergedAnnotation(testMethod, IfProfileValue.class); return isTestEnabledInThisEnvironment(profileValueSource, ifProfileValue); } return false; }
/** * Determine if the supplied {@code testMethod} is <em>enabled</em> in * the current environment, as specified by the {@link IfProfileValue * @IfProfileValue} annotation, which may be declared on the test * method itself or at the class level. Class-level usage overrides * method-level usage. * <p>Defaults to {@code true} if no {@link IfProfileValue * @IfProfileValue} annotation is declared. * @param testMethod the test method * @param testClass the test class * @return {@code true} if the test is <em>enabled</em> in the current * environment */ public static boolean isTestEnabledInThisEnvironment(Method testMethod, Class<?> testClass) { return isTestEnabledInThisEnvironment(retrieveProfileValueSource(testClass), testMethod, testClass); }
public static boolean isTestEnabledInThisEnvironment(Class<?> testClass) { IfProfileActive ifProfileActive = AnnotationUtils.findAnnotation(testClass, IfProfileActive.class); UnlessProfileActive unlessProfileActive = AnnotationUtils.findAnnotation(testClass, UnlessProfileActive.class); return isTestEnabledInThisEnvironment(ProfileValueUtils.retrieveProfileValueSource(testClass), ifProfileActive, unlessProfileActive); }
/** * Return {@code true} if {@link Ignore @Ignore} is present for the supplied * {@linkplain FrameworkMethod test method} or if the test method is disabled * via {@code @IfProfileValue}. * @see ProfileValueUtils#isTestEnabledInThisEnvironment(Method, Class) */ protected boolean isTestMethodIgnored(FrameworkMethod frameworkMethod) { Method method = frameworkMethod.getMethod(); return (method.isAnnotationPresent(Ignore.class) || !ProfileValueUtils.isTestEnabledInThisEnvironment(method, getTestClass().getJavaClass())); }
/** * Determine if the supplied {@code testClass} is <em>enabled</em> in * the current environment, as specified by the {@link IfProfileValue * @IfProfileValue} annotation at the class level. * <p>Defaults to {@code true} if no {@link IfProfileValue * @IfProfileValue} annotation is declared. * @param testClass the test class * @return {@code true} if the test is <em>enabled</em> in the current * environment */ public static boolean isTestEnabledInThisEnvironment(Class<?> testClass) { IfProfileValue ifProfileValue = AnnotatedElementUtils.findMergedAnnotation(testClass, IfProfileValue.class); return isTestEnabledInThisEnvironment(retrieveProfileValueSource(testClass), ifProfileValue); }
public void evaluate() throws Throwable { if (this.testMethod == null) { if (!ProfileValueUtils.isTestEnabledInThisEnvironment(this.testClass)) { Annotation ann = AnnotatedElementUtils.findMergedAnnotation(this.testClass, IfProfileValue.class); throw new AssumptionViolatedException(String.format( if (!ProfileValueUtils.isTestEnabledInThisEnvironment(this.testMethod, this.testClass)) { throw new AssumptionViolatedException(String.format( "Profile configured via @IfProfileValue is not enabled in this environment for test method [%s].",
/** * Determine if the supplied {@code testMethod} is <em>enabled</em> in * the current environment, as specified by the {@link IfProfileValue * @IfProfileValue} annotation, which may be declared on the test * method itself or at the class level. Class-level usage overrides * method-level usage. * <p>Defaults to {@code true} if no {@link IfProfileValue * @IfProfileValue} annotation is declared. * @param testMethod the test method * @param testClass the test class * @return {@code true} if the test is <em>enabled</em> in the current * environment */ public static boolean isTestEnabledInThisEnvironment(Method testMethod, Class<?> testClass) { return isTestEnabledInThisEnvironment(retrieveProfileValueSource(testClass), testMethod, testClass); }
private void assertMethodIsEnabled(String methodName, Class<?> testClass) throws Exception { Method testMethod = testClass.getMethod(methodName); assertTrue("Test method [" + testMethod + "] should be enabled.", ProfileValueUtils.isTestEnabledInThisEnvironment(testMethod, testClass)); }
/** * Determine if the supplied {@code testMethod} is <em>enabled</em> in * the current environment, as specified by the {@link IfProfileValue * @IfProfileValue} annotation, which may be declared on the test * method itself or at the class level. Class-level usage overrides * method-level usage. * <p>Defaults to {@code true} if no {@link IfProfileValue * @IfProfileValue} annotation is declared. * @param testMethod the test method * @param testClass the test class * @return {@code true} if the test is <em>enabled</em> in the current * environment */ public static boolean isTestEnabledInThisEnvironment(Method testMethod, Class<?> testClass) { return isTestEnabledInThisEnvironment(retrieveProfileValueSource(testClass), testMethod, testClass); }
private void assertMethodIsEnabled(ProfileValueSource profileValueSource, String methodName, Class<?> testClass) throws Exception { Method testMethod = testClass.getMethod(methodName); assertTrue("Test method [" + testMethod + "] should be enabled for ProfileValueSource [" + profileValueSource + "].", ProfileValueUtils.isTestEnabledInThisEnvironment(profileValueSource, testMethod, testClass)); }
/** * Determine if the supplied {@code testClass} is <em>enabled</em> in * the current environment, as specified by the {@link IfProfileValue * @IfProfileValue} annotation at the class level. * <p>Defaults to {@code true} if no {@link IfProfileValue * @IfProfileValue} annotation is declared. * @param testClass the test class * @return {@code true} if the test is <em>enabled</em> in the current * environment */ public static boolean isTestEnabledInThisEnvironment(Class<?> testClass) { IfProfileValue ifProfileValue = AnnotatedElementUtils.findMergedAnnotation(testClass, IfProfileValue.class); return isTestEnabledInThisEnvironment(retrieveProfileValueSource(testClass), ifProfileValue); }
private void assertMethodIsDisabled(String methodName, Class<?> testClass) throws Exception { Method testMethod = testClass.getMethod(methodName); assertFalse("Test method [" + testMethod + "] should be disabled.", ProfileValueUtils.isTestEnabledInThisEnvironment(testMethod, testClass)); }
/** * Determine if the supplied {@code testClass} is <em>enabled</em> in * the current environment, as specified by the {@link IfProfileValue * @IfProfileValue} annotation at the class level. * <p>Defaults to {@code true} if no {@link IfProfileValue * @IfProfileValue} annotation is declared. * @param testClass the test class * @return {@code true} if the test is <em>enabled</em> in the current * environment */ public static boolean isTestEnabledInThisEnvironment(Class<?> testClass) { IfProfileValue ifProfileValue = AnnotatedElementUtils.findMergedAnnotation(testClass, IfProfileValue.class); return isTestEnabledInThisEnvironment(retrieveProfileValueSource(testClass), ifProfileValue); }
private void assertMethodIsDisabled(ProfileValueSource profileValueSource, String methodName, Class<?> testClass) throws Exception { Method testMethod = testClass.getMethod(methodName); assertFalse("Test method [" + testMethod + "] should be disabled for ProfileValueSource [" + profileValueSource + "].", ProfileValueUtils.isTestEnabledInThisEnvironment(profileValueSource, testMethod, testClass)); }
private void assertClassIsDisabled(Class<?> testClass) throws Exception { assertFalse("Test class [" + testClass + "] should be disabled.", ProfileValueUtils.isTestEnabledInThisEnvironment(testClass)); }
private void assertClassIsEnabled(Class<?> testClass) throws Exception { assertTrue("Test class [" + testClass + "] should be enabled.", ProfileValueUtils.isTestEnabledInThisEnvironment(testClass)); }
/** * Check whether the test is enabled in the current execution environment. * <p>This prevents classes with a non-matching {@code @IfProfileValue} * annotation from running altogether, even skipping the execution of * {@code prepareTestInstance()} methods in {@code TestExecutionListeners}. * @see ProfileValueUtils#isTestEnabledInThisEnvironment(Class) * @see org.springframework.test.annotation.IfProfileValue * @see org.springframework.test.context.TestExecutionListener */ @Override public void run(RunNotifier notifier) { if (!ProfileValueUtils.isTestEnabledInThisEnvironment(getTestClass().getJavaClass())) { notifier.fireTestIgnored(getDescription()); return; } super.run(notifier); }
private boolean handleProfileValues(SpecInfo spec) { if (!ProfileValueUtils.isTestEnabledInThisEnvironment(spec.getReflection())) { spec.setExcluded(true); return false; } for (FeatureInfo feature : spec.getAllFeatures()) if (!ProfileValueUtils.isTestEnabledInThisEnvironment( feature.getFeatureMethod().getReflection(), spec.getReflection())) feature.setExcluded(true); return true; } }
/** * Return a description suitable for an ignored test class if the test is * disabled via {@code @IfProfileValue} at the class-level, and * otherwise delegate to the parent implementation. * @see ProfileValueUtils#isTestEnabledInThisEnvironment(Class) */ @Override public Description getDescription() { if (!ProfileValueUtils.isTestEnabledInThisEnvironment(getTestClass().getJavaClass())) { return Description.createSuiteDescription(getTestClass().getJavaClass()); } return super.getDescription(); }
/** * Determine if the supplied {@code testMethod} is <em>enabled</em> in * the current environment, as specified by the {@link IfProfileValue * @IfProfileValue} annotation, which may be declared on the test * method itself or at the class level. Class-level usage overrides * method-level usage. * <p>Defaults to {@code true} if no {@link IfProfileValue * @IfProfileValue} annotation is declared. * @param profileValueSource the ProfileValueSource to use to determine if * the test is enabled * @param testMethod the test method * @param testClass the test class * @return {@code true} if the test is <em>enabled</em> in the current * environment */ public static boolean isTestEnabledInThisEnvironment(ProfileValueSource profileValueSource, Method testMethod, Class<?> testClass) { IfProfileValue ifProfileValue = AnnotatedElementUtils.findMergedAnnotation(testClass, IfProfileValue.class); boolean classLevelEnabled = isTestEnabledInThisEnvironment(profileValueSource, ifProfileValue); if (classLevelEnabled) { ifProfileValue = AnnotatedElementUtils.findMergedAnnotation(testMethod, IfProfileValue.class); return isTestEnabledInThisEnvironment(profileValueSource, ifProfileValue); } return false; }