Merge branch '2.0.x' into 2.1.x

Closes gh-17078
This commit is contained in:
Andy Wilkinson
2019-06-07 10:50:34 +01:00
2691 changed files with 27746 additions and 46049 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -33,14 +33,13 @@ import org.springframework.test.context.MergedContextConfiguration;
*
* @author Phillip Webb
*/
class OverrideAutoConfigurationContextCustomizerFactory
implements ContextCustomizerFactory {
class OverrideAutoConfigurationContextCustomizerFactory implements ContextCustomizerFactory {
@Override
public ContextCustomizer createContextCustomizer(Class<?> testClass,
List<ContextConfigurationAttributes> configurationAttributes) {
OverrideAutoConfiguration annotation = AnnotatedElementUtils
.findMergedAnnotation(testClass, OverrideAutoConfiguration.class);
OverrideAutoConfiguration annotation = AnnotatedElementUtils.findMergedAnnotation(testClass,
OverrideAutoConfiguration.class);
if (annotation != null && !annotation.enabled()) {
return new DisableAutoConfigurationContextCustomizer();
}
@@ -50,15 +49,11 @@ class OverrideAutoConfigurationContextCustomizerFactory
/**
* {@link ContextCustomizer} to disable full auto-configuration.
*/
private static class DisableAutoConfigurationContextCustomizer
implements ContextCustomizer {
private static class DisableAutoConfigurationContextCustomizer implements ContextCustomizer {
@Override
public void customizeContext(ConfigurableApplicationContext context,
MergedContextConfiguration mergedConfig) {
TestPropertyValues
.of(EnableAutoConfiguration.ENABLED_OVERRIDE_PROPERTY + "=false")
.applyTo(context);
public void customizeContext(ConfigurableApplicationContext context, MergedContextConfiguration mergedConfig) {
TestPropertyValues.of(EnableAutoConfiguration.ENABLED_OVERRIDE_PROPERTY + "=false").applyTo(context);
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -35,8 +35,7 @@ import org.springframework.test.context.support.DependencyInjectionTestExecution
* @author Phillip Webb
* @since 1.4.1
*/
public class SpringBootDependencyInjectionTestExecutionListener
extends DependencyInjectionTestExecutionListener {
public class SpringBootDependencyInjectionTestExecutionListener extends DependencyInjectionTestExecutionListener {
@Override
public void prepareTestInstance(TestContext testContext) throws Exception {
@@ -68,13 +67,10 @@ public class SpringBootDependencyInjectionTestExecutionListener
@Override
public Set<Class<? extends TestExecutionListener>> postProcessDefaultTestExecutionListeners(
Set<Class<? extends TestExecutionListener>> listeners) {
Set<Class<? extends TestExecutionListener>> updated = new LinkedHashSet<>(
listeners.size());
Set<Class<? extends TestExecutionListener>> updated = new LinkedHashSet<>(listeners.size());
for (Class<? extends TestExecutionListener> listener : listeners) {
updated.add(
listener.equals(DependencyInjectionTestExecutionListener.class)
? SpringBootDependencyInjectionTestExecutionListener.class
: listener);
updated.add(listener.equals(DependencyInjectionTestExecutionListener.class)
? SpringBootDependencyInjectionTestExecutionListener.class : listener);
}
return updated;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -29,8 +29,7 @@ class DataJdbcTestContextBootstrapper extends SpringBootTestContextBootstrapper
@Override
protected String[] getProperties(Class<?> testClass) {
DataJdbcTest annotation = AnnotatedElementUtils.getMergedAnnotation(testClass,
DataJdbcTest.class);
DataJdbcTest annotation = AnnotatedElementUtils.getMergedAnnotation(testClass, DataJdbcTest.class);
return (annotation != null) ? annotation.properties() : null;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -34,8 +34,7 @@ class DataJdbcTypeExcludeFilter extends AnnotationCustomizableTypeExcludeFilter
private final DataJdbcTest annotation;
DataJdbcTypeExcludeFilter(Class<?> testClass) {
this.annotation = AnnotatedElementUtils.getMergedAnnotation(testClass,
DataJdbcTest.class);
this.annotation = AnnotatedElementUtils.getMergedAnnotation(testClass, DataJdbcTest.class);
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -29,8 +29,7 @@ class DataLdapTestContextBootstrapper extends SpringBootTestContextBootstrapper
@Override
protected String[] getProperties(Class<?> testClass) {
DataLdapTest annotation = AnnotatedElementUtils.getMergedAnnotation(testClass,
DataLdapTest.class);
DataLdapTest annotation = AnnotatedElementUtils.getMergedAnnotation(testClass, DataLdapTest.class);
return (annotation != null) ? annotation.properties() : null;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -34,8 +34,7 @@ class DataLdapTypeExcludeFilter extends AnnotationCustomizableTypeExcludeFilter
private final DataLdapTest annotation;
DataLdapTypeExcludeFilter(Class<?> testClass) {
this.annotation = AnnotatedElementUtils.getMergedAnnotation(testClass,
DataLdapTest.class);
this.annotation = AnnotatedElementUtils.getMergedAnnotation(testClass, DataLdapTest.class);
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -29,8 +29,7 @@ class DataMongoTestContextBootstrapper extends SpringBootTestContextBootstrapper
@Override
protected String[] getProperties(Class<?> testClass) {
DataMongoTest annotation = AnnotatedElementUtils.getMergedAnnotation(testClass,
DataMongoTest.class);
DataMongoTest annotation = AnnotatedElementUtils.getMergedAnnotation(testClass, DataMongoTest.class);
return (annotation != null) ? annotation.properties() : null;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -34,8 +34,7 @@ class DataMongoTypeExcludeFilter extends AnnotationCustomizableTypeExcludeFilter
private final DataMongoTest annotation;
DataMongoTypeExcludeFilter(Class<?> testClass) {
this.annotation = AnnotatedElementUtils.getMergedAnnotation(testClass,
DataMongoTest.class);
this.annotation = AnnotatedElementUtils.getMergedAnnotation(testClass, DataMongoTest.class);
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -29,8 +29,7 @@ class DataNeo4jTestContextBootstrapper extends SpringBootTestContextBootstrapper
@Override
protected String[] getProperties(Class<?> testClass) {
DataNeo4jTest annotation = AnnotatedElementUtils.getMergedAnnotation(testClass,
DataNeo4jTest.class);
DataNeo4jTest annotation = AnnotatedElementUtils.getMergedAnnotation(testClass, DataNeo4jTest.class);
return (annotation != null) ? annotation.properties() : null;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -34,8 +34,7 @@ class DataNeo4jTypeExcludeFilter extends AnnotationCustomizableTypeExcludeFilter
private final DataNeo4jTest annotation;
DataNeo4jTypeExcludeFilter(Class<?> testClass) {
this.annotation = AnnotatedElementUtils.getMergedAnnotation(testClass,
DataNeo4jTest.class);
this.annotation = AnnotatedElementUtils.getMergedAnnotation(testClass, DataNeo4jTest.class);
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -29,8 +29,7 @@ class DataRedisTestContextBootstrapper extends SpringBootTestContextBootstrapper
@Override
protected String[] getProperties(Class<?> testClass) {
DataRedisTest annotation = AnnotatedElementUtils.getMergedAnnotation(testClass,
DataRedisTest.class);
DataRedisTest annotation = AnnotatedElementUtils.getMergedAnnotation(testClass, DataRedisTest.class);
return (annotation != null) ? annotation.properties() : null;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -34,8 +34,7 @@ class DataRedisTypeExcludeFilter extends AnnotationCustomizableTypeExcludeFilter
private final DataRedisTest annotation;
DataRedisTypeExcludeFilter(Class<?> testClass) {
this.annotation = AnnotatedElementUtils.getMergedAnnotation(testClass,
DataRedisTest.class);
this.annotation = AnnotatedElementUtils.getMergedAnnotation(testClass, DataRedisTest.class);
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -47,30 +47,28 @@ public abstract class AnnotationCustomizableTypeExcludeFilter extends TypeExclud
}
@Override
public boolean match(MetadataReader metadataReader,
MetadataReaderFactory metadataReaderFactory) throws IOException {
public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory)
throws IOException {
if (hasAnnotation()) {
return !(include(metadataReader, metadataReaderFactory)
&& !exclude(metadataReader, metadataReaderFactory));
return !(include(metadataReader, metadataReaderFactory) && !exclude(metadataReader, metadataReaderFactory));
}
return false;
}
protected boolean include(MetadataReader metadataReader,
MetadataReaderFactory metadataReaderFactory) throws IOException {
if (new FilterAnnotations(this.classLoader, getFilters(FilterType.INCLUDE))
.anyMatches(metadataReader, metadataReaderFactory)) {
protected boolean include(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory)
throws IOException {
if (new FilterAnnotations(this.classLoader, getFilters(FilterType.INCLUDE)).anyMatches(metadataReader,
metadataReaderFactory)) {
return true;
}
if (isUseDefaultFilters()
&& defaultInclude(metadataReader, metadataReaderFactory)) {
if (isUseDefaultFilters() && defaultInclude(metadataReader, metadataReaderFactory)) {
return true;
}
return false;
}
protected boolean defaultInclude(MetadataReader metadataReader,
MetadataReaderFactory metadataReaderFactory) throws IOException {
protected boolean defaultInclude(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory)
throws IOException {
for (Class<?> include : getDefaultIncludes()) {
if (isTypeOrAnnotated(metadataReader, metadataReaderFactory, include)) {
return true;
@@ -84,18 +82,16 @@ public abstract class AnnotationCustomizableTypeExcludeFilter extends TypeExclud
return false;
}
protected boolean exclude(MetadataReader metadataReader,
MetadataReaderFactory metadataReaderFactory) throws IOException {
return new FilterAnnotations(this.classLoader, getFilters(FilterType.EXCLUDE))
.anyMatches(metadataReader, metadataReaderFactory);
protected boolean exclude(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory)
throws IOException {
return new FilterAnnotations(this.classLoader, getFilters(FilterType.EXCLUDE)).anyMatches(metadataReader,
metadataReaderFactory);
}
@SuppressWarnings("unchecked")
protected final boolean isTypeOrAnnotated(MetadataReader metadataReader,
MetadataReaderFactory metadataReaderFactory, Class<?> type)
throws IOException {
AnnotationTypeFilter annotationFilter = new AnnotationTypeFilter(
(Class<? extends Annotation>) type);
MetadataReaderFactory metadataReaderFactory, Class<?> type) throws IOException {
AnnotationTypeFilter annotationFilter = new AnnotationTypeFilter((Class<? extends Annotation>) type);
AssignableTypeFilter typeFilter = new AssignableTypeFilter(type);
return annotationFilter.match(metadataReader, metadataReaderFactory)
|| typeFilter.match(metadataReader, metadataReaderFactory);
@@ -129,14 +125,11 @@ public abstract class AnnotationCustomizableTypeExcludeFilter extends TypeExclud
boolean result = true;
result = result && hasAnnotation() == other.hasAnnotation();
for (FilterType filterType : FilterType.values()) {
result &= ObjectUtils.nullSafeEquals(getFilters(filterType),
other.getFilters(filterType));
result &= ObjectUtils.nullSafeEquals(getFilters(filterType), other.getFilters(filterType));
}
result = result && isUseDefaultFilters() == other.isUseDefaultFilters();
result = result && ObjectUtils.nullSafeEquals(getDefaultIncludes(),
other.getDefaultIncludes());
result = result && ObjectUtils.nullSafeEquals(getComponentIncludes(),
other.getComponentIncludes());
result = result && ObjectUtils.nullSafeEquals(getDefaultIncludes(), other.getDefaultIncludes());
result = result && ObjectUtils.nullSafeEquals(getComponentIncludes(), other.getComponentIncludes());
return result;
}
@@ -146,8 +139,7 @@ public abstract class AnnotationCustomizableTypeExcludeFilter extends TypeExclud
int result = 0;
result = prime * result + Boolean.hashCode(hasAnnotation());
for (FilterType filterType : FilterType.values()) {
result = prime * result
+ ObjectUtils.nullSafeHashCode(getFilters(filterType));
result = prime * result + ObjectUtils.nullSafeHashCode(getFilters(filterType));
}
result = prime * result + Boolean.hashCode(isUseDefaultFilters());
result = prime * result + ObjectUtils.nullSafeHashCode(getDefaultIncludes());

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -81,8 +81,7 @@ public class FilterAnnotations implements Iterable<TypeFilter> {
"An error occurred while processing a CUSTOM type filter: ");
return BeanUtils.instantiateClass(filterClass, TypeFilter.class);
}
throw new IllegalArgumentException(
"Filter type not supported with Class value: " + filterType);
throw new IllegalArgumentException("Filter type not supported with Class value: " + filterType);
}
private TypeFilter createTypeFilter(FilterType filterType, String pattern) {
@@ -92,8 +91,7 @@ public class FilterAnnotations implements Iterable<TypeFilter> {
case REGEX:
return new RegexPatternTypeFilter(Pattern.compile(pattern));
}
throw new IllegalArgumentException(
"Filter type not supported with String pattern: " + filterType);
throw new IllegalArgumentException("Filter type not supported with String pattern: " + filterType);
}
@Override
@@ -101,8 +99,8 @@ public class FilterAnnotations implements Iterable<TypeFilter> {
return this.filters.iterator();
}
public boolean anyMatches(MetadataReader metadataReader,
MetadataReaderFactory metadataReaderFactory) throws IOException {
public boolean anyMatches(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory)
throws IOException {
for (TypeFilter filter : this) {
if (filter.match(metadataReader, metadataReaderFactory)) {
return true;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -38,13 +38,11 @@ import org.springframework.util.ReflectionUtils;
*/
class TypeExcludeFiltersContextCustomizer implements ContextCustomizer {
private static final String EXCLUDE_FILTER_BEAN_NAME = TypeExcludeFilters.class
.getName();
private static final String EXCLUDE_FILTER_BEAN_NAME = TypeExcludeFilters.class.getName();
private final Set<TypeExcludeFilter> filters;
TypeExcludeFiltersContextCustomizer(Class<?> testClass,
Set<Class<? extends TypeExcludeFilter>> filterClasses) {
TypeExcludeFiltersContextCustomizer(Class<?> testClass, Set<Class<? extends TypeExcludeFilter>> filterClasses) {
this.filters = instantiateTypeExcludeFilters(testClass, filterClasses);
}
@@ -57,8 +55,7 @@ class TypeExcludeFiltersContextCustomizer implements ContextCustomizer {
return Collections.unmodifiableSet(filters);
}
private TypeExcludeFilter instantiateTypeExcludeFilter(Class<?> testClass,
Class<?> filterClass) {
private TypeExcludeFilter instantiateTypeExcludeFilter(Class<?> testClass, Class<?> filterClass) {
try {
Constructor<?> constructor = getTypeExcludeFilterConstructor(filterClass);
ReflectionUtils.makeAccessible(constructor);
@@ -68,15 +65,14 @@ class TypeExcludeFiltersContextCustomizer implements ContextCustomizer {
return (TypeExcludeFilter) constructor.newInstance();
}
catch (Exception ex) {
throw new IllegalStateException("Unable to create filter for " + filterClass,
ex);
throw new IllegalStateException("Unable to create filter for " + filterClass, ex);
}
}
@Override
public boolean equals(Object obj) {
return (obj != null && getClass() == obj.getClass() && this.filters
.equals(((TypeExcludeFiltersContextCustomizer) obj).filters));
return (obj != null && getClass() == obj.getClass()
&& this.filters.equals(((TypeExcludeFiltersContextCustomizer) obj).filters));
}
@Override
@@ -88,8 +84,7 @@ class TypeExcludeFiltersContextCustomizer implements ContextCustomizer {
public void customizeContext(ConfigurableApplicationContext context,
MergedContextConfiguration mergedContextConfiguration) {
if (!this.filters.isEmpty()) {
context.getBeanFactory().registerSingleton(EXCLUDE_FILTER_BEAN_NAME,
createDelegatingTypeExcludeFilter());
context.getBeanFactory().registerSingleton(EXCLUDE_FILTER_BEAN_NAME, createDelegatingTypeExcludeFilter());
}
}
@@ -97,8 +92,8 @@ class TypeExcludeFiltersContextCustomizer implements ContextCustomizer {
return new TypeExcludeFilter() {
@Override
public boolean match(MetadataReader metadataReader,
MetadataReaderFactory metadataReaderFactory) throws IOException {
public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory)
throws IOException {
for (TypeExcludeFilter filter : TypeExcludeFiltersContextCustomizer.this.filters) {
if (filter.match(metadataReader, metadataReaderFactory)) {
return true;
@@ -110,8 +105,7 @@ class TypeExcludeFiltersContextCustomizer implements ContextCustomizer {
};
}
private Constructor<?> getTypeExcludeFilterConstructor(Class<?> type)
throws NoSuchMethodException {
private Constructor<?> getTypeExcludeFilterConstructor(Class<?> type) throws NoSuchMethodException {
try {
return type.getDeclaredConstructor(Class.class);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -39,8 +39,7 @@ class TypeExcludeFiltersContextCustomizerFactory implements ContextCustomizerFac
@Override
public ContextCustomizer createContextCustomizer(Class<?> testClass,
List<ContextConfigurationAttributes> configurationAttributes) {
TypeExcludeFilters annotation = AnnotatedElementUtils
.findMergedAnnotation(testClass, TypeExcludeFilters.class);
TypeExcludeFilters annotation = AnnotatedElementUtils.findMergedAnnotation(testClass, TypeExcludeFilters.class);
if (annotation != null) {
Set<Class<? extends TypeExcludeFilter>> filterClasses = new LinkedHashSet<>(
Arrays.asList(annotation.value()));

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -29,8 +29,7 @@ class JdbcTestContextBootstrapper extends SpringBootTestContextBootstrapper {
@Override
protected String[] getProperties(Class<?> testClass) {
JdbcTest annotation = AnnotatedElementUtils.getMergedAnnotation(testClass,
JdbcTest.class);
JdbcTest annotation = AnnotatedElementUtils.getMergedAnnotation(testClass, JdbcTest.class);
return (annotation != null) ? annotation.properties() : null;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -34,8 +34,7 @@ class JdbcTypeExcludeFilter extends AnnotationCustomizableTypeExcludeFilter {
private final JdbcTest annotation;
JdbcTypeExcludeFilter(Class<?> testClass) {
this.annotation = AnnotatedElementUtils.getMergedAnnotation(testClass,
JdbcTest.class);
this.annotation = AnnotatedElementUtils.getMergedAnnotation(testClass, JdbcTest.class);
}
@Override

View File

@@ -64,68 +64,57 @@ public class TestDatabaseAutoConfiguration {
}
@Bean
@ConditionalOnProperty(prefix = "spring.test.database", name = "replace",
havingValue = "AUTO_CONFIGURED")
@ConditionalOnProperty(prefix = "spring.test.database", name = "replace", havingValue = "AUTO_CONFIGURED")
@ConditionalOnMissingBean
public DataSource dataSource() {
return new EmbeddedDataSourceFactory(this.environment).getEmbeddedDatabase();
}
@Bean
@ConditionalOnProperty(prefix = "spring.test.database", name = "replace",
havingValue = "ANY", matchIfMissing = true)
@ConditionalOnProperty(prefix = "spring.test.database", name = "replace", havingValue = "ANY",
matchIfMissing = true)
public static EmbeddedDataSourceBeanFactoryPostProcessor embeddedDataSourceBeanFactoryPostProcessor() {
return new EmbeddedDataSourceBeanFactoryPostProcessor();
}
@Order(Ordered.LOWEST_PRECEDENCE)
private static class EmbeddedDataSourceBeanFactoryPostProcessor
implements BeanDefinitionRegistryPostProcessor {
private static class EmbeddedDataSourceBeanFactoryPostProcessor implements BeanDefinitionRegistryPostProcessor {
private static final Log logger = LogFactory
.getLog(EmbeddedDataSourceBeanFactoryPostProcessor.class);
private static final Log logger = LogFactory.getLog(EmbeddedDataSourceBeanFactoryPostProcessor.class);
@Override
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry)
throws BeansException {
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
Assert.isInstanceOf(ConfigurableListableBeanFactory.class, registry,
"Test Database Auto-configuration can only be "
+ "used with a ConfigurableListableBeanFactory");
"Test Database Auto-configuration can only be " + "used with a ConfigurableListableBeanFactory");
process(registry, (ConfigurableListableBeanFactory) registry);
}
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
throws BeansException {
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
}
private void process(BeanDefinitionRegistry registry,
ConfigurableListableBeanFactory beanFactory) {
private void process(BeanDefinitionRegistry registry, ConfigurableListableBeanFactory beanFactory) {
BeanDefinitionHolder holder = getDataSourceBeanDefinition(beanFactory);
if (holder != null) {
String beanName = holder.getBeanName();
boolean primary = holder.getBeanDefinition().isPrimary();
logger.info("Replacing '" + beanName + "' DataSource bean with "
+ (primary ? "primary " : "") + "embedded version");
logger.info("Replacing '" + beanName + "' DataSource bean with " + (primary ? "primary " : "")
+ "embedded version");
registry.removeBeanDefinition(beanName);
registry.registerBeanDefinition(beanName,
createEmbeddedBeanDefinition(primary));
registry.registerBeanDefinition(beanName, createEmbeddedBeanDefinition(primary));
}
}
private BeanDefinition createEmbeddedBeanDefinition(boolean primary) {
BeanDefinition beanDefinition = new RootBeanDefinition(
EmbeddedDataSourceFactoryBean.class);
BeanDefinition beanDefinition = new RootBeanDefinition(EmbeddedDataSourceFactoryBean.class);
beanDefinition.setPrimary(primary);
return beanDefinition;
}
private BeanDefinitionHolder getDataSourceBeanDefinition(
ConfigurableListableBeanFactory beanFactory) {
private BeanDefinitionHolder getDataSourceBeanDefinition(ConfigurableListableBeanFactory beanFactory) {
String[] beanNames = beanFactory.getBeanNamesForType(DataSource.class);
if (ObjectUtils.isEmpty(beanNames)) {
logger.warn("No DataSource beans found, "
+ "embedded version will not be used");
logger.warn("No DataSource beans found, " + "embedded version will not be used");
return null;
}
if (beanNames.length == 1) {
@@ -139,8 +128,7 @@ public class TestDatabaseAutoConfiguration {
return new BeanDefinitionHolder(beanDefinition, beanName);
}
}
logger.warn("No primary DataSource found, "
+ "embedded version will not be used");
logger.warn("No primary DataSource found, " + "embedded version will not be used");
return null;
}
@@ -189,19 +177,16 @@ public class TestDatabaseAutoConfiguration {
}
public EmbeddedDatabase getEmbeddedDatabase() {
EmbeddedDatabaseConnection connection = this.environment.getProperty(
"spring.test.database.connection", EmbeddedDatabaseConnection.class,
EmbeddedDatabaseConnection.NONE);
EmbeddedDatabaseConnection connection = this.environment.getProperty("spring.test.database.connection",
EmbeddedDatabaseConnection.class, EmbeddedDatabaseConnection.NONE);
if (EmbeddedDatabaseConnection.NONE.equals(connection)) {
connection = EmbeddedDatabaseConnection.get(getClass().getClassLoader());
}
Assert.state(connection != EmbeddedDatabaseConnection.NONE,
"Failed to replace DataSource with an embedded database for tests. If "
+ "you want an embedded database please put a supported one "
+ "on the classpath or tune the replace attribute of "
+ "@AutoConfigureTestDatabase.");
return new EmbeddedDatabaseBuilder().generateUniqueName(true)
.setType(connection.getType()).build();
+ "on the classpath or tune the replace attribute of " + "@AutoConfigureTestDatabase.");
return new EmbeddedDatabaseBuilder().generateUniqueName(true).setType(connection.getType()).build();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -29,8 +29,7 @@ class JooqTestContextBootstrapper extends SpringBootTestContextBootstrapper {
@Override
protected String[] getProperties(Class<?> testClass) {
JooqTest annotation = AnnotatedElementUtils.getMergedAnnotation(testClass,
JooqTest.class);
JooqTest annotation = AnnotatedElementUtils.getMergedAnnotation(testClass, JooqTest.class);
return (annotation != null) ? annotation.properties() : null;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -34,8 +34,7 @@ class JooqTypeExcludeFilter extends AnnotationCustomizableTypeExcludeFilter {
private final JooqTest annotation;
JooqTypeExcludeFilter(Class<?> testClass) {
this.annotation = AnnotatedElementUtils.getMergedAnnotation(testClass,
JooqTest.class);
this.annotation = AnnotatedElementUtils.getMergedAnnotation(testClass, JooqTest.class);
}
@Override

View File

@@ -52,8 +52,7 @@ class JsonExcludeFilter extends AnnotationCustomizableTypeExcludeFilter {
private final JsonTest annotation;
JsonExcludeFilter(Class<?> testClass) {
this.annotation = AnnotatedElementUtils.getMergedAnnotation(testClass,
JsonTest.class);
this.annotation = AnnotatedElementUtils.getMergedAnnotation(testClass, JsonTest.class);
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -29,8 +29,7 @@ class JsonTestContextBootstrapper extends SpringBootTestContextBootstrapper {
@Override
protected String[] getProperties(Class<?> testClass) {
JsonTest annotation = AnnotatedElementUtils.getMergedAnnotation(testClass,
JsonTest.class);
JsonTest annotation = AnnotatedElementUtils.getMergedAnnotation(testClass, JsonTest.class);
return (annotation != null) ? annotation.properties() : null;
}

View File

@@ -59,8 +59,7 @@ import org.springframework.util.ReflectionUtils;
@Configuration
@ConditionalOnClass(name = "org.assertj.core.api.Assert")
@ConditionalOnProperty("spring.test.jsontesters.enabled")
@AutoConfigureAfter({ JacksonAutoConfiguration.class, GsonAutoConfiguration.class,
JsonbAutoConfiguration.class })
@AutoConfigureAfter({ JacksonAutoConfiguration.class, GsonAutoConfiguration.class, JsonbAutoConfiguration.class })
public class JsonTestersAutoConfiguration {
@Bean
@@ -71,8 +70,7 @@ public class JsonTestersAutoConfiguration {
@Bean
@Scope("prototype")
public FactoryBean<BasicJsonTester> basicJsonTesterFactoryBean() {
return new JsonTesterFactoryBean<BasicJsonTester, Void>(BasicJsonTester.class,
null);
return new JsonTesterFactoryBean<BasicJsonTester, Void>(BasicJsonTester.class, null);
}
@Configuration
@@ -82,8 +80,7 @@ public class JsonTestersAutoConfiguration {
@Bean
@Scope("prototype")
@ConditionalOnBean(ObjectMapper.class)
public FactoryBean<JacksonTester<?>> jacksonTesterFactoryBean(
ObjectMapper mapper) {
public FactoryBean<JacksonTester<?>> jacksonTesterFactoryBean(ObjectMapper mapper) {
return new JsonTesterFactoryBean<>(JacksonTester.class, mapper);
}
@@ -145,14 +142,12 @@ public class JsonTestersAutoConfiguration {
Constructor<?>[] constructors = this.objectType.getDeclaredConstructors();
for (Constructor<?> constructor : constructors) {
if (constructor.getParameterCount() == 1
&& constructor.getParameterTypes()[0]
.isInstance(this.marshaller)) {
&& constructor.getParameterTypes()[0].isInstance(this.marshaller)) {
ReflectionUtils.makeAccessible(constructor);
return (T) BeanUtils.instantiateClass(constructor, this.marshaller);
}
}
throw new IllegalStateException(
this.objectType + " does not have a usable constructor");
throw new IllegalStateException(this.objectType + " does not have a usable constructor");
}
@Override
@@ -165,21 +160,17 @@ public class JsonTestersAutoConfiguration {
/**
* {@link BeanPostProcessor} used to initialize JSON testers.
*/
private static class JsonMarshalTestersBeanPostProcessor
extends InstantiationAwareBeanPostProcessorAdapter {
private static class JsonMarshalTestersBeanPostProcessor extends InstantiationAwareBeanPostProcessorAdapter {
@Override
public Object postProcessAfterInitialization(Object bean, String beanName)
throws BeansException {
ReflectionUtils.doWithFields(bean.getClass(),
(field) -> processField(bean, field));
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
ReflectionUtils.doWithFields(bean.getClass(), (field) -> processField(bean, field));
return bean;
}
private void processField(Object bean, Field field) {
if (AbstractJsonMarshalTester.class.isAssignableFrom(field.getType())) {
initializeTester(bean, field, bean.getClass(),
ResolvableType.forField(field).getGeneric());
initializeTester(bean, field, bean.getClass(), ResolvableType.forField(field).getGeneric());
}
else if (BasicJsonTester.class.isAssignableFrom(field.getType())) {
initializeTester(bean, field, bean.getClass());

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -29,8 +29,7 @@ class DataJpaTestContextBootstrapper extends SpringBootTestContextBootstrapper {
@Override
protected String[] getProperties(Class<?> testClass) {
DataJpaTest annotation = AnnotatedElementUtils.getMergedAnnotation(testClass,
DataJpaTest.class);
DataJpaTest annotation = AnnotatedElementUtils.getMergedAnnotation(testClass, DataJpaTest.class);
return (annotation != null) ? annotation.properties() : null;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -34,8 +34,7 @@ class DataJpaTypeExcludeFilter extends AnnotationCustomizableTypeExcludeFilter {
private final DataJpaTest annotation;
DataJpaTypeExcludeFilter(Class<?> testClass) {
this.annotation = AnnotatedElementUtils.getMergedAnnotation(testClass,
DataJpaTest.class);
this.annotation = AnnotatedElementUtils.getMergedAnnotation(testClass, DataJpaTest.class);
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -234,8 +234,7 @@ public class TestEntityManager {
* @return the entity manager
*/
public final EntityManager getEntityManager() {
EntityManager manager = EntityManagerFactoryUtils
.getTransactionalEntityManager(this.entityManagerFactory);
EntityManager manager = EntityManagerFactoryUtils.getTransactionalEntityManager(this.entityManagerFactory);
Assert.state(manager != null, "No transactional EntityManager found");
return manager;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -39,8 +39,7 @@ public class TestEntityManagerAutoConfiguration {
@Bean
@ConditionalOnMissingBean
public TestEntityManager testEntityManager(
EntityManagerFactory entityManagerFactory) {
public TestEntityManager testEntityManager(EntityManagerFactory entityManagerFactory) {
return new TestEntityManager(entityManagerFactory);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -65,19 +65,15 @@ public class AnnotationsPropertySource extends EnumerablePropertySource<Class<?>
return Collections.unmodifiableMap(properties);
}
private void collectProperties(Class<?> root, Class<?> source,
Map<String, Object> properties, Set<Class<?>> seen) {
private void collectProperties(Class<?> root, Class<?> source, Map<String, Object> properties, Set<Class<?>> seen) {
if (source != null && seen.add(source)) {
for (Annotation annotation : getMergedAnnotations(root, source)) {
if (!AnnotationUtils.isInJavaLangAnnotationPackage(annotation)) {
PropertyMapping typeMapping = annotation.annotationType()
.getAnnotation(PropertyMapping.class);
for (Method attribute : annotation.annotationType()
.getDeclaredMethods()) {
PropertyMapping typeMapping = annotation.annotationType().getAnnotation(PropertyMapping.class);
for (Method attribute : annotation.annotationType().getDeclaredMethods()) {
collectProperties(annotation, attribute, typeMapping, properties);
}
collectProperties(root, annotation.annotationType(), properties,
seen);
collectProperties(root, annotation.annotationType(), properties, seen);
}
}
collectProperties(root, source.getSuperclass(), properties, seen);
@@ -90,8 +86,7 @@ public class AnnotationsPropertySource extends EnumerablePropertySource<Class<?>
if (annotations != null) {
for (Annotation annotation : annotations) {
if (!AnnotationUtils.isInJavaLangAnnotationPackage(annotation)) {
Annotation mergedAnnotation = findMergedAnnotation(root,
annotation.annotationType());
Annotation mergedAnnotation = findMergedAnnotation(root, annotation.annotationType());
if (mergedAnnotation != null) {
mergedAnnotations.add(mergedAnnotation);
}
@@ -101,21 +96,18 @@ public class AnnotationsPropertySource extends EnumerablePropertySource<Class<?>
return mergedAnnotations;
}
private Annotation findMergedAnnotation(Class<?> source,
Class<? extends Annotation> annotationType) {
private Annotation findMergedAnnotation(Class<?> source, Class<? extends Annotation> annotationType) {
if (source == null) {
return null;
}
Annotation mergedAnnotation = AnnotatedElementUtils.getMergedAnnotation(source,
annotationType);
Annotation mergedAnnotation = AnnotatedElementUtils.getMergedAnnotation(source, annotationType);
return (mergedAnnotation != null) ? mergedAnnotation
: findMergedAnnotation(source.getSuperclass(), annotationType);
}
private void collectProperties(Annotation annotation, Method attribute,
PropertyMapping typeMapping, Map<String, Object> properties) {
PropertyMapping attributeMapping = AnnotationUtils.getAnnotation(attribute,
PropertyMapping.class);
private void collectProperties(Annotation annotation, Method attribute, PropertyMapping typeMapping,
Map<String, Object> properties) {
PropertyMapping attributeMapping = AnnotationUtils.getAnnotation(attribute, PropertyMapping.class);
SkipPropertyMapping skip = getMappingType(typeMapping, attributeMapping);
if (skip == SkipPropertyMapping.YES) {
return;
@@ -124,8 +116,7 @@ public class AnnotationsPropertySource extends EnumerablePropertySource<Class<?>
ReflectionUtils.makeAccessible(attribute);
Object value = ReflectionUtils.invokeMethod(attribute, annotation);
if (skip == SkipPropertyMapping.ON_DEFAULT_VALUE) {
Object defaultValue = AnnotationUtils.getDefaultValue(annotation,
attribute.getName());
Object defaultValue = AnnotationUtils.getDefaultValue(annotation, attribute.getName());
if (ObjectUtils.nullSafeEquals(value, defaultValue)) {
return;
}
@@ -133,8 +124,7 @@ public class AnnotationsPropertySource extends EnumerablePropertySource<Class<?>
putProperties(name, value, properties);
}
private SkipPropertyMapping getMappingType(PropertyMapping typeMapping,
PropertyMapping attributeMapping) {
private SkipPropertyMapping getMappingType(PropertyMapping typeMapping, PropertyMapping attributeMapping) {
if (attributeMapping != null) {
return attributeMapping.skip();
}
@@ -144,8 +134,7 @@ public class AnnotationsPropertySource extends EnumerablePropertySource<Class<?>
return SkipPropertyMapping.YES;
}
private String getName(PropertyMapping typeMapping, PropertyMapping attributeMapping,
Method attribute) {
private String getName(PropertyMapping typeMapping, PropertyMapping attributeMapping, Method attribute) {
String prefix = (typeMapping != null) ? typeMapping.value() : "";
String name = (attributeMapping != null) ? attributeMapping.value() : "";
if (!StringUtils.hasText(name)) {
@@ -158,8 +147,7 @@ public class AnnotationsPropertySource extends EnumerablePropertySource<Class<?>
Matcher matcher = CAMEL_CASE_PATTERN.matcher(name);
StringBuffer result = new StringBuffer();
while (matcher.find()) {
matcher.appendReplacement(result,
matcher.group(1) + '-' + StringUtils.uncapitalize(matcher.group(2)));
matcher.appendReplacement(result, matcher.group(1) + '-' + StringUtils.uncapitalize(matcher.group(2)));
}
matcher.appendTail(result);
return result.toString().toLowerCase(Locale.ENGLISH);
@@ -172,8 +160,7 @@ public class AnnotationsPropertySource extends EnumerablePropertySource<Class<?>
return postfix;
}
private void putProperties(String name, Object value,
Map<String, Object> properties) {
private void putProperties(String name, Object value, Map<String, Object> properties) {
if (ObjectUtils.isArray(value)) {
Object[] array = ObjectUtils.toObjectArray(value);
for (int i = 0; i < array.length; i++) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -50,15 +50,14 @@ class PropertyMappingContextCustomizer implements ContextCustomizer {
if (!this.propertySource.isEmpty()) {
context.getEnvironment().getPropertySources().addFirst(this.propertySource);
}
context.getBeanFactory().registerSingleton(
PropertyMappingCheckBeanPostProcessor.class.getName(),
context.getBeanFactory().registerSingleton(PropertyMappingCheckBeanPostProcessor.class.getName(),
new PropertyMappingCheckBeanPostProcessor());
}
@Override
public boolean equals(Object obj) {
return (obj != null && getClass() == obj.getClass() && this.propertySource
.equals(((PropertyMappingContextCustomizer) obj).propertySource));
return (obj != null && getClass() == obj.getClass()
&& this.propertySource.equals(((PropertyMappingContextCustomizer) obj).propertySource));
}
@Override
@@ -73,8 +72,7 @@ class PropertyMappingContextCustomizer implements ContextCustomizer {
static class PropertyMappingCheckBeanPostProcessor implements BeanPostProcessor {
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName)
throws BeansException {
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
Class<?> beanClass = bean.getClass();
Set<Class<?>> components = new LinkedHashSet<>();
Set<Class<?>> propertyMappings = new LinkedHashSet<>();
@@ -93,19 +91,17 @@ class PropertyMappingContextCustomizer implements ContextCustomizer {
beanClass = beanClass.getSuperclass();
}
if (!components.isEmpty() && !propertyMappings.isEmpty()) {
throw new IllegalStateException("The @PropertyMapping "
+ getAnnotationsDescription(propertyMappings)
throw new IllegalStateException("The @PropertyMapping " + getAnnotationsDescription(propertyMappings)
+ " cannot be used in combination with the @Component "
+ getAnnotationsDescription(components));
}
return bean;
}
private boolean isAnnotated(Annotation element,
Class<? extends Annotation> annotationType) {
private boolean isAnnotated(Annotation element, Class<? extends Annotation> annotationType) {
try {
return element.annotationType().equals(annotationType) || AnnotationUtils
.findAnnotation(element.annotationType(), annotationType) != null;
return element.annotationType().equals(annotationType)
|| AnnotationUtils.findAnnotation(element.annotationType(), annotationType) != null;
}
catch (Throwable ex) {
return false;
@@ -125,8 +121,7 @@ class PropertyMappingContextCustomizer implements ContextCustomizer {
}
@Override
public Object postProcessAfterInitialization(Object bean, String beanName)
throws BeansException {
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
return bean;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -34,8 +34,7 @@ class PropertyMappingContextCustomizerFactory implements ContextCustomizerFactor
@Override
public ContextCustomizer createContextCustomizer(Class<?> testClass,
List<ContextConfigurationAttributes> configurationAttributes) {
AnnotationsPropertySource propertySource = new AnnotationsPropertySource(
testClass);
AnnotationsPropertySource propertySource = new AnnotationsPropertySource(testClass);
return new PropertyMappingContextCustomizer(propertySource);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -63,25 +63,21 @@ public class RestDocsAutoConfiguration {
MockMvcRestDocumentationConfigurer configurer = MockMvcRestDocumentation
.documentationConfiguration(contextProvider);
configurationCustomizers.orderedStream()
.forEach((configurationCustomizer) -> configurationCustomizer
.customize(configurer));
.forEach((configurationCustomizer) -> configurationCustomizer.customize(configurer));
return configurer;
}
@Bean
public RestDocsMockMvcBuilderCustomizer restDocumentationConfigurer(
RestDocsProperties properties,
public RestDocsMockMvcBuilderCustomizer restDocumentationConfigurer(RestDocsProperties properties,
MockMvcRestDocumentationConfigurer configurer,
ObjectProvider<RestDocumentationResultHandler> resultHandler) {
return new RestDocsMockMvcBuilderCustomizer(properties, configurer,
resultHandler.getIfAvailable());
return new RestDocsMockMvcBuilderCustomizer(properties, configurer, resultHandler.getIfAvailable());
}
}
@Configuration
@ConditionalOnClass({ RequestSpecification.class,
RestAssuredRestDocumentation.class })
@ConditionalOnClass({ RequestSpecification.class, RestAssuredRestDocumentation.class })
@EnableConfigurationProperties(RestDocsProperties.class)
static class RestDocsRestAssuredConfiguration {
@@ -93,14 +89,13 @@ public class RestDocsAutoConfiguration {
RestAssuredRestDocumentationConfigurer configurer = RestAssuredRestDocumentation
.documentationConfiguration(contextProvider);
configurationCustomizers.orderedStream()
.forEach((configurationCustomizer) -> configurationCustomizer
.customize(configurer));
.forEach((configurationCustomizer) -> configurationCustomizer.customize(configurer));
return new RequestSpecBuilder().addFilter(configurer).build();
}
@Bean
public RestDocsRestAssuredBuilderCustomizer restAssuredBuilderCustomizer(
RestDocsProperties properties, RequestSpecification configurer) {
public RestDocsRestAssuredBuilderCustomizer restAssuredBuilderCustomizer(RestDocsProperties properties,
RequestSpecification configurer) {
return new RestDocsRestAssuredBuilderCustomizer(properties, configurer);
}
@@ -120,14 +115,12 @@ public class RestDocsAutoConfiguration {
WebTestClientRestDocumentationConfigurer configurer = WebTestClientRestDocumentation
.documentationConfiguration(contextProvider);
configurationCustomizers.orderedStream()
.forEach((configurationCustomizer) -> configurationCustomizer
.customize(configurer));
.forEach((configurationCustomizer) -> configurationCustomizer.customize(configurer));
return configurer;
}
@Bean
public RestDocsWebTestClientBuilderCustomizer restDocumentationConfigurer(
RestDocsProperties properties,
public RestDocsWebTestClientBuilderCustomizer restDocumentationConfigurer(RestDocsProperties properties,
WebTestClientRestDocumentationConfigurer configurer) {
return new RestDocsWebTestClientBuilderCustomizer(properties, configurer);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -29,8 +29,7 @@ import org.springframework.test.web.servlet.setup.ConfigurableMockMvcBuilder;
*
* @author Andy Wilkinson
*/
class RestDocsMockMvcBuilderCustomizer
implements InitializingBean, MockMvcBuilderCustomizer {
class RestDocsMockMvcBuilderCustomizer implements InitializingBean, MockMvcBuilderCustomizer {
private final RestDocsProperties properties;
@@ -38,8 +37,7 @@ class RestDocsMockMvcBuilderCustomizer
private final RestDocumentationResultHandler resultHandler;
RestDocsMockMvcBuilderCustomizer(RestDocsProperties properties,
MockMvcRestDocumentationConfigurer delegate,
RestDocsMockMvcBuilderCustomizer(RestDocsProperties properties, MockMvcRestDocumentationConfigurer delegate,
RestDocumentationResultHandler resultHandler) {
this.properties = properties;
this.delegate = delegate;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -33,8 +33,7 @@ class RestDocsRestAssuredBuilderCustomizer implements InitializingBean {
private final RequestSpecification delegate;
RestDocsRestAssuredBuilderCustomizer(RestDocsProperties properties,
RequestSpecification delegate) {
RestDocsRestAssuredBuilderCustomizer(RestDocsProperties properties, RequestSpecification delegate) {
this.properties = properties;
this.delegate = delegate;
}
@@ -43,8 +42,8 @@ class RestDocsRestAssuredBuilderCustomizer implements InitializingBean {
public void afterPropertiesSet() throws Exception {
PropertyMapper map = PropertyMapper.get();
String host = this.properties.getUriHost();
map.from(this.properties::getUriScheme).when(
(scheme) -> StringUtils.hasText(scheme) && StringUtils.hasText(host))
map.from(this.properties::getUriScheme)
.when((scheme) -> StringUtils.hasText(scheme) && StringUtils.hasText(host))
.to((scheme) -> this.delegate.baseUri(scheme + "://" + host));
map.from(this.properties::getUriPort).whenNonNull().to(this.delegate::port);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -61,27 +61,22 @@ public class RestDocsTestExecutionListener extends AbstractTestExecutionListener
private static class DocumentationHandler {
private void beforeTestMethod(TestContext testContext) throws Exception {
ManualRestDocumentation restDocumentation = findManualRestDocumentation(
testContext);
ManualRestDocumentation restDocumentation = findManualRestDocumentation(testContext);
if (restDocumentation != null) {
restDocumentation.beforeTest(testContext.getTestClass(),
testContext.getTestMethod().getName());
restDocumentation.beforeTest(testContext.getTestClass(), testContext.getTestMethod().getName());
}
}
private void afterTestMethod(TestContext testContext) {
ManualRestDocumentation restDocumentation = findManualRestDocumentation(
testContext);
ManualRestDocumentation restDocumentation = findManualRestDocumentation(testContext);
if (restDocumentation != null) {
restDocumentation.afterTest();
}
}
private ManualRestDocumentation findManualRestDocumentation(
TestContext testContext) {
private ManualRestDocumentation findManualRestDocumentation(TestContext testContext) {
try {
return testContext.getApplicationContext()
.getBean(ManualRestDocumentation.class);
return testContext.getApplicationContext().getBean(ManualRestDocumentation.class);
}
catch (NoSuchBeanDefinitionException ex) {
return null;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -61,8 +61,7 @@ class RestDocsWebTestClientBuilderCustomizer implements WebTestClientBuilderCust
if (port == null) {
return true;
}
return (scheme.equals("http") && port == 80)
|| (scheme.equals("https") && port == 443);
return (scheme.equals("http") && port == 80) || (scheme.equals("https") && port == 443);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -34,8 +34,7 @@ import org.springframework.util.StringUtils;
class RestDocumentationContextProviderRegistrar implements ImportBeanDefinitionRegistrar {
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata,
BeanDefinitionRegistry registry) {
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
Map<String, Object> annotationAttributes = importingClassMetadata
.getAnnotationAttributes(AutoConfigureRestDocs.class.getName());
BeanDefinitionBuilder definitionBuilder = BeanDefinitionBuilder
@@ -44,8 +43,7 @@ class RestDocumentationContextProviderRegistrar implements ImportBeanDefinitionR
if (StringUtils.hasText(outputDir)) {
definitionBuilder.addConstructorArgValue(outputDir);
}
registry.registerBeanDefinition(ManualRestDocumentation.class.getName(),
definitionBuilder.getBeanDefinition());
registry.registerBeanDefinition(ManualRestDocumentation.class.getName(), definitionBuilder.getBeanDefinition());
}
}

View File

@@ -42,8 +42,7 @@ import org.springframework.web.client.RestTemplate;
* @see AutoConfigureMockRestServiceServer
*/
@Configuration
@ConditionalOnProperty(prefix = "spring.test.webclient.mockrestserviceserver",
name = "enabled")
@ConditionalOnProperty(prefix = "spring.test.webclient.mockrestserviceserver", name = "enabled")
public class MockRestServiceServerAutoConfiguration {
@Bean
@@ -52,8 +51,7 @@ public class MockRestServiceServerAutoConfiguration {
}
@Bean
public MockRestServiceServer mockRestServiceServer(
MockServerRestTemplateCustomizer customizer) {
public MockRestServiceServer mockRestServiceServer(MockServerRestTemplateCustomizer customizer) {
try {
return createDeferredMockRestServiceServer(customizer);
}
@@ -62,8 +60,8 @@ public class MockRestServiceServerAutoConfiguration {
}
}
private MockRestServiceServer createDeferredMockRestServiceServer(
MockServerRestTemplateCustomizer customizer) throws Exception {
private MockRestServiceServer createDeferredMockRestServiceServer(MockServerRestTemplateCustomizer customizer)
throws Exception {
Constructor<MockRestServiceServer> constructor = MockRestServiceServer.class
.getDeclaredConstructor(RequestExpectationManager.class);
constructor.setAccessible(true);
@@ -76,8 +74,7 @@ public class MockRestServiceServerAutoConfiguration {
* {@link MockServerRestTemplateCustomizer#customize(RestTemplate)
* MockServerRestTemplateCustomizer} has been called.
*/
private static class DeferredRequestExpectationManager
implements RequestExpectationManager {
private static class DeferredRequestExpectationManager implements RequestExpectationManager {
private MockServerRestTemplateCustomizer customizer;
@@ -86,14 +83,12 @@ public class MockRestServiceServerAutoConfiguration {
}
@Override
public ResponseActions expectRequest(ExpectedCount count,
RequestMatcher requestMatcher) {
public ResponseActions expectRequest(ExpectedCount count, RequestMatcher requestMatcher) {
return getDelegate().expectRequest(count, requestMatcher);
}
@Override
public ClientHttpResponse validateRequest(ClientHttpRequest request)
throws IOException {
public ClientHttpResponse validateRequest(ClientHttpRequest request) throws IOException {
return getDelegate().validateRequest(request);
}
@@ -104,24 +99,18 @@ public class MockRestServiceServerAutoConfiguration {
@Override
public void reset() {
Map<RestTemplate, RequestExpectationManager> expectationManagers = this.customizer
.getExpectationManagers();
Map<RestTemplate, RequestExpectationManager> expectationManagers = this.customizer.getExpectationManagers();
if (expectationManagers.size() == 1) {
getDelegate().reset();
}
}
private RequestExpectationManager getDelegate() {
Map<RestTemplate, RequestExpectationManager> expectationManagers = this.customizer
.getExpectationManagers();
Assert.state(!expectationManagers.isEmpty(),
"Unable to use auto-configured MockRestServiceServer since "
+ "MockServerRestTemplateCustomizer has not been bound to "
+ "a RestTemplate");
Assert.state(expectationManagers.size() == 1,
"Unable to use auto-configured MockRestServiceServer since "
+ "MockServerRestTemplateCustomizer has been bound to "
+ "more than one RestTemplate");
Map<RestTemplate, RequestExpectationManager> expectationManagers = this.customizer.getExpectationManagers();
Assert.state(!expectationManagers.isEmpty(), "Unable to use auto-configured MockRestServiceServer since "
+ "MockServerRestTemplateCustomizer has not been bound to " + "a RestTemplate");
Assert.state(expectationManagers.size() == 1, "Unable to use auto-configured MockRestServiceServer since "
+ "MockServerRestTemplateCustomizer has been bound to " + "more than one RestTemplate");
return expectationManagers.values().iterator().next();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,8 +28,7 @@ import org.springframework.test.web.client.MockRestServiceServer;
*
* @author Phillip Webb
*/
class MockRestServiceServerResetTestExecutionListener
extends AbstractTestExecutionListener {
class MockRestServiceServerResetTestExecutionListener extends AbstractTestExecutionListener {
@Override
public int getOrder() {
@@ -39,8 +38,7 @@ class MockRestServiceServerResetTestExecutionListener
@Override
public void afterTestMethod(TestContext testContext) throws Exception {
ApplicationContext applicationContext = testContext.getApplicationContext();
String[] names = applicationContext
.getBeanNamesForType(MockRestServiceServer.class, false, false);
String[] names = applicationContext.getBeanNamesForType(MockRestServiceServer.class, false, false);
for (String name : names) {
applicationContext.getBean(name, MockRestServiceServer.class).reset();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -41,15 +41,13 @@ class RestClientExcludeFilter extends AnnotationCustomizableTypeExcludeFilter {
static {
Set<Class<?>> includes = new LinkedHashSet<>();
if (ClassUtils.isPresent(DATABIND_MODULE_CLASS_NAME,
RestClientExcludeFilter.class.getClassLoader())) {
if (ClassUtils.isPresent(DATABIND_MODULE_CLASS_NAME, RestClientExcludeFilter.class.getClassLoader())) {
try {
includes.add(Class.forName(DATABIND_MODULE_CLASS_NAME, true,
RestClientExcludeFilter.class.getClassLoader()));
}
catch (ClassNotFoundException ex) {
throw new IllegalStateException(
"Failed to load " + DATABIND_MODULE_CLASS_NAME, ex);
throw new IllegalStateException("Failed to load " + DATABIND_MODULE_CLASS_NAME, ex);
}
includes.add(JsonComponent.class);
}
@@ -59,8 +57,7 @@ class RestClientExcludeFilter extends AnnotationCustomizableTypeExcludeFilter {
private final RestClientTest annotation;
RestClientExcludeFilter(Class<?> testClass) {
this.annotation = AnnotatedElementUtils.getMergedAnnotation(testClass,
RestClientTest.class);
this.annotation = AnnotatedElementUtils.getMergedAnnotation(testClass, RestClientTest.class);
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -29,8 +29,7 @@ class RestClientTestContextBootstrapper extends SpringBootTestContextBootstrappe
@Override
protected String[] getProperties(Class<?> testClass) {
RestClientTest annotation = AnnotatedElementUtils.getMergedAnnotation(testClass,
RestClientTest.class);
RestClientTest annotation = AnnotatedElementUtils.getMergedAnnotation(testClass, RestClientTest.class);
return (annotation != null) ? annotation.properties() : null;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -36,8 +36,7 @@ import org.springframework.web.reactive.function.client.ExchangeStrategies;
* @author Andy Wilkinson
* @since 2.0.0
*/
public class SpringBootWebTestClientBuilderCustomizer
implements WebTestClientBuilderCustomizer {
public class SpringBootWebTestClientBuilderCustomizer implements WebTestClientBuilderCustomizer {
private final Collection<CodecCustomizer> codecCustomizers;
@@ -48,8 +47,7 @@ public class SpringBootWebTestClientBuilderCustomizer
* the builder's codecs using the given {@code codecCustomizers}.
* @param codecCustomizers the codec customizers
*/
public SpringBootWebTestClientBuilderCustomizer(
Collection<CodecCustomizer> codecCustomizers) {
public SpringBootWebTestClientBuilderCustomizer(Collection<CodecCustomizer> codecCustomizers) {
this.codecCustomizers = codecCustomizers;
}
@@ -67,15 +65,13 @@ public class SpringBootWebTestClientBuilderCustomizer
private void customizeWebTestClientCodecs(WebTestClient.Builder builder) {
if (!CollectionUtils.isEmpty(this.codecCustomizers)) {
builder.exchangeStrategies(ExchangeStrategies.builder()
.codecs(applyCustomizers(this.codecCustomizers)).build());
builder.exchangeStrategies(
ExchangeStrategies.builder().codecs(applyCustomizers(this.codecCustomizers)).build());
}
}
private Consumer<ClientCodecConfigurer> applyCustomizers(
Collection<CodecCustomizer> customizers) {
return (codecs) -> customizers
.forEach((customizer) -> customizer.customize(codecs));
private Consumer<ClientCodecConfigurer> applyCustomizers(Collection<CodecCustomizer> customizers) {
return (codecs) -> customizers.forEach((customizer) -> customizer.customize(codecs));
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -31,16 +31,13 @@ import org.springframework.test.context.TestContextBootstrapper;
class WebFluxTestContextBootstrapper extends SpringBootTestContextBootstrapper {
@Override
protected MergedContextConfiguration processMergedContextConfiguration(
MergedContextConfiguration mergedConfig) {
return new ReactiveWebMergedContextConfiguration(
super.processMergedContextConfiguration(mergedConfig));
protected MergedContextConfiguration processMergedContextConfiguration(MergedContextConfiguration mergedConfig) {
return new ReactiveWebMergedContextConfiguration(super.processMergedContextConfiguration(mergedConfig));
}
@Override
protected String[] getProperties(Class<?> testClass) {
WebFluxTest annotation = AnnotatedElementUtils.getMergedAnnotation(testClass,
WebFluxTest.class);
WebFluxTest annotation = AnnotatedElementUtils.getMergedAnnotation(testClass, WebFluxTest.class);
return (annotation != null) ? annotation.properties() : null;
}

View File

@@ -65,8 +65,7 @@ class WebFluxTypeExcludeFilter extends AnnotationCustomizableTypeExcludeFilter {
private final WebFluxTest annotation;
WebFluxTypeExcludeFilter(Class<?> testClass) {
this.annotation = AnnotatedElementUtils.getMergedAnnotation(testClass,
WebFluxTest.class);
this.annotation = AnnotatedElementUtils.getMergedAnnotation(testClass, WebFluxTest.class);
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -56,10 +56,8 @@ public class WebTestClientAutoConfiguration {
@ConditionalOnMissingBean
@ConditionalOnBean(WebHandler.class)
public WebTestClient webTestClient(ApplicationContext applicationContext,
List<WebTestClientBuilderCustomizer> customizers,
List<MockServerConfigurer> configurers) {
WebTestClient.MockServerSpec<?> mockServerSpec = WebTestClient
.bindToApplicationContext(applicationContext);
List<WebTestClientBuilderCustomizer> customizers, List<MockServerConfigurer> configurers) {
WebTestClient.MockServerSpec<?> mockServerSpec = WebTestClient.bindToApplicationContext(applicationContext);
for (MockServerConfigurer configurer : configurers) {
mockServerSpec.apply(configurer);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -57,8 +57,7 @@ public class MockMvcAutoConfiguration {
private final WebMvcProperties webMvcProperties;
MockMvcAutoConfiguration(WebApplicationContext context,
WebMvcProperties webMvcProperties) {
MockMvcAutoConfiguration(WebApplicationContext context, WebMvcProperties webMvcProperties) {
this.context = context;
this.webMvcProperties = webMvcProperties;
}
@@ -71,11 +70,9 @@ public class MockMvcAutoConfiguration {
@Bean
@ConditionalOnMissingBean(MockMvcBuilder.class)
public DefaultMockMvcBuilder mockMvcBuilder(
List<MockMvcBuilderCustomizer> customizers) {
public DefaultMockMvcBuilder mockMvcBuilder(List<MockMvcBuilderCustomizer> customizers) {
DefaultMockMvcBuilder builder = MockMvcBuilders.webAppContextSetup(this.context);
builder.addDispatcherServletCustomizer(
new MockMvcDispatcherServletCustomizer(this.webMvcProperties));
builder.addDispatcherServletCustomizer(new MockMvcDispatcherServletCustomizer(this.webMvcProperties));
for (MockMvcBuilderCustomizer customizer : customizers) {
customizer.customize(builder);
}
@@ -100,8 +97,7 @@ public class MockMvcAutoConfiguration {
return mockMvc.getDispatcherServlet();
}
private static class MockMvcDispatcherServletCustomizer
implements DispatcherServletCustomizer {
private static class MockMvcDispatcherServletCustomizer implements DispatcherServletCustomizer {
private final WebMvcProperties webMvcProperties;
@@ -111,12 +107,10 @@ public class MockMvcAutoConfiguration {
@Override
public void customize(DispatcherServlet dispatcherServlet) {
dispatcherServlet.setDispatchOptionsRequest(
this.webMvcProperties.isDispatchOptionsRequest());
dispatcherServlet.setDispatchTraceRequest(
this.webMvcProperties.isDispatchTraceRequest());
dispatcherServlet.setThrowExceptionIfNoHandlerFound(
this.webMvcProperties.isThrowExceptionIfNoHandlerFound());
dispatcherServlet.setDispatchOptionsRequest(this.webMvcProperties.isDispatchOptionsRequest());
dispatcherServlet.setDispatchTraceRequest(this.webMvcProperties.isDispatchTraceRequest());
dispatcherServlet
.setThrowExceptionIfNoHandlerFound(this.webMvcProperties.isThrowExceptionIfNoHandlerFound());
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,8 +27,7 @@ import org.springframework.test.context.support.AbstractTestExecutionListener;
*
* @author Phillip Webb
*/
class MockMvcPrintOnlyOnFailureTestExecutionListener
extends AbstractTestExecutionListener {
class MockMvcPrintOnlyOnFailureTestExecutionListener extends AbstractTestExecutionListener {
@Override
public int getOrder() {
@@ -38,8 +37,7 @@ class MockMvcPrintOnlyOnFailureTestExecutionListener
@Override
public void afterTestMethod(TestContext testContext) throws Exception {
if (testContext.getTestException() != null) {
DeferredLinesWriter writer = DeferredLinesWriter
.get(testContext.getApplicationContext());
DeferredLinesWriter writer = DeferredLinesWriter.get(testContext.getApplicationContext());
if (writer != null) {
writer.writeDeferredResult();
}

View File

@@ -29,8 +29,7 @@ import org.springframework.context.annotation.Import;
* @since 1.4.0
*/
@Configuration
@ConditionalOnProperty(prefix = "spring.test.mockmvc", name = "secure",
havingValue = "true", matchIfMissing = true)
@ConditionalOnProperty(prefix = "spring.test.mockmvc", name = "secure", havingValue = "true", matchIfMissing = true)
@Import({ SecurityAutoConfiguration.class, UserDetailsServiceAutoConfiguration.class,
MockMvcSecurityConfiguration.class })
public class MockMvcSecurityAutoConfiguration {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -58,8 +58,7 @@ class MockMvcSecurityConfiguration {
builder.apply(new MockMvcConfigurerAdapter() {
@Override
public RequestPostProcessor beforeMockMvcCreated(
ConfigurableMockMvcBuilder<?> builder,
public RequestPostProcessor beforeMockMvcCreated(ConfigurableMockMvcBuilder<?> builder,
WebApplicationContext context) {
return SecurityMockMvcRequestPostProcessors.testSecurityContext();
}

View File

@@ -39,8 +39,7 @@ import org.springframework.test.web.servlet.htmlunit.MockMvcWebClientBuilder;
@Configuration
@ConditionalOnClass(WebClient.class)
@AutoConfigureAfter(MockMvcAutoConfiguration.class)
@ConditionalOnProperty(prefix = "spring.test.mockmvc.webclient", name = "enabled",
matchIfMissing = true)
@ConditionalOnProperty(prefix = "spring.test.mockmvc.webclient", name = "enabled", matchIfMissing = true)
public class MockMvcWebClientAutoConfiguration {
private final Environment environment;
@@ -53,8 +52,7 @@ public class MockMvcWebClientAutoConfiguration {
@ConditionalOnMissingBean({ WebClient.class, MockMvcWebClientBuilder.class })
@ConditionalOnBean(MockMvc.class)
public MockMvcWebClientBuilder mockMvcWebClientBuilder(MockMvc mockMvc) {
return MockMvcWebClientBuilder.mockMvcSetup(mockMvc)
.withDelegate(new LocalHostWebClient(this.environment));
return MockMvcWebClientBuilder.mockMvcSetup(mockMvc).withDelegate(new LocalHostWebClient(this.environment));
}
@Bean

View File

@@ -45,8 +45,7 @@ import org.springframework.util.ClassUtils;
@Configuration
@ConditionalOnClass(HtmlUnitDriver.class)
@AutoConfigureAfter(MockMvcAutoConfiguration.class)
@ConditionalOnProperty(prefix = "spring.test.mockmvc.webdriver", name = "enabled",
matchIfMissing = true)
@ConditionalOnProperty(prefix = "spring.test.mockmvc.webdriver", name = "enabled", matchIfMissing = true)
public class MockMvcWebDriverAutoConfiguration {
private final Environment environment;
@@ -62,8 +61,7 @@ public class MockMvcWebDriverAutoConfiguration {
@ConditionalOnBean(MockMvc.class)
public MockMvcHtmlUnitDriverBuilder mockMvcHtmlUnitDriverBuilder(MockMvc mockMvc) {
return MockMvcHtmlUnitDriverBuilder.mockMvcSetup(mockMvc)
.withDelegate(new LocalHostWebConnectionHtmlUnitDriver(this.environment,
BrowserVersion.CHROME));
.withDelegate(new LocalHostWebConnectionHtmlUnitDriver(this.environment, BrowserVersion.CHROME));
}
@Bean
@@ -71,10 +69,8 @@ public class MockMvcWebDriverAutoConfiguration {
@ConditionalOnBean(MockMvcHtmlUnitDriverBuilder.class)
public HtmlUnitDriver htmlUnitDriver(MockMvcHtmlUnitDriverBuilder builder) {
HtmlUnitDriver driver = builder.build();
if (ClassUtils.isPresent(SECURITY_CONTEXT_EXECUTOR,
getClass().getClassLoader())) {
driver.setExecutor(new DelegatingSecurityContextExecutor(
Executors.newSingleThreadExecutor()));
if (ClassUtils.isPresent(SECURITY_CONTEXT_EXECUTOR, getClass().getClassLoader())) {
driver.setExecutor(new DelegatingSecurityContextExecutor(Executors.newSingleThreadExecutor()));
}
return driver;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -114,8 +114,7 @@ public class SpringBootMockMvcBuilderCustomizer implements MockMvcBuilderCustomi
.forEach((registration) -> addFilter(builder, registration));
}
private void addFilter(ConfigurableMockMvcBuilder<?> builder,
AbstractFilterRegistrationBean<?> registration) {
private void addFilter(ConfigurableMockMvcBuilder<?> builder, AbstractFilterRegistrationBean<?> registration) {
Filter filter = registration.getFilter();
Collection<String> urls = registration.getUrlPatterns();
if (urls.isEmpty()) {
@@ -232,8 +231,7 @@ public class SpringBootMockMvcBuilderCustomizer implements MockMvcBuilderCustomi
DeferredLinesWriter(WebApplicationContext context, LinesWriter delegate) {
Assert.state(context instanceof ConfigurableApplicationContext,
"A ConfigurableApplicationContext is required for printOnlyOnFailure");
((ConfigurableApplicationContext) context).getBeanFactory()
.registerSingleton(BEAN_NAME, this);
((ConfigurableApplicationContext) context).getBeanFactory().registerSingleton(BEAN_NAME, this);
this.delegate = delegate;
}
@@ -262,8 +260,7 @@ public class SpringBootMockMvcBuilderCustomizer implements MockMvcBuilderCustomi
*/
private static class LoggingLinesWriter implements LinesWriter {
private static final Log logger = LogFactory
.getLog("org.springframework.test.web.servlet.result");
private static final Log logger = LogFactory.getLog("org.springframework.test.web.servlet.result");
@Override
public void write(List<String> lines) {
@@ -310,24 +307,19 @@ public class SpringBootMockMvcBuilderCustomizer implements MockMvcBuilderCustomi
private static class FilterRegistrationBeans extends ServletContextInitializerBeans {
FilterRegistrationBeans(ListableBeanFactory beanFactory) {
super(beanFactory, FilterRegistrationBean.class,
DelegatingFilterProxyRegistrationBean.class);
super(beanFactory, FilterRegistrationBean.class, DelegatingFilterProxyRegistrationBean.class);
}
@Override
protected void addAdaptableBeans(ListableBeanFactory beanFactory) {
addAsRegistrationBean(beanFactory, Filter.class,
new FilterRegistrationBeanAdapter());
addAsRegistrationBean(beanFactory, Filter.class, new FilterRegistrationBeanAdapter());
}
private static class FilterRegistrationBeanAdapter
implements RegistrationBeanAdapter<Filter> {
private static class FilterRegistrationBeanAdapter implements RegistrationBeanAdapter<Filter> {
@Override
public RegistrationBean createRegistrationBean(String name, Filter source,
int totalNumberOfSourceBeans) {
FilterRegistrationBean<Filter> bean = new FilterRegistrationBean<>(
source);
public RegistrationBean createRegistrationBean(String name, Filter source, int totalNumberOfSourceBeans) {
FilterRegistrationBean<Filter> bean = new FilterRegistrationBean<>(source);
bean.setName(name);
return bean;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -44,8 +44,7 @@ class WebDriverContextCustomizerFactory implements ContextCustomizerFactory {
private static class Customizer implements ContextCustomizer {
@Override
public void customizeContext(ConfigurableApplicationContext context,
MergedContextConfiguration mergedConfig) {
public void customizeContext(ConfigurableApplicationContext context, MergedContextConfiguration mergedConfig) {
WebDriverScope.registerWith(context);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -117,11 +117,9 @@ class WebDriverScope implements Scope {
context.addBeanFactoryPostProcessor(WebDriverScope::postProcessBeanFactory);
}
private static void postProcessBeanFactory(
ConfigurableListableBeanFactory beanFactory) {
private static void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {
for (String beanClass : BEAN_CLASSES) {
for (String beanName : beanFactory
.getBeanNamesForType(ClassUtils.resolveClassName(beanClass, null))) {
for (String beanName : beanFactory.getBeanNamesForType(ClassUtils.resolveClassName(beanClass, null))) {
BeanDefinition definition = beanFactory.getBeanDefinition(beanName);
if (!StringUtils.hasLength(definition.getScope())) {
definition.setScope(NAME);
@@ -137,8 +135,7 @@ class WebDriverScope implements Scope {
*/
public static WebDriverScope getFrom(ApplicationContext context) {
if (context instanceof ConfigurableApplicationContext) {
Scope scope = ((ConfigurableApplicationContext) context).getBeanFactory()
.getRegisteredScope(NAME);
Scope scope = ((ConfigurableApplicationContext) context).getBeanFactory().getRegisteredScope(NAME);
return (scope instanceof WebDriverScope) ? (WebDriverScope) scope : null;
}
return null;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -38,11 +38,9 @@ class WebDriverTestExecutionListener extends AbstractTestExecutionListener {
@Override
public void afterTestMethod(TestContext testContext) throws Exception {
WebDriverScope scope = WebDriverScope
.getFrom(testContext.getApplicationContext());
WebDriverScope scope = WebDriverScope.getFrom(testContext.getApplicationContext());
if (scope != null && scope.reset()) {
testContext.setAttribute(
DependencyInjectionTestExecutionListener.REINJECT_DEPENDENCIES_ATTRIBUTE,
testContext.setAttribute(DependencyInjectionTestExecutionListener.REINJECT_DEPENDENCIES_ATTRIBUTE,
Boolean.TRUE);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -31,16 +31,13 @@ import org.springframework.test.context.web.WebMergedContextConfiguration;
class WebMvcTestContextBootstrapper extends SpringBootTestContextBootstrapper {
@Override
protected MergedContextConfiguration processMergedContextConfiguration(
MergedContextConfiguration mergedConfig) {
return new WebMergedContextConfiguration(
super.processMergedContextConfiguration(mergedConfig), "");
protected MergedContextConfiguration processMergedContextConfiguration(MergedContextConfiguration mergedConfig) {
return new WebMergedContextConfiguration(super.processMergedContextConfiguration(mergedConfig), "");
}
@Override
protected String[] getProperties(Class<?> testClass) {
WebMvcTest annotation = AnnotatedElementUtils.getMergedAnnotation(testClass,
WebMvcTest.class);
WebMvcTest annotation = AnnotatedElementUtils.getMergedAnnotation(testClass, WebMvcTest.class);
return (annotation != null) ? annotation.properties() : null;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -90,18 +90,15 @@ class WebMvcTypeExcludeFilter extends AnnotationCustomizableTypeExcludeFilter {
private static final Set<Class<?>> DEFAULT_INCLUDES_SECURITY_CONFIGURER_AND_CONTROLLER;
static {
Set<Class<?>> includes = new LinkedHashSet<>(
DEFAULT_INCLUDES_AND_SECURITY_CONFIGURER);
Set<Class<?>> includes = new LinkedHashSet<>(DEFAULT_INCLUDES_AND_SECURITY_CONFIGURER);
includes.add(Controller.class);
DEFAULT_INCLUDES_SECURITY_CONFIGURER_AND_CONTROLLER = Collections
.unmodifiableSet(includes);
DEFAULT_INCLUDES_SECURITY_CONFIGURER_AND_CONTROLLER = Collections.unmodifiableSet(includes);
}
private final WebMvcTest annotation;
WebMvcTypeExcludeFilter(Class<?> testClass) {
this.annotation = AnnotatedElementUtils.getMergedAnnotation(testClass,
WebMvcTest.class);
this.annotation = AnnotatedElementUtils.getMergedAnnotation(testClass, WebMvcTest.class);
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,8 +28,7 @@ import org.springframework.context.ApplicationContext;
*
* @author Andy Wilkinson
*/
public final class AutoConfigurationImportedCondition
extends Condition<ApplicationContext> {
public final class AutoConfigurationImportedCondition extends Condition<ApplicationContext> {
private final Class<?> autoConfigurationClass;
@@ -41,10 +40,8 @@ public final class AutoConfigurationImportedCondition
@Override
public boolean matches(ApplicationContext context) {
ConditionEvaluationReport report = ConditionEvaluationReport
.get((ConfigurableListableBeanFactory) context
.getAutowireCapableBeanFactory());
return report.getConditionAndOutcomesBySource()
.containsKey(this.autoConfigurationClass.getName());
.get((ConfigurableListableBeanFactory) context.getAutowireCapableBeanFactory());
return report.getConditionAndOutcomesBySource().containsKey(this.autoConfigurationClass.getName());
}
/**
@@ -53,8 +50,7 @@ public final class AutoConfigurationImportedCondition
* @param autoConfigurationClass the auto-configuration class
* @return the condition
*/
public static AutoConfigurationImportedCondition importedAutoConfiguration(
Class<?> autoConfigurationClass) {
public static AutoConfigurationImportedCondition importedAutoConfiguration(Class<?> autoConfigurationClass) {
return new AutoConfigurationImportedCondition(autoConfigurationClass);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -33,31 +33,26 @@ public class OverrideAutoConfigurationContextCustomizerFactoryTests {
@Test
public void getContextCustomizerWhenHasNoAnnotationShouldReturnNull() {
ContextCustomizer customizer = this.factory
.createContextCustomizer(NoAnnotation.class, null);
ContextCustomizer customizer = this.factory.createContextCustomizer(NoAnnotation.class, null);
assertThat(customizer).isNull();
}
@Test
public void getContextCustomizerWhenHasAnnotationEnabledTrueShouldReturnNull() {
ContextCustomizer customizer = this.factory
.createContextCustomizer(WithAnnotationEnabledTrue.class, null);
ContextCustomizer customizer = this.factory.createContextCustomizer(WithAnnotationEnabledTrue.class, null);
assertThat(customizer).isNull();
}
@Test
public void getContextCustomizerWhenHasAnnotationEnabledFalseShouldReturnCustomizer() {
ContextCustomizer customizer = this.factory
.createContextCustomizer(WithAnnotationEnabledFalse.class, null);
ContextCustomizer customizer = this.factory.createContextCustomizer(WithAnnotationEnabledFalse.class, null);
assertThat(customizer).isNotNull();
}
@Test
public void hashCodeAndEquals() {
ContextCustomizer customizer1 = this.factory
.createContextCustomizer(WithAnnotationEnabledFalse.class, null);
ContextCustomizer customizer2 = this.factory
.createContextCustomizer(WithSameAnnotation.class, null);
ContextCustomizer customizer1 = this.factory.createContextCustomizer(WithAnnotationEnabledFalse.class, null);
ContextCustomizer customizer2 = this.factory.createContextCustomizer(WithSameAnnotation.class, null);
assertThat(customizer1.hashCode()).isEqualTo(customizer2.hashCode());
assertThat(customizer1).isEqualTo(customizer1).isEqualTo(customizer2);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -51,8 +51,7 @@ public class SpringBootDependencyInjectionTestExecutionListenerTests {
@Test
public void orderShouldBeSameAsDependencyInjectionTestExecutionListener() {
Ordered injectionListener = new DependencyInjectionTestExecutionListener();
assertThat(this.reportListener.getOrder())
.isEqualTo(injectionListener.getOrder());
assertThat(this.reportListener.getOrder()).isEqualTo(injectionListener.getOrder());
}
@Test
@@ -82,8 +81,7 @@ public class SpringBootDependencyInjectionTestExecutionListenerTests {
SpringApplication application = new SpringApplication(Config.class);
application.setWebApplicationType(WebApplicationType.NONE);
given(testContext.getApplicationContext()).willThrow(new RuntimeException());
assertThatIllegalStateException()
.isThrownBy(() -> this.reportListener.prepareTestInstance(testContext))
assertThatIllegalStateException().isThrownBy(() -> this.reportListener.prepareTestInstance(testContext))
.isEqualTo(originalFailure);
}

View File

@@ -48,8 +48,7 @@ public class ImportsContextCustomizerFactoryWithAutoConfigurationTests {
static ApplicationContext contextFromTest;
@Test
public void testClassesThatHaveSameAnnotationsShareAContext()
throws InitializationError {
public void testClassesThatHaveSameAnnotationsShareAContext() throws InitializationError {
RunNotifier notifier = new RunNotifier();
new SpringJUnit4ClassRunner(DataJpaTest1.class).run(notifier);
ApplicationContext test1Context = contextFromTest;
@@ -59,8 +58,7 @@ public class ImportsContextCustomizerFactoryWithAutoConfigurationTests {
}
@Test
public void testClassesThatOnlyHaveDifferingUnrelatedAnnotationsShareAContext()
throws InitializationError {
public void testClassesThatOnlyHaveDifferingUnrelatedAnnotationsShareAContext() throws InitializationError {
RunNotifier notifier = new RunNotifier();
new SpringJUnit4ClassRunner(DataJpaTest1.class).run(notifier);
ApplicationContext test1Context = contextFromTest;

View File

@@ -59,36 +59,31 @@ public class DataJdbcTestIntegrationTests {
@Test
public void testRepository() {
this.jdbcTemplate.update(
"INSERT INTO EXAMPLE_ENTITY (id, name, reference) VALUES (1, 'a', 'alpha')");
this.jdbcTemplate.update(
"INSERT INTO EXAMPLE_ENTITY (id, name, reference) VALUES (2, 'b', 'bravo')");
this.jdbcTemplate.update("INSERT INTO EXAMPLE_ENTITY (id, name, reference) VALUES (1, 'a', 'alpha')");
this.jdbcTemplate.update("INSERT INTO EXAMPLE_ENTITY (id, name, reference) VALUES (2, 'b', 'bravo')");
assertThat(this.repository.findAll()).hasSize(2);
}
@Test
public void replacesDefinedDataSourceWithEmbeddedDefault() throws Exception {
String product = this.dataSource.getConnection().getMetaData()
.getDatabaseProductName();
String product = this.dataSource.getConnection().getMetaData().getDatabaseProductName();
assertThat(product).isEqualTo("H2");
}
@Test
public void didNotInjectExampleComponent() {
assertThatExceptionOfType(NoSuchBeanDefinitionException.class).isThrownBy(
() -> this.applicationContext.getBean(ExampleComponent.class));
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
.isThrownBy(() -> this.applicationContext.getBean(ExampleComponent.class));
}
@Test
public void flywayAutoConfigurationWasImported() {
assertThat(this.applicationContext)
.has(importedAutoConfiguration(FlywayAutoConfiguration.class));
assertThat(this.applicationContext).has(importedAutoConfiguration(FlywayAutoConfiguration.class));
}
@Test
public void liquibaseAutoConfigurationWasImported() {
assertThat(this.applicationContext)
.has(importedAutoConfiguration(LiquibaseAutoConfiguration.class));
assertThat(this.applicationContext).has(importedAutoConfiguration(LiquibaseAutoConfiguration.class));
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -33,8 +33,7 @@ public class ExampleDataJdbcApplication {
@Bean
public DataSource dataSource() {
return new EmbeddedDatabaseBuilder().generateUniqueName(true)
.setType(EmbeddedDatabaseType.HSQL).build();
return new EmbeddedDatabaseBuilder().generateUniqueName(true).setType(EmbeddedDatabaseType.HSQL).build();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -59,11 +59,10 @@ public class DataLdapTestIntegrationTests {
LdapQuery ldapQuery = LdapQueryBuilder.query().where("cn").is("Bob Smith");
Optional<ExampleEntry> entry = this.exampleRepository.findOne(ldapQuery);
assertThat(entry.isPresent()).isTrue();
assertThat(entry.get().getDn()).isEqualTo(LdapUtils
.newLdapName("cn=Bob Smith,ou=company1,c=Sweden,dc=spring,dc=org"));
assertThat(entry.get().getDn())
.isEqualTo(LdapUtils.newLdapName("cn=Bob Smith,ou=company1,c=Sweden,dc=spring,dc=org"));
assertThat(this.ldapTemplate.findOne(ldapQuery, ExampleEntry.class).getDn())
.isEqualTo(LdapUtils.newLdapName(
"cn=Bob Smith,ou=company1,c=Sweden,dc=spring,dc=org"));
.isEqualTo(LdapUtils.newLdapName("cn=Bob Smith,ou=company1,c=Sweden,dc=spring,dc=org"));
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -46,11 +46,9 @@ public class DataMongoTestReactiveIntegrationTests {
public void testRepository() {
ExampleDocument exampleDocument = new ExampleDocument();
exampleDocument.setText("Look, new @DataMongoTest!");
exampleDocument = this.exampleRepository.save(exampleDocument)
.block(Duration.ofSeconds(30));
exampleDocument = this.exampleRepository.save(exampleDocument).block(Duration.ofSeconds(30));
assertThat(exampleDocument.getId()).isNotNull();
assertThat(this.mongoTemplate.collectionExists("exampleDocuments")
.block(Duration.ofSeconds(30))).isTrue();
assertThat(this.mongoTemplate.collectionExists("exampleDocuments").block(Duration.ofSeconds(30))).isTrue();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,7 +23,6 @@ import org.springframework.data.mongodb.repository.ReactiveMongoRepository;
*
* @author Stephane Nicoll
*/
public interface ExampleReactiveRepository
extends ReactiveMongoRepository<ExampleDocument, String> {
public interface ExampleReactiveRepository extends ReactiveMongoRepository<ExampleDocument, String> {
}

View File

@@ -76,14 +76,11 @@ public class DataNeo4jTestIntegrationTests {
.isThrownBy(() -> this.applicationContext.getBean(ExampleService.class));
}
static class Initializer
implements ApplicationContextInitializer<ConfigurableApplicationContext> {
static class Initializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
@Override
public void initialize(
ConfigurableApplicationContext configurableApplicationContext) {
TestPropertyValues
.of("spring.data.neo4j.uri=" + neo4j.getContainer().getBoltUrl())
public void initialize(ConfigurableApplicationContext configurableApplicationContext) {
TestPropertyValues.of("spring.data.neo4j.uri=" + neo4j.getContainer().getBoltUrl())
.applyTo(configurableApplicationContext.getEnvironment());
}

View File

@@ -39,8 +39,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Artsiom Yudovin
*/
@RunWith(SpringRunner.class)
@ContextConfiguration(
initializers = DataNeo4jTestPropertiesIntegrationTests.Initializer.class)
@ContextConfiguration(initializers = DataNeo4jTestPropertiesIntegrationTests.Initializer.class)
@DataNeo4jTest(properties = "spring.profiles.active=test")
public class DataNeo4jTestPropertiesIntegrationTests {
@@ -56,14 +55,11 @@ public class DataNeo4jTestPropertiesIntegrationTests {
assertThat(this.environment.getActiveProfiles()).containsExactly("test");
}
static class Initializer
implements ApplicationContextInitializer<ConfigurableApplicationContext> {
static class Initializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
@Override
public void initialize(
ConfigurableApplicationContext configurableApplicationContext) {
TestPropertyValues
.of("spring.data.neo4j.uri=" + neo4j.getContainer().getBoltUrl())
public void initialize(ConfigurableApplicationContext configurableApplicationContext) {
TestPropertyValues.of("spring.data.neo4j.uri=" + neo4j.getContainer().getBoltUrl())
.applyTo(configurableApplicationContext.getEnvironment());
}

View File

@@ -40,8 +40,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Michael Simons
*/
@RunWith(SpringRunner.class)
@ContextConfiguration(
initializers = DataNeo4jTestWithIncludeFilterIntegrationTests.Initializer.class)
@ContextConfiguration(initializers = DataNeo4jTestWithIncludeFilterIntegrationTests.Initializer.class)
@DataNeo4jTest(includeFilters = @Filter(Service.class))
public class DataNeo4jTestWithIncludeFilterIntegrationTests {
@@ -57,14 +56,11 @@ public class DataNeo4jTestWithIncludeFilterIntegrationTests {
assertThat(this.service.hasNode(ExampleGraph.class)).isFalse();
}
static class Initializer
implements ApplicationContextInitializer<ConfigurableApplicationContext> {
static class Initializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
@Override
public void initialize(
ConfigurableApplicationContext configurableApplicationContext) {
TestPropertyValues
.of("spring.data.neo4j.uri=" + neo4j.getContainer().getBoltUrl())
public void initialize(ConfigurableApplicationContext configurableApplicationContext) {
TestPropertyValues.of("spring.data.neo4j.uri=" + neo4j.getContainer().getBoltUrl())
.applyTo(configurableApplicationContext.getEnvironment());
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -80,12 +80,10 @@ public class DataRedisTestIntegrationTests {
.isThrownBy(() -> this.applicationContext.getBean(ExampleService.class));
}
static class Initializer
implements ApplicationContextInitializer<ConfigurableApplicationContext> {
static class Initializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
@Override
public void initialize(
ConfigurableApplicationContext configurableApplicationContext) {
public void initialize(ConfigurableApplicationContext configurableApplicationContext) {
TestPropertyValues.of("spring.redis.port=" + redis.getMappedPort())
.applyTo(configurableApplicationContext.getEnvironment());
}

View File

@@ -38,8 +38,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Artsiom Yudovin
*/
@RunWith(SpringRunner.class)
@ContextConfiguration(
initializers = DataRedisTestPropertiesIntegrationTests.Initializer.class)
@ContextConfiguration(initializers = DataRedisTestPropertiesIntegrationTests.Initializer.class)
@DataRedisTest(properties = "spring.profiles.active=test")
public class DataRedisTestPropertiesIntegrationTests {
@@ -54,12 +53,10 @@ public class DataRedisTestPropertiesIntegrationTests {
assertThat(this.environment.getActiveProfiles()).containsExactly("test");
}
static class Initializer
implements ApplicationContextInitializer<ConfigurableApplicationContext> {
static class Initializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
@Override
public void initialize(
ConfigurableApplicationContext configurableApplicationContext) {
public void initialize(ConfigurableApplicationContext configurableApplicationContext) {
TestPropertyValues.of("spring.redis.port=" + redis.getMappedPort())
.applyTo(configurableApplicationContext.getEnvironment());
}

View File

@@ -38,8 +38,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Jayaram Pradhan
*/
@RunWith(SpringRunner.class)
@ContextConfiguration(
initializers = DataRedisTestWithIncludeFilterIntegrationTests.Initializer.class)
@ContextConfiguration(initializers = DataRedisTestWithIncludeFilterIntegrationTests.Initializer.class)
@DataRedisTest(includeFilters = @Filter(Service.class))
public class DataRedisTestWithIncludeFilterIntegrationTests {
@@ -61,12 +60,10 @@ public class DataRedisTestWithIncludeFilterIntegrationTests {
assertThat(this.service.hasRecord(savedEntity)).isTrue();
}
static class Initializer
implements ApplicationContextInitializer<ConfigurableApplicationContext> {
static class Initializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
@Override
public void initialize(
ConfigurableApplicationContext configurableApplicationContext) {
public void initialize(ConfigurableApplicationContext configurableApplicationContext) {
TestPropertyValues.of("spring.redis.port=" + redis.getMappedPort())
.applyTo(configurableApplicationContext.getEnvironment());
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -40,8 +40,8 @@ public class ExampleService {
}
public boolean hasRecord(PersonHash personHash) {
return this.operations.execute((RedisConnection connection) -> connection
.exists(("persons:" + personHash.getId()).getBytes(CHARSET)));
return this.operations.execute(
(RedisConnection connection) -> connection.exists(("persons:" + personHash.getId()).getBytes(CHARSET)));
}
}

View File

@@ -83,11 +83,9 @@ public class FilterAnnotationsTests {
return new FilterAnnotations(getClass().getClassLoader(), filters.value());
}
private boolean match(FilterAnnotations filterAnnotations, Class<?> type)
throws IOException {
private boolean match(FilterAnnotations filterAnnotations, Class<?> type) throws IOException {
MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
MetadataReader metadataReader = metadataReaderFactory
.getMetadataReader(type.getName());
MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(type.getName());
return filterAnnotations.anyMatches(metadataReader, metadataReaderFactory);
}
@@ -96,8 +94,7 @@ public class FilterAnnotationsTests {
}
@Filters(@Filter(type = FilterType.ASSIGNABLE_TYPE,
classes = ExampleWithoutAnnotation.class))
@Filters(@Filter(type = FilterType.ASSIGNABLE_TYPE, classes = ExampleWithoutAnnotation.class))
static class FilterByType {
}
@@ -107,8 +104,7 @@ public class FilterAnnotationsTests {
}
@Filters(@Filter(type = FilterType.ASPECTJ,
pattern = "(*..*ExampleWithoutAnnotation)"))
@Filters(@Filter(type = FilterType.ASPECTJ, pattern = "(*..*ExampleWithoutAnnotation)"))
static class FilterByAspectJ {
}
@@ -130,10 +126,8 @@ public class FilterAnnotationsTests {
static class ExampleCustomFilter implements TypeFilter {
@Override
public boolean match(MetadataReader metadataReader,
MetadataReaderFactory metadataReaderFactory) {
return metadataReader.getClassMetadata().getClassName()
.equals(ExampleWithoutAnnotation.class.getName());
public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory) {
return metadataReader.getClassMetadata().getClassName().equals(ExampleWithoutAnnotation.class.getName());
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -39,54 +39,43 @@ public class TypeExcludeFiltersContextCustomizerFactoryTests {
private TypeExcludeFiltersContextCustomizerFactory factory = new TypeExcludeFiltersContextCustomizerFactory();
private MergedContextConfiguration mergedContextConfiguration = mock(
MergedContextConfiguration.class);
private MergedContextConfiguration mergedContextConfiguration = mock(MergedContextConfiguration.class);
private ConfigurableApplicationContext context = new AnnotationConfigApplicationContext();
@Test
public void getContextCustomizerWhenHasNoAnnotationShouldReturnNull() {
ContextCustomizer customizer = this.factory
.createContextCustomizer(NoAnnotation.class, null);
ContextCustomizer customizer = this.factory.createContextCustomizer(NoAnnotation.class, null);
assertThat(customizer).isNull();
}
@Test
public void getContextCustomizerWhenHasAnnotationShouldReturnCustomizer() {
ContextCustomizer customizer = this.factory
.createContextCustomizer(WithExcludeFilters.class, null);
ContextCustomizer customizer = this.factory.createContextCustomizer(WithExcludeFilters.class, null);
assertThat(customizer).isNotNull();
}
@Test
public void hashCodeAndEquals() {
ContextCustomizer customizer1 = this.factory
.createContextCustomizer(WithExcludeFilters.class, null);
ContextCustomizer customizer2 = this.factory
.createContextCustomizer(WithSameExcludeFilters.class, null);
ContextCustomizer customizer3 = this.factory
.createContextCustomizer(WithDifferentExcludeFilters.class, null);
ContextCustomizer customizer1 = this.factory.createContextCustomizer(WithExcludeFilters.class, null);
ContextCustomizer customizer2 = this.factory.createContextCustomizer(WithSameExcludeFilters.class, null);
ContextCustomizer customizer3 = this.factory.createContextCustomizer(WithDifferentExcludeFilters.class, null);
assertThat(customizer1.hashCode()).isEqualTo(customizer2.hashCode());
assertThat(customizer1).isEqualTo(customizer1).isEqualTo(customizer2)
.isNotEqualTo(customizer3);
assertThat(customizer1).isEqualTo(customizer1).isEqualTo(customizer2).isNotEqualTo(customizer3);
}
@Test
public void getContextCustomizerShouldAddExcludeFilters() throws Exception {
ContextCustomizer customizer = this.factory
.createContextCustomizer(WithExcludeFilters.class, null);
ContextCustomizer customizer = this.factory.createContextCustomizer(WithExcludeFilters.class, null);
customizer.customizeContext(this.context, this.mergedContextConfiguration);
this.context.refresh();
TypeExcludeFilter filter = this.context.getBean(TypeExcludeFilter.class);
MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
MetadataReader metadataReader = metadataReaderFactory
.getMetadataReader(NoAnnotation.class.getName());
MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(NoAnnotation.class.getName());
assertThat(filter.match(metadataReader, metadataReaderFactory)).isFalse();
metadataReader = metadataReaderFactory
.getMetadataReader(SimpleExclude.class.getName());
metadataReader = metadataReaderFactory.getMetadataReader(SimpleExclude.class.getName());
assertThat(filter.match(metadataReader, metadataReaderFactory)).isTrue();
metadataReader = metadataReaderFactory
.getMetadataReader(TestClassAwareExclude.class.getName());
metadataReader = metadataReaderFactory.getMetadataReader(TestClassAwareExclude.class.getName());
assertThat(filter.match(metadataReader, metadataReaderFactory)).isTrue();
}
@@ -112,10 +101,8 @@ public class TypeExcludeFiltersContextCustomizerFactoryTests {
static class SimpleExclude extends TypeExcludeFilter {
@Override
public boolean match(MetadataReader metadataReader,
MetadataReaderFactory metadataReaderFactory) {
return metadataReader.getClassMetadata().getClassName()
.equals(getClass().getName());
public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory) {
return metadataReader.getClassMetadata().getClassName().equals(getClass().getName());
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -49,8 +49,7 @@ public class AutoConfigureTestDatabaseWithMultipleDatasourcesIntegrationTests {
@Test
public void replacesDefinedDataSourceWithExplicit() throws Exception {
// Look that the datasource is replaced with an H2 DB.
String product = this.dataSource.getConnection().getMetaData()
.getDatabaseProductName();
String product = this.dataSource.getConnection().getMetaData().getDatabaseProductName();
assertThat(product).startsWith("H2");
}
@@ -61,14 +60,12 @@ public class AutoConfigureTestDatabaseWithMultipleDatasourcesIntegrationTests {
@Bean
@Primary
public DataSource dataSource() {
return new EmbeddedDatabaseBuilder().generateUniqueName(true)
.setType(EmbeddedDatabaseType.HSQL).build();
return new EmbeddedDatabaseBuilder().generateUniqueName(true).setType(EmbeddedDatabaseType.HSQL).build();
}
@Bean
public DataSource secondaryDataSource() {
return new EmbeddedDatabaseBuilder().generateUniqueName(true)
.setType(EmbeddedDatabaseType.HSQL).build();
return new EmbeddedDatabaseBuilder().generateUniqueName(true).setType(EmbeddedDatabaseType.HSQL).build();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -33,8 +33,7 @@ public class ExampleJdbcApplication {
@Bean
public DataSource dataSource() {
return new EmbeddedDatabaseBuilder().generateUniqueName(true)
.setType(EmbeddedDatabaseType.HSQL).build();
return new EmbeddedDatabaseBuilder().generateUniqueName(true).setType(EmbeddedDatabaseType.HSQL).build();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -44,13 +44,11 @@ public class ExampleRepository {
@Transactional
public void save(ExampleEntity entity) {
this.jdbcTemplate.update("insert into example (id, name) values (?, ?)",
entity.getId(), entity.getName());
this.jdbcTemplate.update("insert into example (id, name) values (?, ?)", entity.getId(), entity.getName());
}
public ExampleEntity findById(int id) {
return this.jdbcTemplate.queryForObject(
"select id, name from example where id =?", new Object[] { id },
return this.jdbcTemplate.queryForObject("select id, name from example where id =?", new Object[] { id },
ROW_MAPPER);
}

View File

@@ -69,27 +69,24 @@ public class JdbcTestIntegrationTests {
@Test
public void replacesDefinedDataSourceWithEmbeddedDefault() throws Exception {
String product = this.dataSource.getConnection().getMetaData()
.getDatabaseProductName();
String product = this.dataSource.getConnection().getMetaData().getDatabaseProductName();
assertThat(product).isEqualTo("H2");
}
@Test
public void didNotInjectExampleRepository() {
assertThatExceptionOfType(NoSuchBeanDefinitionException.class).isThrownBy(
() -> this.applicationContext.getBean(ExampleRepository.class));
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
.isThrownBy(() -> this.applicationContext.getBean(ExampleRepository.class));
}
@Test
public void flywayAutoConfigurationWasImported() {
assertThat(this.applicationContext)
.has(importedAutoConfiguration(FlywayAutoConfiguration.class));
assertThat(this.applicationContext).has(importedAutoConfiguration(FlywayAutoConfiguration.class));
}
@Test
public void liquibaseAutoConfigurationWasImported() {
assertThat(this.applicationContext)
.has(importedAutoConfiguration(LiquibaseAutoConfiguration.class));
assertThat(this.applicationContext).has(importedAutoConfiguration(LiquibaseAutoConfiguration.class));
}
}

View File

@@ -46,8 +46,7 @@ public class JdbcTestWithAutoConfigureTestDatabaseReplaceAutoConfiguredIntegrati
@Test
public void replacesAutoConfiguredDataSource() throws Exception {
String product = this.dataSource.getConnection().getMetaData()
.getDatabaseProductName();
String product = this.dataSource.getConnection().getMetaData().getDatabaseProductName();
assertThat(product).startsWith("HSQL");
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -42,8 +42,7 @@ public class JdbcTestWithAutoConfigureTestDatabaseReplaceAutoConfiguredWithoutOv
@Test
public void usesDefaultEmbeddedDatabase() throws Exception {
String product = this.dataSource.getConnection().getMetaData()
.getDatabaseProductName();
String product = this.dataSource.getConnection().getMetaData().getDatabaseProductName();
// @AutoConfigureTestDatabase would use H2 but HSQL is manually defined
assertThat(product).startsWith("HSQL");
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -49,8 +49,7 @@ public class JdbcTestWithAutoConfigureTestDatabaseReplaceExplicitIntegrationTest
@Test
public void replacesDefinedDataSourceWithExplicit() throws Exception {
// H2 is explicitly defined but HSQL is the override.
String product = this.dataSource.getConnection().getMetaData()
.getDatabaseProductName();
String product = this.dataSource.getConnection().getMetaData().getDatabaseProductName();
assertThat(product).startsWith("HSQL");
}
@@ -60,8 +59,7 @@ public class JdbcTestWithAutoConfigureTestDatabaseReplaceExplicitIntegrationTest
@Bean
public DataSource dataSource() {
return new EmbeddedDatabaseBuilder().generateUniqueName(true)
.setType(EmbeddedDatabaseType.H2).build();
return new EmbeddedDatabaseBuilder().generateUniqueName(true).setType(EmbeddedDatabaseType.H2).build();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -43,8 +43,7 @@ public class JdbcTestWithAutoConfigureTestDatabaseReplaceNoneIntegrationTests {
@Test
public void usesDefaultEmbeddedDatabase() throws Exception {
// HSQL is explicitly defined and should not be replaced
String product = this.dataSource.getConnection().getMetaData()
.getDatabaseProductName();
String product = this.dataSource.getConnection().getMetaData().getDatabaseProductName();
assertThat(product).startsWith("HSQL");
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -51,8 +51,7 @@ public class JdbcTestWithAutoConfigureTestDatabaseReplacePropertyAnyIntegrationT
@Test
public void replacesDefinedDataSourceWithExplicit() throws Exception {
// H2 is explicitly defined but HSQL is the override.
String product = this.dataSource.getConnection().getMetaData()
.getDatabaseProductName();
String product = this.dataSource.getConnection().getMetaData().getDatabaseProductName();
assertThat(product).startsWith("HSQL");
}
@@ -62,8 +61,7 @@ public class JdbcTestWithAutoConfigureTestDatabaseReplacePropertyAnyIntegrationT
@Bean
public DataSource dataSource() {
return new EmbeddedDatabaseBuilder().generateUniqueName(true)
.setType(EmbeddedDatabaseType.H2).build();
return new EmbeddedDatabaseBuilder().generateUniqueName(true).setType(EmbeddedDatabaseType.H2).build();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -47,8 +47,7 @@ public class JdbcTestWithAutoConfigureTestDatabaseReplacePropertyAutoConfiguredI
@Test
public void replacesAutoConfiguredDataSource() throws Exception {
String product = this.dataSource.getConnection().getMetaData()
.getDatabaseProductName();
String product = this.dataSource.getConnection().getMetaData().getDatabaseProductName();
assertThat(product).startsWith("HSQL");
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -44,8 +44,7 @@ public class JdbcTestWithAutoConfigureTestDatabaseReplacePropertyNoneIntegration
@Test
public void usesDefaultEmbeddedDatabase() throws Exception {
// HSQL is explicitly defined and should not be replaced
String product = this.dataSource.getConnection().getMetaData()
.getDatabaseProductName();
String product = this.dataSource.getConnection().getMetaData().getDatabaseProductName();
assertThat(product).startsWith("HSQL");
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -39,33 +39,25 @@ import static org.assertj.core.api.Assertions.assertThat;
public class TestDatabaseAutoConfigurationTests {
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(
AutoConfigurations.of(TestDatabaseAutoConfiguration.class));
.withConfiguration(AutoConfigurations.of(TestDatabaseAutoConfiguration.class));
@Test
public void replaceWithNoDataSourceAvailable() {
this.contextRunner
.run((context) -> assertThat(context).doesNotHaveBean(DataSource.class));
this.contextRunner.run((context) -> assertThat(context).doesNotHaveBean(DataSource.class));
}
@Test
public void replaceWithUniqueDatabase() {
this.contextRunner.withUserConfiguration(ExistingDataSourceConfiguration.class)
.run((context) -> {
DataSource datasource = context.getBean(DataSource.class);
JdbcTemplate jdbcTemplate = new JdbcTemplate(datasource);
jdbcTemplate.execute("create table example (id int, name varchar);");
this.contextRunner
.withUserConfiguration(ExistingDataSourceConfiguration.class)
.run((secondContext) -> {
DataSource anotherDatasource = secondContext
.getBean(DataSource.class);
JdbcTemplate anotherJdbcTemplate = new JdbcTemplate(
anotherDatasource);
anotherJdbcTemplate.execute(
"create table example (id int, name varchar);");
});
});
this.contextRunner.withUserConfiguration(ExistingDataSourceConfiguration.class).run((context) -> {
DataSource datasource = context.getBean(DataSource.class);
JdbcTemplate jdbcTemplate = new JdbcTemplate(datasource);
jdbcTemplate.execute("create table example (id int, name varchar);");
this.contextRunner.withUserConfiguration(ExistingDataSourceConfiguration.class).run((secondContext) -> {
DataSource anotherDatasource = secondContext.getBean(DataSource.class);
JdbcTemplate anotherJdbcTemplate = new JdbcTemplate(anotherDatasource);
anotherJdbcTemplate.execute("create table example (id int, name varchar);");
});
});
}
@Configuration
@@ -73,8 +65,7 @@ public class TestDatabaseAutoConfigurationTests {
@Bean
public DataSource dataSource() {
return new EmbeddedDatabaseBuilder().generateUniqueName(true)
.setType(EmbeddedDatabaseType.HSQL).build();
return new EmbeddedDatabaseBuilder().generateUniqueName(true).setType(EmbeddedDatabaseType.HSQL).build();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -33,8 +33,7 @@ public class ExampleJooqApplication {
@Bean
public DataSource dataSource() {
return new EmbeddedDatabaseBuilder().generateUniqueName(true)
.setType(EmbeddedDatabaseType.HSQL).build();
return new EmbeddedDatabaseBuilder().generateUniqueName(true).setType(EmbeddedDatabaseType.HSQL).build();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -55,34 +55,31 @@ public class JooqTestIntegrationTests {
@Test
public void testDSLContext() {
assertThat(this.dsl.selectCount().from("INFORMATION_SCHEMA.TABLES").fetchOne(0,
Integer.class)).isGreaterThan(0);
assertThat(this.dsl.selectCount().from("INFORMATION_SCHEMA.TABLES").fetchOne(0, Integer.class))
.isGreaterThan(0);
}
@Test
public void useDefinedDataSource() throws Exception {
String product = this.dataSource.getConnection().getMetaData()
.getDatabaseProductName();
String product = this.dataSource.getConnection().getMetaData().getDatabaseProductName();
assertThat(product).startsWith("HSQL");
assertThat(this.dsl.configuration().dialect()).isEqualTo(SQLDialect.HSQLDB);
}
@Test
public void didNotInjectExampleComponent() {
assertThatExceptionOfType(NoSuchBeanDefinitionException.class).isThrownBy(
() -> this.applicationContext.getBean(ExampleComponent.class));
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
.isThrownBy(() -> this.applicationContext.getBean(ExampleComponent.class));
}
@Test
public void flywayAutoConfigurationWasImported() {
assertThat(this.applicationContext)
.has(importedAutoConfiguration(FlywayAutoConfiguration.class));
assertThat(this.applicationContext).has(importedAutoConfiguration(FlywayAutoConfiguration.class));
}
@Test
public void liquibaseAutoConfigurationWasImported() {
assertThat(this.applicationContext)
.has(importedAutoConfiguration(LiquibaseAutoConfiguration.class));
assertThat(this.applicationContext).has(importedAutoConfiguration(LiquibaseAutoConfiguration.class));
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -48,8 +48,7 @@ public class JooqTestWithAutoConfigureTestDatabaseIntegrationTests {
@Test
public void replacesAutoConfiguredDataSource() throws Exception {
String product = this.dataSource.getConnection().getMetaData()
.getDatabaseProductName();
String product = this.dataSource.getConnection().getMetaData().getDatabaseProductName();
assertThat(product).startsWith("H2");
assertThat(this.dsl.configuration().dialect()).isEqualTo(SQLDialect.H2);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -41,8 +41,8 @@ public class ExampleJsonComponent {
public static class Serializer extends JsonObjectSerializer<ExampleCustomObject> {
@Override
protected void serializeObject(ExampleCustomObject value, JsonGenerator jgen,
SerializerProvider provider) throws IOException {
protected void serializeObject(ExampleCustomObject value, JsonGenerator jgen, SerializerProvider provider)
throws IOException {
jgen.writeStringField("value", value.toString());
}
@@ -51,11 +51,9 @@ public class ExampleJsonComponent {
public static class Deserializer extends JsonObjectDeserializer<ExampleCustomObject> {
@Override
protected ExampleCustomObject deserializeObject(JsonParser jsonParser,
DeserializationContext context, ObjectCodec codec, JsonNode tree)
throws IOException {
return new ExampleCustomObject(
nullSafeValue(tree.get("value"), String.class));
protected ExampleCustomObject deserializeObject(JsonParser jsonParser, DeserializationContext context,
ObjectCodec codec, JsonNode tree) throws IOException {
return new ExampleCustomObject(nullSafeValue(tree.get("value"), String.class));
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -54,8 +54,7 @@ public class ExampleJsonObjectWithView {
return false;
}
ExampleJsonObjectWithView other = (ExampleJsonObjectWithView) obj;
return ObjectUtils.nullSafeEquals(this.value, other.value)
&& ObjectUtils.nullSafeEquals(this.id, other.id);
return ObjectUtils.nullSafeEquals(this.value, other.value) && ObjectUtils.nullSafeEquals(this.id, other.id);
}
@Override

View File

@@ -42,8 +42,7 @@ import static org.springframework.boot.test.autoconfigure.AutoConfigurationImpor
*/
@RunWith(SpringRunner.class)
@DataJpaTest
@TestPropertySource(
properties = "spring.jpa.hibernate.use-new-id-generator-mappings=false")
@TestPropertySource(properties = "spring.jpa.hibernate.use-new-id-generator-mappings=false")
public class DataJpaTestIntegrationTests {
@Autowired
@@ -72,12 +71,10 @@ public class DataJpaTestIntegrationTests {
@Test
public void testEntityManagerPersistAndGetId() {
Long id = this.entities.persistAndGetId(new ExampleEntity("spring", "123"),
Long.class);
Long id = this.entities.persistAndGetId(new ExampleEntity("spring", "123"), Long.class);
assertThat(id).isNotNull();
String reference = this.jdbcTemplate.queryForObject(
"SELECT REFERENCE FROM EXAMPLE_ENTITY WHERE ID = ?", new Object[] { id },
String.class);
String reference = this.jdbcTemplate.queryForObject("SELECT REFERENCE FROM EXAMPLE_ENTITY WHERE ID = ?",
new Object[] { id }, String.class);
assertThat(reference).isEqualTo("123");
}
@@ -92,27 +89,24 @@ public class DataJpaTestIntegrationTests {
@Test
public void replacesDefinedDataSourceWithEmbeddedDefault() throws Exception {
String product = this.dataSource.getConnection().getMetaData()
.getDatabaseProductName();
String product = this.dataSource.getConnection().getMetaData().getDatabaseProductName();
assertThat(product).isEqualTo("H2");
}
@Test
public void didNotInjectExampleComponent() {
assertThatExceptionOfType(NoSuchBeanDefinitionException.class).isThrownBy(
() -> this.applicationContext.getBean(ExampleComponent.class));
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
.isThrownBy(() -> this.applicationContext.getBean(ExampleComponent.class));
}
@Test
public void flywayAutoConfigurationWasImported() {
assertThat(this.applicationContext)
.has(importedAutoConfiguration(FlywayAutoConfiguration.class));
assertThat(this.applicationContext).has(importedAutoConfiguration(FlywayAutoConfiguration.class));
}
@Test
public void liquibaseAutoConfigurationWasImported() {
assertThat(this.applicationContext)
.has(importedAutoConfiguration(LiquibaseAutoConfiguration.class));
assertThat(this.applicationContext).has(importedAutoConfiguration(LiquibaseAutoConfiguration.class));
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -33,8 +33,7 @@ public class ExampleDataJpaApplication {
@Bean
public DataSource dataSource() {
return new EmbeddedDatabaseBuilder().generateUniqueName(true)
.setType(EmbeddedDatabaseType.HSQL).build();
return new EmbeddedDatabaseBuilder().generateUniqueName(true).setType(EmbeddedDatabaseType.HSQL).build();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -46,29 +46,22 @@ public class TestDatabaseAutoConfigurationNoEmbeddedTests {
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withUserConfiguration(ExistingDataSourceConfiguration.class)
.withConfiguration(
AutoConfigurations.of(TestDatabaseAutoConfiguration.class));
.withConfiguration(AutoConfigurations.of(TestDatabaseAutoConfiguration.class));
@Test
public void applyAnyReplace() {
this.contextRunner.run((context) -> assertThat(context).getFailure()
.isInstanceOf(BeanCreationException.class)
.hasMessageContaining(
"Failed to replace DataSource with an embedded database for tests.")
.hasMessageContaining(
"If you want an embedded database please put a supported one on the classpath")
.hasMessageContaining(
"or tune the replace attribute of @AutoConfigureTestDatabase."));
this.contextRunner.run((context) -> assertThat(context).getFailure().isInstanceOf(BeanCreationException.class)
.hasMessageContaining("Failed to replace DataSource with an embedded database for tests.")
.hasMessageContaining("If you want an embedded database please put a supported one on the classpath")
.hasMessageContaining("or tune the replace attribute of @AutoConfigureTestDatabase."));
}
@Test
public void applyNoReplace() {
this.contextRunner.withPropertyValues("spring.test.database.replace=NONE")
.run((context) -> {
assertThat(context).hasSingleBean(DataSource.class);
assertThat(context).getBean(DataSource.class)
.isSameAs(context.getBean("myCustomDataSource"));
});
this.contextRunner.withPropertyValues("spring.test.database.replace=NONE").run((context) -> {
assertThat(context).hasSingleBean(DataSource.class);
assertThat(context).getBean(DataSource.class).isSameAs(context.getBean("myCustomDataSource"));
});
}
@Configuration

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -56,8 +56,7 @@ public class TestEntityManagerTests {
public void setup() {
MockitoAnnotations.initMocks(this);
this.testEntityManager = new TestEntityManager(this.entityManagerFactory);
given(this.entityManagerFactory.getPersistenceUnitUtil())
.willReturn(this.persistenceUnitUtil);
given(this.entityManagerFactory.getPersistenceUnitUtil()).willReturn(this.persistenceUnitUtil);
}
@Test
@@ -187,8 +186,7 @@ public class TestEntityManagerTests {
public void getIdForTypeWhenTypeIsWrongShouldThrowException() {
TestEntity entity = new TestEntity();
given(this.persistenceUnitUtil.getIdentifier(entity)).willReturn(123);
assertThatIllegalArgumentException()
.isThrownBy(() -> this.testEntityManager.getId(entity, Long.class))
assertThatIllegalArgumentException().isThrownBy(() -> this.testEntityManager.getId(entity, Long.class))
.withMessageContaining("ID mismatch: Object of class [java.lang.Integer] "
+ "must be an instance of class java.lang.Long");
}
@@ -204,14 +202,12 @@ public class TestEntityManagerTests {
@Test
public void getEntityManagerShouldGetEntityManager() {
bindEntityManager();
assertThat(this.testEntityManager.getEntityManager())
.isEqualTo(this.entityManager);
assertThat(this.testEntityManager.getEntityManager()).isEqualTo(this.entityManager);
}
@Test
public void getEntityManagerWhenNotSetShouldThrowException() {
assertThatIllegalStateException()
.isThrownBy(this.testEntityManager::getEntityManager)
assertThatIllegalStateException().isThrownBy(this.testEntityManager::getEntityManager)
.withMessageContaining("No transactional EntityManager found");
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -52,8 +52,8 @@ public class OverrideAutoConfigurationEnabledFalseIntegrationTests {
public void disabledAutoConfiguration() {
ApplicationContext context = this.context;
assertThat(context.getBean(ExampleTestConfig.class)).isNotNull();
assertThatExceptionOfType(NoSuchBeanDefinitionException.class).isThrownBy(
() -> context.getBean(ConfigurationPropertiesBindingPostProcessor.class));
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
.isThrownBy(() -> context.getBean(ConfigurationPropertiesBindingPostProcessor.class));
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -49,10 +49,8 @@ public class OverrideAutoConfigurationEnabledTrueIntegrationTests {
@Test
public void autoConfiguredContext() {
ApplicationContext context = this.context;
assertThat(context.getBean(OverrideAutoConfigurationSpringBootApplication.class))
.isNotNull();
assertThat(context.getBean(ConfigurationPropertiesBindingPostProcessor.class))
.isNotNull();
assertThat(context.getBean(OverrideAutoConfigurationSpringBootApplication.class)).isNotNull();
assertThat(context.getBean(ConfigurationPropertiesBindingPostProcessor.class)).isNotNull();
}
}

View File

@@ -36,15 +36,13 @@ public class AnnotationsPropertySourceTests {
@Test
public void createWhenSourceIsNullShouldThrowException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new AnnotationsPropertySource(null))
assertThatIllegalArgumentException().isThrownBy(() -> new AnnotationsPropertySource(null))
.withMessageContaining("Property source must not be null");
}
@Test
public void propertiesWhenHasNoAnnotationShouldBeEmpty() {
AnnotationsPropertySource source = new AnnotationsPropertySource(
NoAnnotation.class);
AnnotationsPropertySource source = new AnnotationsPropertySource(NoAnnotation.class);
assertThat(source.getPropertyNames()).isEmpty();
assertThat(source.getProperty("value")).isNull();
}
@@ -58,40 +56,35 @@ public class AnnotationsPropertySourceTests {
@Test
public void propertiesWhenHasTypeLevelWithPrefixShouldUsePrefixedName() {
AnnotationsPropertySource source = new AnnotationsPropertySource(
TypeLevelWithPrefix.class);
AnnotationsPropertySource source = new AnnotationsPropertySource(TypeLevelWithPrefix.class);
assertThat(source.getPropertyNames()).containsExactly("test.value");
assertThat(source.getProperty("test.value")).isEqualTo("abc");
}
@Test
public void propertiesWhenHasAttributeLevelWithPrefixShouldUsePrefixedName() {
AnnotationsPropertySource source = new AnnotationsPropertySource(
AttributeLevelWithPrefix.class);
AnnotationsPropertySource source = new AnnotationsPropertySource(AttributeLevelWithPrefix.class);
assertThat(source.getPropertyNames()).containsExactly("test");
assertThat(source.getProperty("test")).isEqualTo("abc");
}
@Test
public void propertiesWhenHasTypeAndAttributeLevelWithPrefixShouldUsePrefixedName() {
AnnotationsPropertySource source = new AnnotationsPropertySource(
TypeAndAttributeLevelWithPrefix.class);
AnnotationsPropertySource source = new AnnotationsPropertySource(TypeAndAttributeLevelWithPrefix.class);
assertThat(source.getPropertyNames()).containsExactly("test.example");
assertThat(source.getProperty("test.example")).isEqualTo("abc");
}
@Test
public void propertiesWhenNotMappedAtTypeLevelShouldIgnoreAttributes() {
AnnotationsPropertySource source = new AnnotationsPropertySource(
NotMappedAtTypeLevel.class);
AnnotationsPropertySource source = new AnnotationsPropertySource(NotMappedAtTypeLevel.class);
assertThat(source.getPropertyNames()).containsExactly("value");
assertThat(source.getProperty("ignore")).isNull();
}
@Test
public void propertiesWhenNotMappedAtAttributeLevelShouldIgnoreAttributes() {
AnnotationsPropertySource source = new AnnotationsPropertySource(
NotMappedAtAttributeLevel.class);
AnnotationsPropertySource source = new AnnotationsPropertySource(NotMappedAtAttributeLevel.class);
assertThat(source.getPropertyNames()).containsExactly("value");
assertThat(source.getProperty("ignore")).isNull();
}
@@ -99,10 +92,9 @@ public class AnnotationsPropertySourceTests {
@Test
public void propertiesWhenContainsArraysShouldExpandNames() {
AnnotationsPropertySource source = new AnnotationsPropertySource(Arrays.class);
assertThat(source.getPropertyNames()).contains("strings[0]", "strings[1]",
"classes[0]", "classes[1]", "ints[0]", "ints[1]", "longs[0]", "longs[1]",
"floats[0]", "floats[1]", "doubles[0]", "doubles[1]", "booleans[0]",
"booleans[1]");
assertThat(source.getPropertyNames()).contains("strings[0]", "strings[1]", "classes[0]", "classes[1]",
"ints[0]", "ints[1]", "longs[0]", "longs[1]", "floats[0]", "floats[1]", "doubles[0]", "doubles[1]",
"booleans[0]", "booleans[1]");
assertThat(source.getProperty("strings[0]")).isEqualTo("a");
assertThat(source.getProperty("strings[1]")).isEqualTo("b");
assertThat(source.getProperty("classes[0]")).isEqualTo(Integer.class);
@@ -121,25 +113,21 @@ public class AnnotationsPropertySourceTests {
@Test
public void propertiesWhenHasCamelCaseShouldConvertToKebabCase() {
AnnotationsPropertySource source = new AnnotationsPropertySource(
CamelCaseToKebabCase.class);
AnnotationsPropertySource source = new AnnotationsPropertySource(CamelCaseToKebabCase.class);
assertThat(source.getPropertyNames()).contains("camel-case-to-kebab-case");
}
@Test
public void propertiesFromMetaAnnotationsAreMapped() {
AnnotationsPropertySource source = new AnnotationsPropertySource(
PropertiesFromSingleMetaAnnotation.class);
AnnotationsPropertySource source = new AnnotationsPropertySource(PropertiesFromSingleMetaAnnotation.class);
assertThat(source.getPropertyNames()).containsExactly("value");
assertThat(source.getProperty("value")).isEqualTo("foo");
}
@Test
public void propertiesFromMultipleMetaAnnotationsAreMappedUsingTheirOwnPropertyMapping() {
AnnotationsPropertySource source = new AnnotationsPropertySource(
PropertiesFromMultipleMetaAnnotations.class);
assertThat(source.getPropertyNames()).containsExactly("value", "test.value",
"test.example");
AnnotationsPropertySource source = new AnnotationsPropertySource(PropertiesFromMultipleMetaAnnotations.class);
assertThat(source.getPropertyNames()).containsExactly("value", "test.value", "test.example");
assertThat(source.getProperty("value")).isEqualTo("alpha");
assertThat(source.getProperty("test.value")).isEqualTo("bravo");
assertThat(source.getProperty("test.example")).isEqualTo("charlie");
@@ -147,8 +135,7 @@ public class AnnotationsPropertySourceTests {
@Test
public void propertyMappedAttributesCanBeAliased() {
AnnotationsPropertySource source = new AnnotationsPropertySource(
PropertyMappedAttributeWithAnAlias.class);
AnnotationsPropertySource source = new AnnotationsPropertySource(PropertyMappedAttributeWithAnAlias.class);
assertThat(source.getPropertyNames()).containsExactly("aliasing.value");
assertThat(source.getProperty("aliasing.value")).isEqualTo("baz");
}
@@ -160,8 +147,7 @@ public class AnnotationsPropertySourceTests {
@Test
public void typeLevelAnnotationOnSuperClass() {
AnnotationsPropertySource source = new AnnotationsPropertySource(
PropertyMappedAnnotationOnSuperClass.class);
AnnotationsPropertySource source = new AnnotationsPropertySource(PropertyMappedAnnotationOnSuperClass.class);
assertThat(source.getPropertyNames()).containsExactly("value");
assertThat(source.getProperty("value")).isEqualTo("abc");
}
@@ -176,15 +162,13 @@ public class AnnotationsPropertySourceTests {
@Test
public void enumValueMapped() {
AnnotationsPropertySource source = new AnnotationsPropertySource(
EnumValueMapped.class);
AnnotationsPropertySource source = new AnnotationsPropertySource(EnumValueMapped.class);
assertThat(source.getProperty("testenum.value")).isEqualTo(EnumItem.TWO);
}
@Test
public void enumValueNotMapped() {
AnnotationsPropertySource source = new AnnotationsPropertySource(
EnumValueNotMapped.class);
AnnotationsPropertySource source = new AnnotationsPropertySource(EnumValueNotMapped.class);
assertThat(source.containsProperty("testenum.value")).isFalse();
}
@@ -277,9 +261,8 @@ public class AnnotationsPropertySourceTests {
}
@ArraysAnnotation(strings = { "a", "b" }, classes = { Integer.class, Long.class },
ints = { 1, 2 }, longs = { 1, 2 }, floats = { 1.0f, 2.0f },
doubles = { 1.0, 2.0 }, booleans = { false, true })
@ArraysAnnotation(strings = { "a", "b" }, classes = { Integer.class, Long.class }, ints = { 1, 2 },
longs = { 1, 2 }, floats = { 1.0f, 2.0f }, doubles = { 1.0, 2.0 }, booleans = { false, true })
static class Arrays {
}
@@ -380,8 +363,7 @@ public class AnnotationsPropertySourceTests {
}
static class AliasedPropertyMappedAnnotationOnSuperClass
extends PropertyMappedAttributeWithAnAlias {
static class AliasedPropertyMappedAnnotationOnSuperClass extends PropertyMappedAttributeWithAnAlias {
}

View File

@@ -46,13 +46,10 @@ public class PropertyMappingContextCustomizerFactoryTests {
@Test
public void getContextCustomizerWhenHasNoMappingShouldNotAddPropertySource() {
ContextCustomizer customizer = this.factory
.createContextCustomizer(NoMapping.class, null);
ConfigurableApplicationContext context = mock(
ConfigurableApplicationContext.class);
ContextCustomizer customizer = this.factory.createContextCustomizer(NoMapping.class, null);
ConfigurableApplicationContext context = mock(ConfigurableApplicationContext.class);
ConfigurableEnvironment environment = mock(ConfigurableEnvironment.class);
ConfigurableListableBeanFactory beanFactory = mock(
ConfigurableListableBeanFactory.class);
ConfigurableListableBeanFactory beanFactory = mock(ConfigurableListableBeanFactory.class);
given(context.getEnvironment()).willReturn(environment);
given(context.getBeanFactory()).willReturn(beanFactory);
customizer.customizeContext(context, null);
@@ -61,35 +58,28 @@ public class PropertyMappingContextCustomizerFactoryTests {
@Test
public void getContextCustomizerWhenHasTypeMappingShouldReturnCustomizer() {
ContextCustomizer customizer = this.factory
.createContextCustomizer(TypeMapping.class, null);
ContextCustomizer customizer = this.factory.createContextCustomizer(TypeMapping.class, null);
assertThat(customizer).isNotNull();
}
@Test
public void getContextCustomizerWhenHasAttributeMappingShouldReturnCustomizer() {
ContextCustomizer customizer = this.factory
.createContextCustomizer(AttributeMapping.class, null);
ContextCustomizer customizer = this.factory.createContextCustomizer(AttributeMapping.class, null);
assertThat(customizer).isNotNull();
}
@Test
public void hashCodeAndEqualsShouldBeBasedOnPropertyValues() {
ContextCustomizer customizer1 = this.factory
.createContextCustomizer(TypeMapping.class, null);
ContextCustomizer customizer2 = this.factory
.createContextCustomizer(AttributeMapping.class, null);
ContextCustomizer customizer3 = this.factory
.createContextCustomizer(OtherMapping.class, null);
ContextCustomizer customizer1 = this.factory.createContextCustomizer(TypeMapping.class, null);
ContextCustomizer customizer2 = this.factory.createContextCustomizer(AttributeMapping.class, null);
ContextCustomizer customizer3 = this.factory.createContextCustomizer(OtherMapping.class, null);
assertThat(customizer1.hashCode()).isEqualTo(customizer2.hashCode());
assertThat(customizer1).isEqualTo(customizer1).isEqualTo(customizer2)
.isNotEqualTo(customizer3);
assertThat(customizer1).isEqualTo(customizer1).isEqualTo(customizer2).isNotEqualTo(customizer3);
}
@Test
public void prepareContextShouldAddPropertySource() {
ContextCustomizer customizer = this.factory
.createContextCustomizer(AttributeMapping.class, null);
ContextCustomizer customizer = this.factory.createContextCustomizer(AttributeMapping.class, null);
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
customizer.customizeContext(context, null);
assertThat(context.getEnvironment().getProperty("mapped")).isEqualTo("Mapped");
@@ -97,13 +87,11 @@ public class PropertyMappingContextCustomizerFactoryTests {
@Test
public void propertyMappingShouldNotBeUsedWithComponent() {
ContextCustomizer customizer = this.factory
.createContextCustomizer(AttributeMapping.class, null);
ContextCustomizer customizer = this.factory.createContextCustomizer(AttributeMapping.class, null);
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.register(ConfigMapping.class);
customizer.customizeContext(context, null);
assertThatExceptionOfType(BeanCreationException.class)
.isThrownBy(context::refresh)
assertThatExceptionOfType(BeanCreationException.class).isThrownBy(context::refresh)
.withMessageContaining("The @PropertyMapping annotation "
+ "@PropertyMappingContextCustomizerFactoryTests.TypeMappingAnnotation "
+ "cannot be used in combination with the @Component annotation @Configuration");

Some files were not shown because too many files have changed in this diff Show More