/** * Process <em>annotated classes</em> in the supplied {@link ContextConfigurationAttributes}. * <p>If the <em>annotated classes</em> are {@code null} or empty and * {@link #isGenerateDefaultLocations()} returns {@code true}, this * {@code SmartContextLoader} will attempt to {@linkplain * #detectDefaultConfigurationClasses detect default configuration classes}. * If defaults are detected they will be * {@linkplain ContextConfigurationAttributes#setClasses(Class[]) set} in the * supplied configuration attributes. Otherwise, properties in the supplied * configuration attributes will not be modified. * @param configAttributes the context configuration attributes to process * @see org.springframework.test.context.SmartContextLoader#processContextConfiguration(ContextConfigurationAttributes) * @see #isGenerateDefaultLocations() * @see #detectDefaultConfigurationClasses(Class) */ @Override public void processContextConfiguration(ContextConfigurationAttributes configAttributes) { if (!configAttributes.hasClasses() && isGenerateDefaultLocations()) { configAttributes.setClasses(detectDefaultConfigurationClasses(configAttributes.getDeclaringClass())); } }
/** * Process <em>annotated classes</em> in the supplied {@link ContextConfigurationAttributes}. * <p>If the <em>annotated classes</em> are {@code null} or empty and * {@link #isGenerateDefaultLocations()} returns {@code true}, this * {@code SmartContextLoader} will attempt to {@link * #detectDefaultConfigurationClasses detect default configuration classes}. * If defaults are detected they will be * {@link ContextConfigurationAttributes#setClasses(Class[]) set} in the * supplied configuration attributes. Otherwise, properties in the supplied * configuration attributes will not be modified. * @param configAttributes the context configuration attributes to process * @see org.springframework.test.context.SmartContextLoader#processContextConfiguration(ContextConfigurationAttributes) * @see #isGenerateDefaultLocations() * @see #detectDefaultConfigurationClasses(Class) */ @Override public void processContextConfiguration(ContextConfigurationAttributes configAttributes) { if (!configAttributes.hasClasses() && isGenerateDefaultLocations()) { configAttributes.setClasses(detectDefaultConfigurationClasses(configAttributes.getDeclaringClass())); } }
@Override public void processContextConfiguration(ContextConfigurationAttributes configAttributes) { // Detect default XML configuration files: super.processContextConfiguration(configAttributes); // Detect default configuration classes: if (!configAttributes.hasClasses() && isGenerateDefaultLocations()) { configAttributes.setClasses(detectDefaultConfigurationClasses(configAttributes.getDeclaringClass())); } }
private void addConfigAttributesClasses( ContextConfigurationAttributes configAttributes, Class<?>[] classes) { List<Class<?>> combined = new ArrayList<>(); combined.addAll(Arrays.asList(classes)); if (configAttributes.getClasses() != null) { combined.addAll(Arrays.asList(configAttributes.getClasses())); } configAttributes.setClasses(ClassUtils.toClassArray(combined)); }
@Override public void processContextConfiguration( ContextConfigurationAttributes configAttributes ) { Class<?>[] classes = configAttributes.getClasses(); if( classes.length == 0 ) { // Allow empty loaders, in this case everything should be mocked configAttributes.setClasses( new Class<?>[]{Object.class} ); } super.processContextConfiguration( configAttributes ); }
@Override public void processContextConfiguration( ContextConfigurationAttributes configAttributes) { super.processContextConfiguration(configAttributes); if (!configAttributes.hasResources()) { Class<?>[] defaultConfigClasses = detectDefaultConfigurationClasses( configAttributes.getDeclaringClass()); configAttributes.setClasses(defaultConfigClasses); } }
/** * Process <em>annotated classes</em> in the supplied {@link ContextConfigurationAttributes}. * <p>If the <em>annotated classes</em> are {@code null} or empty and * {@link #isGenerateDefaultLocations()} returns {@code true}, this * {@code SmartContextLoader} will attempt to {@linkplain * #detectDefaultConfigurationClasses detect default configuration classes}. * If defaults are detected they will be * {@linkplain ContextConfigurationAttributes#setClasses(Class[]) set} in the * supplied configuration attributes. Otherwise, properties in the supplied * configuration attributes will not be modified. * @param configAttributes the context configuration attributes to process * @see org.springframework.test.context.SmartContextLoader#processContextConfiguration(ContextConfigurationAttributes) * @see #isGenerateDefaultLocations() * @see #detectDefaultConfigurationClasses(Class) */ @Override public void processContextConfiguration(ContextConfigurationAttributes configAttributes) { if (!configAttributes.hasClasses() && isGenerateDefaultLocations()) { configAttributes.setClasses(detectDefaultConfigurationClasses(configAttributes.getDeclaringClass())); } }
/** * Process <em>annotated classes</em> in the supplied {@link ContextConfigurationAttributes}. * <p>If the <em>annotated classes</em> are {@code null} or empty and * {@link #isGenerateDefaultLocations()} returns {@code true}, this * {@code SmartContextLoader} will attempt to {@link * #detectDefaultConfigurationClasses detect default configuration classes}. * If defaults are detected they will be * {@link ContextConfigurationAttributes#setClasses(Class[]) set} in the * supplied configuration attributes. Otherwise, properties in the supplied * configuration attributes will not be modified. * @param configAttributes the context configuration attributes to process * @see org.springframework.test.context.SmartContextLoader#processContextConfiguration(ContextConfigurationAttributes) * @see #isGenerateDefaultLocations() * @see #detectDefaultConfigurationClasses(Class) */ @Override public void processContextConfiguration(ContextConfigurationAttributes configAttributes) { if (!configAttributes.hasClasses() && isGenerateDefaultLocations()) { configAttributes.setClasses(detectDefaultConfigurationClasses(configAttributes.getDeclaringClass())); } }
/** * Process <em>annotated classes</em> in the supplied {@link ContextConfigurationAttributes}. * <p>If the <em>annotated classes</em> are {@code null} or empty and * {@link #isGenerateDefaultLocations()} returns {@code true}, this * {@code SmartContextLoader} will attempt to {@linkplain * #detectDefaultConfigurationClasses detect default configuration classes}. * If defaults are detected they will be * {@linkplain ContextConfigurationAttributes#setClasses(Class[]) set} in the * supplied configuration attributes. Otherwise, properties in the supplied * configuration attributes will not be modified. * @param configAttributes the context configuration attributes to process * @see org.springframework.test.context.SmartContextLoader#processContextConfiguration(ContextConfigurationAttributes) * @see #isGenerateDefaultLocations() * @see #detectDefaultConfigurationClasses(Class) */ @Override public void processContextConfiguration(ContextConfigurationAttributes configAttributes) { if (!configAttributes.hasClasses() && isGenerateDefaultLocations()) { configAttributes.setClasses(detectDefaultConfigurationClasses(configAttributes.getDeclaringClass())); } }
/** * Process <em>annotated classes</em> in the supplied {@link ContextConfigurationAttributes}. * <p>If the <em>annotated classes</em> are {@code null} or empty and * {@link #isGenerateDefaultLocations()} returns {@code true}, this * {@code SmartContextLoader} will attempt to {@link * #detectDefaultConfigurationClasses detect default configuration classes}. * If defaults are detected they will be * {@link ContextConfigurationAttributes#setClasses(Class[]) set} in the * supplied configuration attributes. Otherwise, properties in the supplied * configuration attributes will not be modified. * @param configAttributes the context configuration attributes to process * @see org.springframework.test.context.SmartContextLoader#processContextConfiguration(ContextConfigurationAttributes) * @see #isGenerateDefaultLocations() * @see #detectDefaultConfigurationClasses(Class) */ @Override public void processContextConfiguration(ContextConfigurationAttributes configAttributes) { if (!configAttributes.hasClasses() && isGenerateDefaultLocations()) { configAttributes.setClasses(detectDefaultConfigurationClasses(configAttributes.getDeclaringClass())); } }