/** * Determine if the value for the {@link Parameter} in the supplied {@link ParameterContext} * should be autowired from the test's {@link ApplicationContext}. * <p>Returns {@code true} if the parameter is declared in a {@link Constructor} * that is annotated with {@link Autowired @Autowired} and otherwise delegates to * {@link ParameterAutowireUtils#isAutowirable}. * <p><strong>WARNING</strong>: If the parameter is declared in a {@code Constructor} * that is annotated with {@code @Autowired}, Spring will assume the responsibility * for resolving all parameters in the constructor. Consequently, no other registered * {@link ParameterResolver} will be able to resolve parameters. * @see #resolveParameter * @see ParameterAutowireUtils#isAutowirable */ @Override public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) { Parameter parameter = parameterContext.getParameter(); int index = parameterContext.getIndex(); Executable executable = parameter.getDeclaringExecutable(); return (executable instanceof Constructor && AnnotatedElementUtils.hasAnnotation(executable, Autowired.class)) || ParameterAutowireUtils.isAutowirable(parameter, index); }
/** * Resolve a value for the {@link Parameter} in the supplied {@link ParameterContext} by * retrieving the corresponding dependency from the test's {@link ApplicationContext}. * <p>Delegates to {@link ParameterAutowireUtils#resolveDependency}. * @see #supportsParameter * @see ParameterAutowireUtils#resolveDependency */ @Override @Nullable public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) { Parameter parameter = parameterContext.getParameter(); int index = parameterContext.getIndex(); Class<?> testClass = extensionContext.getRequiredTestClass(); ApplicationContext applicationContext = getApplicationContext(extensionContext); return ParameterAutowireUtils.resolveDependency(parameter, index, testClass, applicationContext); }
/** * Determine if the supplied {@link Parameter} can potentially be * autowired from an {@link ApplicationContext}. * <p>Returns {@code true} if the supplied parameter is of type * {@link ApplicationContext} (or a sub-type thereof) or is annotated or * meta-annotated with {@link Autowired @Autowired}, * {@link Qualifier @Qualifier}, or {@link Value @Value}. * @param parameter the parameter whose dependency should be autowired * @param parameterIndex the index of the parameter * @see #resolveDependency */ static boolean isAutowirable(Parameter parameter, int parameterIndex) { if (ApplicationContext.class.isAssignableFrom(parameter.getType())) { return true; } AnnotatedElement annotatedParameter = getEffectiveAnnotatedParameter(parameter, parameterIndex); return (AnnotatedElementUtils.hasAnnotation(annotatedParameter, Autowired.class) || AnnotatedElementUtils.hasAnnotation(annotatedParameter, Qualifier.class) || AnnotatedElementUtils.hasAnnotation(annotatedParameter, Value.class)); }
ApplicationContext applicationContext) { boolean required = findMergedAnnotation(parameter, Autowired.class).map(Autowired::required).orElse(true); MethodParameter methodParameter = (parameter.getDeclaringExecutable() instanceof Method ? MethodParameterFactory.createSynthesizingMethodParameter(parameter)
/** * Resolve a value for the {@link Parameter} in the supplied {@link ParameterContext} by * retrieving the corresponding dependency from the test's {@link ApplicationContext}. * <p>Delegates to {@link ParameterAutowireUtils#resolveDependency}. * @see #supportsParameter * @see ParameterAutowireUtils#resolveDependency */ @Override public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) { Parameter parameter = parameterContext.getParameter(); Class<?> testClass = extensionContext.getRequiredTestClass(); ApplicationContext applicationContext = getApplicationContext(extensionContext); return ParameterAutowireUtils.resolveDependency(parameter, testClass, applicationContext); }
/** * Determine if the value for the {@link Parameter} in the supplied {@link ParameterContext} * should be autowired from the test's {@link ApplicationContext}. * <p>Returns {@code true} if the parameter is declared in a {@link Constructor} * that is annotated with {@link Autowired @Autowired} and otherwise delegates to * {@link ParameterAutowireUtils#isAutowirable}. * <p><strong>WARNING</strong>: If the parameter is declared in a {@code Constructor} * that is annotated with {@code @Autowired}, Spring will assume the responsibility * for resolving all parameters in the constructor. Consequently, no other registered * {@link ParameterResolver} will be able to resolve parameters. * @see #resolveParameter * @see ParameterAutowireUtils#isAutowirable */ @Override public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) { Parameter parameter = parameterContext.getParameter(); Executable executable = parameter.getDeclaringExecutable(); return (executable instanceof Constructor && AnnotatedElementUtils.hasAnnotation(executable, Autowired.class)) || ParameterAutowireUtils.isAutowirable(parameter); }
Parameter parameter, int parameterIndex, Class<?> containingClass, ApplicationContext applicationContext) { AnnotatedElement annotatedParameter = getEffectiveAnnotatedParameter(parameter, parameterIndex); Autowired autowired = AnnotatedElementUtils.findMergedAnnotation(annotatedParameter, Autowired.class); boolean required = (autowired == null || autowired.required());
/** * Resolve a value for the {@link Parameter} in the supplied {@link ParameterContext} by * retrieving the corresponding dependency from the test's {@link ApplicationContext}. * <p>Delegates to {@link ParameterAutowireUtils#resolveDependency}. * @see #supportsParameter * @see ParameterAutowireUtils#resolveDependency */ @Override @Nullable public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) { Parameter parameter = parameterContext.getParameter(); int index = parameterContext.getIndex(); Class<?> testClass = extensionContext.getRequiredTestClass(); ApplicationContext applicationContext = getApplicationContext(extensionContext); return ParameterAutowireUtils.resolveDependency(parameter, index, testClass, applicationContext); }
/** * Determine if the value for the {@link Parameter} in the supplied {@link ParameterContext} * should be autowired from the test's {@link ApplicationContext}. * <p>Returns {@code true} if the parameter is declared in a {@link Constructor} * that is annotated with {@link Autowired @Autowired} and otherwise delegates to * {@link ParameterAutowireUtils#isAutowirable}. * <p><strong>WARNING</strong>: If the parameter is declared in a {@code Constructor} * that is annotated with {@code @Autowired}, Spring will assume the responsibility * for resolving all parameters in the constructor. Consequently, no other registered * {@link ParameterResolver} will be able to resolve parameters. * @see #resolveParameter * @see ParameterAutowireUtils#isAutowirable */ @Override public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) { Parameter parameter = parameterContext.getParameter(); int index = parameterContext.getIndex(); Executable executable = parameter.getDeclaringExecutable(); return (executable instanceof Constructor && AnnotatedElementUtils.hasAnnotation(executable, Autowired.class)) || ParameterAutowireUtils.isAutowirable(parameter, index); }
/** * Determine if the supplied {@link Parameter} can potentially be * autowired from an {@link ApplicationContext}. * <p>Returns {@code true} if the supplied parameter is of type * {@link ApplicationContext} (or a sub-type thereof) or is annotated or * meta-annotated with {@link Autowired @Autowired}, * {@link Qualifier @Qualifier}, or {@link Value @Value}. * @param parameter the parameter whose dependency should be autowired * @param parameterIndex the index of the parameter * @see #resolveDependency */ static boolean isAutowirable(Parameter parameter, int parameterIndex) { if (ApplicationContext.class.isAssignableFrom(parameter.getType())) { return true; } AnnotatedElement annotatedParameter = getEffectiveAnnotatedParameter(parameter, parameterIndex); return (AnnotatedElementUtils.hasAnnotation(annotatedParameter, Autowired.class) || AnnotatedElementUtils.hasAnnotation(annotatedParameter, Qualifier.class) || AnnotatedElementUtils.hasAnnotation(annotatedParameter, Value.class)); }
/** * Resolve a value for the {@link Parameter} in the supplied {@link ParameterContext} by * retrieving the corresponding dependency from the test's {@link ApplicationContext}. * <p>Delegates to {@link ParameterAutowireUtils#resolveDependency}. * @see #supportsParameter * @see ParameterAutowireUtils#resolveDependency */ @Override @Nullable public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) { Parameter parameter = parameterContext.getParameter(); int index = parameterContext.getIndex(); Class<?> testClass = extensionContext.getRequiredTestClass(); ApplicationContext applicationContext = getApplicationContext(extensionContext); return ParameterAutowireUtils.resolveDependency(parameter, index, testClass, applicationContext); }
/** * Determine if the value for the {@link Parameter} in the supplied {@link ParameterContext} * should be autowired from the test's {@link ApplicationContext}. * <p>Returns {@code true} if the parameter is declared in a {@link Constructor} * that is annotated with {@link Autowired @Autowired} and otherwise delegates to * {@link ParameterAutowireUtils#isAutowirable}. * <p><strong>WARNING</strong>: If the parameter is declared in a {@code Constructor} * that is annotated with {@code @Autowired}, Spring will assume the responsibility * for resolving all parameters in the constructor. Consequently, no other registered * {@link ParameterResolver} will be able to resolve parameters. * @see #resolveParameter * @see ParameterAutowireUtils#isAutowirable */ @Override public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) { Parameter parameter = parameterContext.getParameter(); int index = parameterContext.getIndex(); Executable executable = parameter.getDeclaringExecutable(); return (executable instanceof Constructor && AnnotatedElementUtils.hasAnnotation(executable, Autowired.class)) || ParameterAutowireUtils.isAutowirable(parameter, index); }
/** * Determine if the supplied {@link Parameter} can potentially be * autowired from an {@link ApplicationContext}. * <p>Returns {@code true} if the supplied parameter is of type * {@link ApplicationContext} (or a sub-type thereof) or is annotated or * meta-annotated with {@link Autowired @Autowired}, * {@link Qualifier @Qualifier}, or {@link Value @Value}. * @param parameter the parameter whose dependency should be autowired * @param parameterIndex the index of the parameter * @see #resolveDependency */ static boolean isAutowirable(Parameter parameter, int parameterIndex) { if (ApplicationContext.class.isAssignableFrom(parameter.getType())) { return true; } AnnotatedElement annotatedParameter = getEffectiveAnnotatedParameter(parameter, parameterIndex); return (AnnotatedElementUtils.hasAnnotation(annotatedParameter, Autowired.class) || AnnotatedElementUtils.hasAnnotation(annotatedParameter, Qualifier.class) || AnnotatedElementUtils.hasAnnotation(annotatedParameter, Value.class)); }
Parameter parameter, int parameterIndex, Class<?> containingClass, ApplicationContext applicationContext) { AnnotatedElement annotatedParameter = getEffectiveAnnotatedParameter(parameter, parameterIndex); Autowired autowired = AnnotatedElementUtils.findMergedAnnotation(annotatedParameter, Autowired.class); boolean required = (autowired == null || autowired.required());
Parameter parameter, int parameterIndex, Class<?> containingClass, ApplicationContext applicationContext) { AnnotatedElement annotatedParameter = getEffectiveAnnotatedParameter(parameter, parameterIndex); Autowired autowired = AnnotatedElementUtils.findMergedAnnotation(annotatedParameter, Autowired.class); boolean required = (autowired == null || autowired.required());