/** * Returns the return type of the method */ @Override public Class<?> getType() { return getReturnType(); }
/** * Returns the return type of the method */ @Override public Class<?> getType() { return getReturnType(); }
/** * Finds the methods annotated with the specified annotation and returning the specified type, * invokes it and pass the return value to the specified consumer. * * @since 4.13 */ public <T> void collectAnnotatedMethodValues(Object test, Class<? extends Annotation> annotationClass, Class<T> valueClass, MemberValueConsumer<T> consumer) { for (FrameworkMethod each : getAnnotatedMethods(annotationClass)) { try { /* * A method annotated with @Rule may return a @TestRule or a @MethodRule, * we cannot call the method to check whether the return type matches our * expectation i.e. subclass of valueClass. If we do that then the method * will be invoked twice and we do not want to do that. So we first check * whether return type matches our expectation and only then call the method * to fetch the MethodRule */ if (valueClass.isAssignableFrom(each.getReturnType())) { Object fieldValue = each.invokeExplosively(test); consumer.accept(each, valueClass.cast(fieldValue)); } } catch (Throwable e) { throw new RuntimeException( "Exception in " + each.getName(), e); } } }
private void addMultiPointMethods(ParameterSignature sig, List<PotentialAssignment> list) throws Throwable { for (FrameworkMethod dataPointsMethod : getDataPointsMethods(sig)) { Class<?> returnType = dataPointsMethod.getReturnType(); if ((returnType.isArray() && sig.canPotentiallyAcceptType(returnType.getComponentType())) || Iterable.class.isAssignableFrom(returnType)) { try { addDataPointsValues(returnType, sig, dataPointsMethod.getName(), list, dataPointsMethod.invokeExplosively(null)); } catch (Throwable throwable) { DataPoints annotation = dataPointsMethod.getAnnotation(DataPoints.class); if (annotation != null && isAssignableToAnyOf(annotation.ignoredExceptions(), throwable)) { return; } else { throw throwable; } } } } }
/** * Returns the return type of the method */ @Override public Class<?> getType() { return getReturnType(); }
/** * Returns the return type of the method */ @Override public Class<?> getType() { return getReturnType(); }
/** * Returns the return type of the method */ @Override public Class<?> getType() { return getReturnType(); }
/** * Returns the return type of the method */ @Override public Class<?> getType() { return getReturnType(); }
/** * Returns the return type of the method */ @Override public Class<?> getType() { return getReturnType(); }
@Override public Class<?> getReturnType() { return delegate.getReturnType(); }
private void verifyTestInputAnnotatedMethods(List<Throwable> errors) { List<FrameworkMethod> testInputMethods = getTestInputMethods(); if (testInputMethods.isEmpty()) { errors.add(new Exception(String.format( "At least one method with @%s annotation is required!", TestInput.class.getSimpleName() ))); } errors.addAll(testInputMethods.stream() .filter(m -> !m.getReturnType().equals(INPUT_DATA_RETURN_TYPE)) .map(m -> new Exception(String.format( "Method %s marked @%s must return %s", m.getName(), TestInput.class.getSimpleName(), INPUT_DATA_RETURN_TYPE.getCanonicalName() ))).collect(Collectors.toList())); }
private void verifyTestInputAnnotatedMethods(List<Throwable> errors) { List<FrameworkMethod> testInputMethods = getTestInputMethods(); if (testInputMethods.isEmpty()) { errors.add(new Exception(String.format( "At least one method with @%s annotation is required!", TestInput.class.getSimpleName() ))); } errors.addAll(testInputMethods.stream() .filter(m -> !m.getReturnType().equals(INPUT_DATA_RETURN_TYPE)) .map(m -> new Exception(String.format( "Method %s marked @%s must return %s", m.getName(), TestInput.class.getSimpleName(), INPUT_DATA_RETURN_TYPE.getCanonicalName() ))).collect(Collectors.toList())); }
private void verifyAtMostOneAdditionalDataMethodWithMatchingReturnType(List<Throwable> errors) { final List<FrameworkMethod> additionalDataAnnotatedMethods = getTestClass().getAnnotatedMethods (AdditionalData.class); if (additionalDataAnnotatedMethods.isEmpty()) { return; } if (additionalDataAnnotatedMethods.size() > 1) { errors.add(new Exception( String.format( "At most one method annotated with @%s allowed!", AdditionalData.class.getSimpleName() ) ) ); } errors.addAll(additionalDataAnnotatedMethods.stream() .filter(additionalDataMethod -> !additionalDataMethod.getReturnType().equals(INPUT_DATA_RETURN_TYPE)) .map(additionalDataMethod -> new Exception( String.format( "Method %s annotated with @%s must return a %s!", additionalDataMethod.getName(), AdditionalData.class.getSimpleName(), INPUT_DATA_RETURN_TYPE.getCanonicalName() ) )).collect(Collectors.toList())); }
private void verifyAtMostOneAdditionalDataMethodWithMatchingReturnType(List<Throwable> errors) { final List<FrameworkMethod> additionalDataAnnotatedMethods = getTestClass().getAnnotatedMethods (AdditionalData.class); if (additionalDataAnnotatedMethods.isEmpty()) { return; } if (additionalDataAnnotatedMethods.size() > 1) { errors.add(new Exception( String.format( "At most one method annotated with @%s allowed!", AdditionalData.class.getSimpleName() ) ) ); } errors.addAll(additionalDataAnnotatedMethods.stream() .filter(additionalDataMethod -> !additionalDataMethod.getReturnType().equals(INPUT_DATA_RETURN_TYPE)) .map(additionalDataMethod -> new Exception( String.format( "Method %s annotated with @%s must return a %s!", additionalDataMethod.getName(), AdditionalData.class.getSimpleName(), INPUT_DATA_RETURN_TYPE.getCanonicalName() ) )).collect(Collectors.toList())); }
public <T> List<T> getAnnotatedMethodValues(Object test, Class<? extends Annotation> annotationClass, Class<T> valueClass) { List<T> results = new ArrayList<T>(); for (FrameworkMethod each : getAnnotatedMethods(annotationClass)) { try { /* * A method annotated with @Rule may return a @TestRule or a @MethodRule, * we cannot call the method to check whether the return type matches our * expectation i.e. subclass of valueClass. If we do that then the method * will be invoked twice and we do not want to do that. So we first check * whether return type matches our expectation and only then call the method * to fetch the MethodRule */ if (valueClass.isAssignableFrom(each.getReturnType())) { Object fieldValue = each.invokeExplosively(test); results.add(valueClass.cast(fieldValue)); } } catch (Throwable e) { throw new RuntimeException( "Exception in " + each.getName(), e); } } return results; }
public <T> List<T> getAnnotatedMethodValues(Object test, Class<? extends Annotation> annotationClass, Class<T> valueClass) { List<T> results = new ArrayList<T>(); for (FrameworkMethod each : getAnnotatedMethods(annotationClass)) { try { /* * A method annotated with @Rule may return a @TestRule or a @MethodRule, * we cannot call the method to check whether the return type matches our * expectation i.e. subclass of valueClass. If we do that then the method * will be invoked twice and we do not want to do that. So we first check * whether return type matches our expectation and only then call the method * to fetch the MethodRule */ if (valueClass.isAssignableFrom(each.getReturnType())) { Object fieldValue = each.invokeExplosively(test); results.add(valueClass.cast(fieldValue)); } } catch (Throwable e) { throw new RuntimeException( "Exception in " + each.getName(), e); } } return results; }
))); if (!Boolean.TYPE.equals(method.getReturnType())) { errors.add(new Exception(String.format( "The method '%s' must return a boolean value, but '%s' is returned. (in %s)", method.getName(), method.getReturnType().getName(), testClass.getCanonicalName() )));
))); if (!Boolean.TYPE.equals(method.getReturnType())) { errors.add(new Exception(String.format( "The method '%s' must return a boolean value, but '%s' is returned. (in %s)", method.getName(), method.getReturnType().getName(), testClass.getCanonicalName() )));
private void addMultiPointMethods(ParameterSignature sig, List<PotentialAssignment> list) throws Throwable { for (FrameworkMethod dataPointsMethod : getDataPointsMethods(sig)) { Class<?> returnType = dataPointsMethod.getReturnType(); if ((returnType.isArray() && sig.canPotentiallyAcceptType(returnType.getComponentType())) || Iterable.class.isAssignableFrom(returnType)) { try { addDataPointsValues(returnType, sig, dataPointsMethod.getName(), list, dataPointsMethod.invokeExplosively(null)); } catch (Throwable throwable) { DataPoints annotation = dataPointsMethod.getAnnotation(DataPoints.class); if (annotation != null && isAssignableToAnyOf(annotation.ignoredExceptions(), throwable)) { return; } else { throw throwable; } } } } }
private void addMultiPointMethods(ParameterSignature sig, List<PotentialAssignment> list) throws Throwable { for (FrameworkMethod dataPointsMethod : getDataPointsMethods(sig)) { Class<?> returnType = dataPointsMethod.getReturnType(); if ((returnType.isArray() && sig.canPotentiallyAcceptType(returnType.getComponentType())) || Iterable.class.isAssignableFrom(returnType)) { try { addDataPointsValues(returnType, sig, dataPointsMethod.getName(), list, dataPointsMethod.invokeExplosively(null)); } catch (Throwable throwable) { DataPoints annotation = dataPointsMethod.getAnnotation(DataPoints.class); if (annotation != null && isAssignableToAnyOf(annotation.ignoredExceptions(), throwable)) { return; } else { throw throwable; } } } } }