/** * Evaluates whether {@link FrameworkMethod}s are ignored based on the * {@link Ignore} annotation. */ @Override protected boolean isIgnored(FrameworkMethod child) { return child.getAnnotation(Ignore.class) != null; }
protected boolean shouldIgnore(FrameworkMethod method) { return method.getAnnotation(Ignore.class) != null; } }
@Override @SuppressWarnings( {"unchecked"}) public <T extends Annotation> T getAnnotation(Class<T> annotationType) { if ( Ignore.class.equals( annotationType ) && virtualIgnore != null ) { return (T) virtualIgnore; } return delegatee.getAnnotation( annotationType ); } }
/** * Get the {@code exception} that the supplied {@linkplain FrameworkMethod * test method} is expected to throw. * <p>Supports JUnit's {@link Test#expected() @Test(expected=...)} annotation. * <p>Can be overridden by subclasses. * @return the expected exception, or {@code null} if none was specified */ @Nullable protected Class<? extends Throwable> getExpectedException(FrameworkMethod frameworkMethod) { Test test = frameworkMethod.getAnnotation(Test.class); return (test != null && test.expected() != Test.None.class ? test.expected() : null); }
private String concatNames(List<FrameworkMethod> parametersMethods) { StringBuilder sb = new StringBuilder(); for (FrameworkMethod method : parametersMethods) { Parameterized.Parameters parameters = method.getAnnotation(Parameterized.Parameters.class); if (sb.length() != 0) { sb.append(", "); } sb.append(parameters.name()); } return sb.toString(); }
public static <T extends Annotation> T locateAnnotation( Class<T> annotationClass, FrameworkMethod frameworkMethod, TestClass testClass) { T annotation = frameworkMethod.getAnnotation( annotationClass ); if ( annotation == null ) { annotation = testClass.getJavaClass().getAnnotation( annotationClass ); } return annotation; }
/** * Retrieve the configured JUnit {@code timeout} from the {@link Test @Test} * annotation on the supplied {@linkplain FrameworkMethod test method}. * @return the timeout, or {@code 0} if none was specified */ protected long getJUnitTimeout(FrameworkMethod frameworkMethod) { Test test = frameworkMethod.getAnnotation(Test.class); return (test != null && test.timeout() > 0 ? test.timeout() : 0); }
/** * Returns a {@link Statement}: if {@code method}'s {@code @Test} annotation * has the {@code timeout} attribute, throw an exception if {@code next} * takes more than the specified number of milliseconds. * * @deprecated Will be private soon: use Rules instead */ @Deprecated protected Statement withPotentialTimeout(FrameworkMethod method, Object test, Statement next) { long timeout = getTimeout(method.getAnnotation(Test.class)); return timeout > 0 ? new FailOnTimeout(next, timeout) : next; }
private List<Runner> createRunners() throws Exception { if (runnerOverride != null) { return Collections.singletonList(runnerOverride); } Parameters parameters = parametersMethod.getAnnotation(Parameters.class); return Collections.unmodifiableList(createRunnersForParameters( allParameters, parameters.name(), getParametersRunnerFactory())); }
/** * Returns a {@link Statement}: if {@code method}'s {@code @Test} annotation * has the {@link Test#expected()} attribute, return normally only if {@code next} * throws an exception of the correct type, and throw an exception * otherwise. */ protected Statement possiblyExpectingExceptions(FrameworkMethod method, Object test, Statement next) { Test annotation = method.getAnnotation(Test.class); Class<? extends Throwable> expectedExceptionClass = getExpectedException(annotation); return expectedExceptionClass != null ? new ExpectException(next, expectedExceptionClass) : next; }
@Override protected Collection<FrameworkMethod> getSingleDataPointMethods(ParameterSignature sig) { Collection<FrameworkMethod> methods = super.getSingleDataPointMethods(sig); String requestedName = sig.getAnnotation(FromDataPoints.class).value(); List<FrameworkMethod> methodsWithMatchingNames = new ArrayList<FrameworkMethod>(); for (FrameworkMethod method : methods) { String[] methodNames = method.getAnnotation(DataPoint.class).value(); if (Arrays.asList(methodNames).contains(requestedName)) { methodsWithMatchingNames.add(method); } } return methodsWithMatchingNames; }
@Override protected Collection<FrameworkMethod> getDataPointsMethods(ParameterSignature sig) { Collection<FrameworkMethod> methods = super.getDataPointsMethods(sig); String requestedName = sig.getAnnotation(FromDataPoints.class).value(); List<FrameworkMethod> methodsWithMatchingNames = new ArrayList<FrameworkMethod>(); for (FrameworkMethod method : methods) { String[] methodNames = method.getAnnotation(DataPoints.class).value(); if (Arrays.asList(methodNames).contains(requestedName)) { methodsWithMatchingNames.add(method); } } return methodsWithMatchingNames; }
@Nonnull protected Class<?>[] getExtraShadows(FrameworkMethod method) { List<Class<?>> shadowClasses = new ArrayList<>(); addShadows(shadowClasses, getTestClass().getJavaClass().getAnnotation(SandboxConfig.class)); addShadows(shadowClasses, method.getAnnotation(SandboxConfig.class)); return shadowClasses.toArray(new Class[shadowClasses.size()]); }
private void processAnnotations(FrameworkMethod method) { // configuration will be added to potential class level configuration processWithClasses( method.getAnnotation( WithClasses.class ) ); processWithMappingFiles( method.getAnnotation( WithMappingFiles.class ) ); processOptions( method.getAnnotation( WithProcessorOption.class ), method.getAnnotation( WithProcessorOption.List.class ) ); // overrides potential class level configuration ignoreCompilationErrors = method.getAnnotation( IgnoreCompilationErrors.class ) != null; }
@Override public Object getValue() throws CouldNotGenerateValueException { try { return method.invokeExplosively(null); } catch (IllegalArgumentException e) { throw new RuntimeException( "unexpected: argument length is checked"); } catch (IllegalAccessException e) { throw new RuntimeException( "unexpected: getMethods returned an inaccessible method"); } catch (Throwable throwable) { DataPoint annotation = method.getAnnotation(DataPoint.class); Assume.assumeTrue(annotation == null || !isAssignableToAnyOf(annotation.ignoredExceptions(), throwable)); throw new CouldNotGenerateValueException(throwable); } }
@Override protected void validateTestMethods(List<Throwable> errors) { for (FrameworkMethod each : computeTestMethods()) { if (each.getAnnotation(Theory.class) != null) { each.validatePublicVoid(false, errors); } else { each.validatePublicVoidNoArg(false, errors); } } }
/** * Returns a {@link Statement}: if {@code method}'s {@code @Test} annotation * has the {@code timeout} attribute, throw an exception if {@code next} * takes more than the specified number of milliseconds. * @deprecated */ @Deprecated protected Statement withPotentialTimeout(FrameworkMethod method, Object test, Statement next) { long timeout = getTimeout(method.getAnnotation(Test.class)); if (timeout <= 0) { return next; } return FailOnTimeout.builder() .withTimeout(timeout, TimeUnit.MILLISECONDS) .build(next); }
/** * Only called reflectively. Do not use programmatically. */ public Parameterized(Class<?> klass) throws Throwable { super(klass, NO_RUNNERS); Parameters parameters = getParametersMethod().getAnnotation( Parameters.class); createRunnersForParameters(allParameters(), parameters.name()); }
@Override protected void runChild(final FrameworkMethod method, RunNotifier notifier) { Description description = describeChild(method); if (method.getAnnotation(Ignore.class) != null) { notifier.fireTestIgnored(description); } else { runLeaf(methodBlock(method), description, notifier); } }
@Override public void evaluate() throws Throwable { runWithAssignment(Assignments.allUnassigned( testMethod.getMethod(), getTestClass())); //if this test method is not annotated with Theory, then no successes is a valid case boolean hasTheoryAnnotation = testMethod.getAnnotation(Theory.class) != null; if (successes == 0 && hasTheoryAnnotation) { Assert .fail("Never found parameters that satisfied method assumptions. Violated assumptions: " + fInvalidParameters); } }