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.
@@ -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");

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.
@@ -68,13 +68,11 @@ public class MockMvcRestDocsAutoConfigurationAdvancedConfigurationIntegrationTes
@Test
public void snippetGeneration() throws Exception {
this.mvc.perform(get("/")).andDo(this.documentationHandler.document(links(
linkWithRel("self").description("Canonical location of this resource"))));
File defaultSnippetsDir = new File(
"target/generated-snippets/snippet-generation");
this.mvc.perform(get("/")).andDo(this.documentationHandler
.document(links(linkWithRel("self").description("Canonical location of this resource"))));
File defaultSnippetsDir = new File("target/generated-snippets/snippet-generation");
assertThat(defaultSnippetsDir).exists();
assertThat(new File(defaultSnippetsDir, "curl-request.md"))
.has(contentContaining("'http://localhost:8080/'"));
assertThat(new File(defaultSnippetsDir, "curl-request.md")).has(contentContaining("'http://localhost:8080/'"));
assertThat(new File(defaultSnippetsDir, "links.md")).isFile();
assertThat(new File(defaultSnippetsDir, "response-fields.md")).isFile();
}
@@ -93,14 +91,13 @@ public class MockMvcRestDocsAutoConfigurationAdvancedConfigurationIntegrationTes
@Bean
public RestDocsMockMvcConfigurationCustomizer templateFormatCustomizer() {
return (configurer) -> configurer.snippets()
.withTemplateFormat(TemplateFormats.markdown());
return (configurer) -> configurer.snippets().withTemplateFormat(TemplateFormats.markdown());
}
@Bean
public RestDocsMockMvcConfigurationCustomizer defaultSnippetsCustomizer() {
return (configurer) -> configurer.snippets().withAdditionalDefaults(
responseFields(fieldWithPath("_links.self").description("Main URL")));
return (configurer) -> configurer.snippets()
.withAdditionalDefaults(responseFields(fieldWithPath("_links.self").description("Main URL")));
}
}

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 @@ public class MockMvcRestDocsAutoConfigurationIntegrationTests {
assertThat(defaultSnippetsDir).exists();
assertThat(new File(defaultSnippetsDir, "curl-request.adoc"))
.has(contentContaining("'https://api.example.com/'"));
assertThat(new File(defaultSnippetsDir, "http-request.adoc"))
.has(contentContaining("api.example.com"));
assertThat(new File(defaultSnippetsDir, "http-request.adoc")).has(contentContaining("api.example.com"));
assertThat(new File(defaultSnippetsDir, "http-response.adoc")).isFile();
}

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.
@@ -71,15 +71,13 @@ public class RestAssuredRestDocsAutoConfigurationAdvancedConfigurationIntegratio
public void snippetGeneration() {
given(this.documentationSpec)
.filter(document("default-snippets",
preprocessRequest(modifyUris().scheme("https")
.host("api.example.com").removePort())))
preprocessRequest(modifyUris().scheme("https").host("api.example.com").removePort())))
.when().port(this.port).get("/").then().assertThat().statusCode(is(200));
File defaultSnippetsDir = new File("target/generated-snippets/default-snippets");
assertThat(defaultSnippetsDir).exists();
assertThat(new File(defaultSnippetsDir, "curl-request.md"))
.has(contentContaining("'https://api.example.com/'"));
assertThat(new File(defaultSnippetsDir, "http-request.md"))
.has(contentContaining("api.example.com"));
assertThat(new File(defaultSnippetsDir, "http-request.md")).has(contentContaining("api.example.com"));
assertThat(new File(defaultSnippetsDir, "http-response.md")).isFile();
assertThat(new File(defaultSnippetsDir, "response-fields.md")).isFile();
}
@@ -98,14 +96,13 @@ public class RestAssuredRestDocsAutoConfigurationAdvancedConfigurationIntegratio
@Bean
public RestDocsRestAssuredConfigurationCustomizer templateFormatCustomizer() {
return (configurer) -> configurer.snippets()
.withTemplateFormat(TemplateFormats.markdown());
return (configurer) -> configurer.snippets().withTemplateFormat(TemplateFormats.markdown());
}
@Bean
public RestDocsRestAssuredConfigurationCustomizer defaultSnippetsCustomizer() {
return (configurer) -> configurer.snippets().withAdditionalDefaults(
responseFields(fieldWithPath("_links.self").description("Main URL")));
return (configurer) -> configurer.snippets()
.withAdditionalDefaults(responseFields(fieldWithPath("_links.self").description("Main URL")));
}
}

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,15 +63,13 @@ public class RestAssuredRestDocsAutoConfigurationIntegrationTests {
public void defaultSnippetsAreWritten() {
given(this.documentationSpec)
.filter(document("default-snippets",
preprocessRequest(modifyUris().scheme("https")
.host("api.example.com").removePort())))
preprocessRequest(modifyUris().scheme("https").host("api.example.com").removePort())))
.when().port(this.port).get("/").then().assertThat().statusCode(is(200));
File defaultSnippetsDir = new File("target/generated-snippets/default-snippets");
assertThat(defaultSnippetsDir).exists();
assertThat(new File(defaultSnippetsDir, "curl-request.adoc"))
.has(contentContaining("'https://api.example.com/'"));
assertThat(new File(defaultSnippetsDir, "http-request.adoc"))
.has(contentContaining("api.example.com"));
assertThat(new File(defaultSnippetsDir, "http-request.adoc")).has(contentContaining("api.example.com"));
assertThat(new File(defaultSnippetsDir, "http-response.adoc")).isFile();
}

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,14 +61,13 @@ public class WebTestClientRestDocsAutoConfigurationAdvancedConfigurationIntegrat
@Test
public void defaultSnippetsAreWritten() throws Exception {
this.webTestClient.get().uri("/").exchange().expectStatus().is2xxSuccessful()
.expectBody().consumeWith(document("default-snippets"));
this.webTestClient.get().uri("/").exchange().expectStatus().is2xxSuccessful().expectBody()
.consumeWith(document("default-snippets"));
File defaultSnippetsDir = new File("target/generated-snippets/default-snippets");
assertThat(defaultSnippetsDir).exists();
assertThat(new File(defaultSnippetsDir, "curl-request.md"))
.has(contentContaining("'https://api.example.com/'"));
assertThat(new File(defaultSnippetsDir, "http-request.md"))
.has(contentContaining("api.example.com"));
assertThat(new File(defaultSnippetsDir, "http-request.md")).has(contentContaining("api.example.com"));
assertThat(new File(defaultSnippetsDir, "http-response.md")).isFile();
assertThat(new File(defaultSnippetsDir, "response-fields.md")).isFile();
}
@@ -87,14 +86,13 @@ public class WebTestClientRestDocsAutoConfigurationAdvancedConfigurationIntegrat
@Bean
public RestDocsWebTestClientConfigurationCustomizer templateFormatCustomizer() {
return (configurer) -> configurer.snippets()
.withTemplateFormat(TemplateFormats.markdown());
return (configurer) -> configurer.snippets().withTemplateFormat(TemplateFormats.markdown());
}
@Bean
public RestDocsWebTestClientConfigurationCustomizer defaultSnippetsCustomizer() {
return (configurer) -> configurer.snippets().withAdditionalDefaults(
responseFields(fieldWithPath("_links.self").description("Main URL")));
return (configurer) -> configurer.snippets()
.withAdditionalDefaults(responseFields(fieldWithPath("_links.self").description("Main URL")));
}
}

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,14 +54,13 @@ public class WebTestClientRestDocsAutoConfigurationIntegrationTests {
@Test
public void defaultSnippetsAreWritten() throws Exception {
this.webTestClient.get().uri("/").exchange().expectStatus().is2xxSuccessful()
.expectBody().consumeWith(document("default-snippets"));
this.webTestClient.get().uri("/").exchange().expectStatus().is2xxSuccessful().expectBody()
.consumeWith(document("default-snippets"));
File defaultSnippetsDir = new File("target/generated-snippets/default-snippets");
assertThat(defaultSnippetsDir).exists();
assertThat(new File(defaultSnippetsDir, "curl-request.adoc"))
.has(contentContaining("'https://api.example.com/'"));
assertThat(new File(defaultSnippetsDir, "http-request.adoc"))
.has(contentContaining("api.example.com"));
assertThat(new File(defaultSnippetsDir, "http-request.adoc")).has(contentContaining("api.example.com"));
assertThat(new File(defaultSnippetsDir, "http-response.adoc")).isFile();
}

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.
@@ -54,16 +54,13 @@ public class MockMvcSecurityAutoConfigurationIntegrationTests {
@Test
public void unauthorizedResponseWithNoUser() throws Exception {
this.mockMvc.perform(get("/").accept(MediaType.APPLICATION_JSON))
.andExpect(status().isUnauthorized());
this.mockMvc.perform(get("/").accept(MediaType.APPLICATION_JSON)).andExpect(status().isUnauthorized());
}
@Test
public void okResponseWithBasicAuthCredentialsForKnownUser() throws Exception {
this.mockMvc
.perform(get("/").header(HttpHeaders.AUTHORIZATION,
"Basic " + Base64Utils.encodeToString("user:secret".getBytes())))
.andExpect(status().isOk());
this.mockMvc.perform(get("/").header(HttpHeaders.AUTHORIZATION,
"Basic " + Base64Utils.encodeToString("user:secret".getBytes()))).andExpect(status().isOk());
}
}

View File

@@ -43,8 +43,7 @@ public class AutoConfigureMockRestServiceServerEnabledFalseIntegrationTests {
@Test
public void mockServerRestTemplateCustomizerShouldNotBeRegistered() {
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
.isThrownBy(() -> this.applicationContext
.getBean(MockServerRestTemplateCustomizer.class));
.isThrownBy(() -> this.applicationContext.getBean(MockServerRestTemplateCustomizer.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.
@@ -52,10 +52,8 @@ public class AutoConfigureWebClientWithRestTemplateIntegrationTests {
@Test
public void restTemplateTest() {
this.server.expect(requestTo("/test"))
.andRespond(withSuccess("hello", MediaType.TEXT_HTML));
ResponseEntity<String> entity = this.restTemplate.getForEntity("/test",
String.class);
this.server.expect(requestTo("/test")).andRespond(withSuccess("hello", MediaType.TEXT_HTML));
ResponseEntity<String> entity = this.restTemplate.getForEntity("/test", String.class);
assertThat(entity.getBody()).isEqualTo("hello");
}

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.
@@ -46,15 +46,13 @@ public class RestClientRestIntegrationTests {
@Test
public void mockServerCall1() {
this.server.expect(requestTo("/test"))
.andRespond(withSuccess("1", MediaType.TEXT_HTML));
this.server.expect(requestTo("/test")).andRespond(withSuccess("1", MediaType.TEXT_HTML));
assertThat(this.client.test()).isEqualTo("1");
}
@Test
public void mockServerCall2() {
this.server.expect(requestTo("/test"))
.andRespond(withSuccess("2", MediaType.TEXT_HTML));
this.server.expect(requestTo("/test")).andRespond(withSuccess("2", MediaType.TEXT_HTML));
assertThat(this.client.test()).isEqualTo("2");
}

View File

@@ -52,15 +52,14 @@ public class RestClientTestNoComponentIntegrationTests {
@Test
public void exampleRestClientIsNotInjected() {
assertThatExceptionOfType(NoSuchBeanDefinitionException.class).isThrownBy(
() -> this.applicationContext.getBean(ExampleRestClient.class));
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
.isThrownBy(() -> this.applicationContext.getBean(ExampleRestClient.class));
}
@Test
public void manuallyCreateBean() {
ExampleRestClient client = new ExampleRestClient(this.restTemplateBuilder);
this.server.expect(requestTo("/test"))
.andRespond(withSuccess("hello", MediaType.TEXT_HTML));
this.server.expect(requestTo("/test")).andRespond(withSuccess("hello", MediaType.TEXT_HTML));
assertThat(client.test()).isEqualTo("hello");
}

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.
@@ -53,24 +53,21 @@ public class RestClientTestTwoComponentsIntegrationTests {
@Test
public void serverShouldNotWork() {
assertThatIllegalStateException()
.isThrownBy(() -> this.server.expect(requestTo("/test"))
.andRespond(withSuccess("hello", MediaType.TEXT_HTML)))
assertThatIllegalStateException().isThrownBy(
() -> this.server.expect(requestTo("/test")).andRespond(withSuccess("hello", MediaType.TEXT_HTML)))
.withMessageContaining("Unable to use auto-configured");
}
@Test
public void client1RestCallViaCustomizer() {
this.customizer.getServer(this.client1.getRestTemplate())
.expect(requestTo("/test"))
this.customizer.getServer(this.client1.getRestTemplate()).expect(requestTo("/test"))
.andRespond(withSuccess("hello", MediaType.TEXT_HTML));
assertThat(this.client1.test()).isEqualTo("hello");
}
@Test
public void client2RestCallViaCustomizer() {
this.customizer.getServer(this.client2.getRestTemplate())
.expect(requestTo("/test"))
this.customizer.getServer(this.client2.getRestTemplate()).expect(requestTo("/test"))
.andRespond(withSuccess("there", MediaType.TEXT_HTML));
assertThat(this.client2.test()).isEqualTo("there");
}

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.
@@ -45,8 +45,7 @@ public class RestClientTestWithComponentIntegrationTests {
@Test
public void mockServerCall() {
this.server.expect(requestTo("/test"))
.andRespond(withSuccess("hello", MediaType.TEXT_HTML));
this.server.expect(requestTo("/test")).andRespond(withSuccess("hello", MediaType.TEXT_HTML));
assertThat(this.client.test()).isEqualTo("hello");
}

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.
@@ -38,10 +38,9 @@ public class RestClientTestWithoutJacksonIntegrationTests {
@Test
public void restClientTestCanBeUsedWhenJacksonIsNotOnTheClassPath() {
assertThat(ClassUtils.isPresent("com.fasterxml.jackson.databind.Module",
getClass().getClassLoader())).isFalse();
Result result = JUnitCore
.runClasses(RestClientTestWithComponentIntegrationTests.class);
assertThat(ClassUtils.isPresent("com.fasterxml.jackson.databind.Module", getClass().getClassLoader()))
.isFalse();
Result result = JUnitCore.runClasses(RestClientTestWithComponentIntegrationTests.class);
assertThat(result.getFailureCount()).isEqualTo(0);
assertThat(result.getRunCount()).isGreaterThan(0);
}

View File

@@ -45,8 +45,7 @@ public class WebFluxTypeExcludeFilterTests {
@Test
public void matchWhenHasNoControllers() throws Exception {
WebFluxTypeExcludeFilter filter = new WebFluxTypeExcludeFilter(
WithNoControllers.class);
WebFluxTypeExcludeFilter filter = new WebFluxTypeExcludeFilter(WithNoControllers.class);
assertThat(excludes(filter, Controller1.class)).isFalse();
assertThat(excludes(filter, Controller2.class)).isFalse();
assertThat(excludes(filter, ExampleControllerAdvice.class)).isFalse();
@@ -57,8 +56,7 @@ public class WebFluxTypeExcludeFilterTests {
@Test
public void matchWhenHasController() throws Exception {
WebFluxTypeExcludeFilter filter = new WebFluxTypeExcludeFilter(
WithController.class);
WebFluxTypeExcludeFilter filter = new WebFluxTypeExcludeFilter(WithController.class);
assertThat(excludes(filter, Controller1.class)).isFalse();
assertThat(excludes(filter, Controller2.class)).isTrue();
assertThat(excludes(filter, ExampleControllerAdvice.class)).isFalse();
@@ -69,8 +67,7 @@ public class WebFluxTypeExcludeFilterTests {
@Test
public void matchNotUsingDefaultFilters() throws Exception {
WebFluxTypeExcludeFilter filter = new WebFluxTypeExcludeFilter(
NotUsingDefaultFilters.class);
WebFluxTypeExcludeFilter filter = new WebFluxTypeExcludeFilter(NotUsingDefaultFilters.class);
assertThat(excludes(filter, Controller1.class)).isTrue();
assertThat(excludes(filter, Controller2.class)).isTrue();
assertThat(excludes(filter, ExampleControllerAdvice.class)).isTrue();
@@ -81,8 +78,7 @@ public class WebFluxTypeExcludeFilterTests {
@Test
public void matchWithIncludeFilter() throws Exception {
WebFluxTypeExcludeFilter filter = new WebFluxTypeExcludeFilter(
WithIncludeFilter.class);
WebFluxTypeExcludeFilter filter = new WebFluxTypeExcludeFilter(WithIncludeFilter.class);
assertThat(excludes(filter, Controller1.class)).isFalse();
assertThat(excludes(filter, Controller2.class)).isFalse();
assertThat(excludes(filter, ExampleControllerAdvice.class)).isFalse();
@@ -93,8 +89,7 @@ public class WebFluxTypeExcludeFilterTests {
@Test
public void matchWithExcludeFilter() throws Exception {
WebFluxTypeExcludeFilter filter = new WebFluxTypeExcludeFilter(
WithExcludeFilter.class);
WebFluxTypeExcludeFilter filter = new WebFluxTypeExcludeFilter(WithExcludeFilter.class);
assertThat(excludes(filter, Controller1.class)).isTrue();
assertThat(excludes(filter, Controller2.class)).isFalse();
assertThat(excludes(filter, ExampleControllerAdvice.class)).isFalse();
@@ -103,10 +98,8 @@ public class WebFluxTypeExcludeFilterTests {
assertThat(excludes(filter, ExampleRepository.class)).isTrue();
}
private boolean excludes(WebFluxTypeExcludeFilter filter, Class<?> type)
throws IOException {
MetadataReader metadataReader = this.metadataReaderFactory
.getMetadataReader(type.getName());
private boolean excludes(WebFluxTypeExcludeFilter filter, Class<?> type) throws IOException {
MetadataReader metadataReader = this.metadataReaderFactory.getMetadataReader(type.getName());
return filter.match(metadataReader, this.metadataReaderFactory);
}
@@ -130,8 +123,7 @@ public class WebFluxTypeExcludeFilterTests {
}
@WebFluxTest(excludeFilters = @Filter(type = FilterType.ASSIGNABLE_TYPE,
classes = Controller1.class))
@WebFluxTest(excludeFilters = @Filter(type = FilterType.ASSIGNABLE_TYPE, classes = Controller1.class))
static class WithExcludeFilter {
}

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 @@ import static org.mockito.Mockito.verify;
public class WebTestClientAutoConfigurationTests {
private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(
AutoConfigurations.of(WebTestClientAutoConfiguration.class));
.withConfiguration(AutoConfigurations.of(WebTestClientAutoConfiguration.class));
@Test
public void shouldNotBeConfiguredWithoutWebHandler() {
@@ -64,23 +63,19 @@ public class WebTestClientAutoConfigurationTests {
@Test
public void shouldCustomizeClientCodecs() {
this.contextRunner.withUserConfiguration(CodecConfiguration.class)
.run((context) -> {
assertThat(context).hasSingleBean(WebTestClient.class);
assertThat(context).hasSingleBean(CodecCustomizer.class);
verify(context.getBean(CodecCustomizer.class))
.customize(any(CodecConfigurer.class));
});
this.contextRunner.withUserConfiguration(CodecConfiguration.class).run((context) -> {
assertThat(context).hasSingleBean(WebTestClient.class);
assertThat(context).hasSingleBean(CodecCustomizer.class);
verify(context.getBean(CodecCustomizer.class)).customize(any(CodecConfigurer.class));
});
}
@Test
public void shouldCustomizeTimeout() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("spring.test.webtestclient.timeout=15m")
.run((context) -> {
.withPropertyValues("spring.test.webtestclient.timeout=15m").run((context) -> {
WebTestClient webTestClient = context.getBean(WebTestClient.class);
Object duration = ReflectionTestUtils.getField(webTestClient,
"timeout");
Object duration = ReflectionTestUtils.getField(webTestClient, "timeout");
assertThat(duration).isEqualTo(Duration.of(15, ChronoUnit.MINUTES));
});
}
@@ -88,34 +83,31 @@ public class WebTestClientAutoConfigurationTests {
@Test
@SuppressWarnings("unchecked")
public void shouldApplySpringSecurityConfigurer() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.run((context) -> {
WebTestClient webTestClient = context.getBean(WebTestClient.class);
WebTestClient.Builder builder = (WebTestClient.Builder) ReflectionTestUtils
.getField(webTestClient, "builder");
WebHttpHandlerBuilder httpHandlerBuilder = (WebHttpHandlerBuilder) ReflectionTestUtils
.getField(builder, "httpHandlerBuilder");
List<WebFilter> filters = (List<WebFilter>) ReflectionTestUtils
.getField(httpHandlerBuilder, "filters");
assertThat(filters.get(0).getClass().getName()).isEqualTo(
"org.springframework.security.test.web.reactive.server.SecurityMockServerConfigurers$MutatorFilter");
});
this.contextRunner.withUserConfiguration(BaseConfiguration.class).run((context) -> {
WebTestClient webTestClient = context.getBean(WebTestClient.class);
WebTestClient.Builder builder = (WebTestClient.Builder) ReflectionTestUtils.getField(webTestClient,
"builder");
WebHttpHandlerBuilder httpHandlerBuilder = (WebHttpHandlerBuilder) ReflectionTestUtils.getField(builder,
"httpHandlerBuilder");
List<WebFilter> filters = (List<WebFilter>) ReflectionTestUtils.getField(httpHandlerBuilder, "filters");
assertThat(filters.get(0).getClass().getName()).isEqualTo(
"org.springframework.security.test.web.reactive.server.SecurityMockServerConfigurers$MutatorFilter");
});
}
@Test
@SuppressWarnings("unchecked")
public void shouldNotApplySpringSecurityConfigurerWhenSpringSecurityNotOnClassPath() {
FilteredClassLoader classLoader = new FilteredClassLoader(
SecurityMockServerConfigurers.class);
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withClassLoader(classLoader).run((context) -> {
FilteredClassLoader classLoader = new FilteredClassLoader(SecurityMockServerConfigurers.class);
this.contextRunner.withUserConfiguration(BaseConfiguration.class).withClassLoader(classLoader)
.run((context) -> {
WebTestClient webTestClient = context.getBean(WebTestClient.class);
WebTestClient.Builder builder = (WebTestClient.Builder) ReflectionTestUtils
.getField(webTestClient, "builder");
WebTestClient.Builder builder = (WebTestClient.Builder) ReflectionTestUtils.getField(webTestClient,
"builder");
WebHttpHandlerBuilder httpHandlerBuilder = (WebHttpHandlerBuilder) ReflectionTestUtils
.getField(builder, "httpHandlerBuilder");
List<WebFilter> filters = (List<WebFilter>) ReflectionTestUtils
.getField(httpHandlerBuilder, "filters");
List<WebFilter> filters = (List<WebFilter>) ReflectionTestUtils.getField(httpHandlerBuilder,
"filters");
assertThat(filters).isEmpty();
});
}

View File

@@ -39,8 +39,7 @@ public class ExampleIdConverter implements GenericConverter {
}
@Override
public Object convert(Object source, TypeDescriptor sourceType,
TypeDescriptor targetType) {
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
if (source == 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.
@@ -40,14 +40,12 @@ public class WebFluxTestAllControllersIntegrationTests {
@Test
public void shouldFindController1() {
this.webClient.get().uri("/one").exchange().expectStatus().isOk()
.expectBody(String.class).isEqualTo("one");
this.webClient.get().uri("/one").exchange().expectStatus().isOk().expectBody(String.class).isEqualTo("one");
}
@Test
public void shouldFindController2() {
this.webClient.get().uri("/two").exchange().expectStatus().isOk()
.expectBody(String.class).isEqualTo("two");
this.webClient.get().uri("/two").exchange().expectStatus().isOk().expectBody(String.class).isEqualTo("two");
}
@Test

View File

@@ -49,38 +49,32 @@ public class WebFluxTestAutoConfigurationIntegrationTests {
@Test
public void messageSourceAutoConfigurationIsImported() {
assertThat(this.applicationContext)
.has(importedAutoConfiguration(MessageSourceAutoConfiguration.class));
assertThat(this.applicationContext).has(importedAutoConfiguration(MessageSourceAutoConfiguration.class));
}
@Test
public void validationAutoConfigurationIsImported() {
assertThat(this.applicationContext)
.has(importedAutoConfiguration(ValidationAutoConfiguration.class));
assertThat(this.applicationContext).has(importedAutoConfiguration(ValidationAutoConfiguration.class));
}
@Test
public void mustacheAutoConfigurationIsImported() {
assertThat(this.applicationContext)
.has(importedAutoConfiguration(MustacheAutoConfiguration.class));
assertThat(this.applicationContext).has(importedAutoConfiguration(MustacheAutoConfiguration.class));
}
@Test
public void freemarkerAutoConfigurationIsImported() {
assertThat(this.applicationContext)
.has(importedAutoConfiguration(FreeMarkerAutoConfiguration.class));
assertThat(this.applicationContext).has(importedAutoConfiguration(FreeMarkerAutoConfiguration.class));
}
@Test
public void thymeleafAutoConfigurationIsImported() {
assertThat(this.applicationContext)
.has(importedAutoConfiguration(ThymeleafAutoConfiguration.class));
assertThat(this.applicationContext).has(importedAutoConfiguration(ThymeleafAutoConfiguration.class));
}
@Test
public void errorWebFluxAutoConfigurationIsImported() {
assertThat(this.applicationContext)
.has(importedAutoConfiguration(ErrorWebFluxAutoConfiguration.class));
assertThat(this.applicationContext).has(importedAutoConfiguration(ErrorWebFluxAutoConfiguration.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.
@@ -43,8 +43,8 @@ public class WebFluxTestConverterIntegrationTests {
@Test
public void shouldFindConverter() {
UUID id = UUID.randomUUID();
this.webClient.get().uri("/two/" + id).exchange().expectStatus().isOk()
.expectBody(String.class).isEqualTo(id + "two");
this.webClient.get().uri("/two/" + id).exchange().expectStatus().isOk().expectBody(String.class)
.isEqualTo(id + "two");
}
}

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.
@@ -40,8 +40,7 @@ public class WebFluxTestOneControllerIntegrationTests {
@Test
public void shouldFindController() {
this.webClient.get().uri("/one").exchange().expectStatus().isOk()
.expectBody(String.class).isEqualTo("one");
this.webClient.get().uri("/one").exchange().expectStatus().isOk().expectBody(String.class).isEqualTo("one");
}
@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.
@@ -41,8 +41,7 @@ public class WebFluxTestWebTestClientCodecCustomizationIntegrationTests {
@Test
public void shouldBeAbleToCreatePojoViaParametersModule() {
this.webClient.get().uri("/json").exchange().expectStatus().isOk()
.expectBody(ExamplePojo.class);
this.webClient.get().uri("/json").exchange().expectStatus().isOk().expectBody(ExamplePojo.class);
}
}

View File

@@ -39,9 +39,8 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Stephane Nicoll
*/
@RunWith(SpringRunner.class)
@SpringBootTest(properties = "spring.main.web-application-type=reactive",
classes = { WebTestClientSpringBootTestIntegrationTests.TestConfiguration.class,
ExampleWebFluxApplication.class })
@SpringBootTest(properties = "spring.main.web-application-type=reactive", classes = {
WebTestClientSpringBootTestIntegrationTests.TestConfiguration.class, ExampleWebFluxApplication.class })
@AutoConfigureWebTestClient
public class WebTestClientSpringBootTestIntegrationTests {
@@ -53,20 +52,17 @@ public class WebTestClientSpringBootTestIntegrationTests {
@Test
public void shouldFindController1() {
this.webClient.get().uri("/one").exchange().expectStatus().isOk()
.expectBody(String.class).isEqualTo("one");
this.webClient.get().uri("/one").exchange().expectStatus().isOk().expectBody(String.class).isEqualTo("one");
}
@Test
public void shouldFindController2() {
this.webClient.get().uri("/two").exchange().expectStatus().isOk()
.expectBody(String.class).isEqualTo("two");
this.webClient.get().uri("/two").exchange().expectStatus().isOk().expectBody(String.class).isEqualTo("two");
}
@Test
public void shouldHaveRealService() {
assertThat(this.applicationContext.getBeansOfType(ExampleRealService.class))
.hasSize(1);
assertThat(this.applicationContext.getBeansOfType(ExampleRealService.class)).hasSize(1);
}
@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.
@@ -39,8 +39,7 @@ public class MockMvcAutoConfigurationTests {
this.contextRunner.run((context) -> {
MockMvc mockMvc = context.getBean(MockMvc.class);
assertThat(context).hasSingleBean(DispatcherServlet.class);
assertThat(context.getBean(DispatcherServlet.class))
.isEqualTo(mockMvc.getDispatcherServlet());
assertThat(context.getBean(DispatcherServlet.class)).isEqualTo(mockMvc.getDispatcherServlet());
});
}

View File

@@ -61,8 +61,7 @@ public class SpringBootMockMvcBuilderCustomizerTests {
.getBean("filterRegistrationBean");
Filter testFilter = (Filter) context.getBean("testFilter");
Filter otherTestFilter = registrationBean.getFilter();
List<Filter> filters = (List<Filter>) ReflectionTestUtils.getField(builder,
"filters");
List<Filter> filters = (List<Filter>) ReflectionTestUtils.getField(builder, "filters");
assertThat(filters).containsExactlyInAnyOrder(testFilter, otherTestFilter);
}
@@ -103,8 +102,7 @@ public class SpringBootMockMvcBuilderCustomizerTests {
}
@Override
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) {
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) {
}
@@ -123,8 +121,7 @@ public class SpringBootMockMvcBuilderCustomizerTests {
}
@Override
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) {
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) {
}

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,42 +49,34 @@ public class WebMvcTestAutoConfigurationIntegrationTests {
@Test
public void freemarkerAutoConfigurationWasImported() {
assertThat(this.applicationContext)
.has(importedAutoConfiguration(FreeMarkerAutoConfiguration.class));
assertThat(this.applicationContext).has(importedAutoConfiguration(FreeMarkerAutoConfiguration.class));
}
@Test
public void groovyTemplatesAutoConfigurationWasImported() {
assertThat(this.applicationContext)
.has(importedAutoConfiguration(GroovyTemplateAutoConfiguration.class));
assertThat(this.applicationContext).has(importedAutoConfiguration(GroovyTemplateAutoConfiguration.class));
}
@Test
public void mustacheAutoConfigurationWasImported() {
assertThat(this.applicationContext)
.has(importedAutoConfiguration(MustacheAutoConfiguration.class));
assertThat(this.applicationContext).has(importedAutoConfiguration(MustacheAutoConfiguration.class));
}
@Test
public void thymeleafAutoConfigurationWasImported() {
assertThat(this.applicationContext)
.has(importedAutoConfiguration(ThymeleafAutoConfiguration.class));
assertThat(this.applicationContext).has(importedAutoConfiguration(ThymeleafAutoConfiguration.class));
}
@Test
public void taskExecutionAutoConfigurationWasImported() {
assertThat(this.applicationContext)
.has(importedAutoConfiguration(TaskExecutionAutoConfiguration.class));
assertThat(this.applicationContext).has(importedAutoConfiguration(TaskExecutionAutoConfiguration.class));
}
@Test
public void asyncTaskExecutorWithApplicationTaskExecutor() {
assertThat(this.applicationContext.getBeansOfType(AsyncTaskExecutor.class))
.hasSize(1);
assertThat(ReflectionTestUtils.getField(
this.applicationContext.getBean(RequestMappingHandlerAdapter.class),
"taskExecutor")).isSameAs(
this.applicationContext.getBean("applicationTaskExecutor"));
assertThat(this.applicationContext.getBeansOfType(AsyncTaskExecutor.class)).hasSize(1);
assertThat(ReflectionTestUtils.getField(this.applicationContext.getBean(RequestMappingHandlerAdapter.class),
"taskExecutor")).isSameAs(this.applicationContext.getBean("applicationTaskExecutor"));
}
}

View File

@@ -46,8 +46,7 @@ public class WebMvcTypeExcludeFilterTests {
@Test
public void matchWhenHasNoControllers() throws Exception {
WebMvcTypeExcludeFilter filter = new WebMvcTypeExcludeFilter(
WithNoControllers.class);
WebMvcTypeExcludeFilter filter = new WebMvcTypeExcludeFilter(WithNoControllers.class);
assertThat(excludes(filter, Controller1.class)).isFalse();
assertThat(excludes(filter, Controller2.class)).isFalse();
assertThat(excludes(filter, ExampleControllerAdvice.class)).isFalse();
@@ -60,8 +59,7 @@ public class WebMvcTypeExcludeFilterTests {
@Test
public void matchWhenHasController() throws Exception {
WebMvcTypeExcludeFilter filter = new WebMvcTypeExcludeFilter(
WithController.class);
WebMvcTypeExcludeFilter filter = new WebMvcTypeExcludeFilter(WithController.class);
assertThat(excludes(filter, Controller1.class)).isFalse();
assertThat(excludes(filter, Controller2.class)).isTrue();
assertThat(excludes(filter, ExampleControllerAdvice.class)).isFalse();
@@ -74,8 +72,7 @@ public class WebMvcTypeExcludeFilterTests {
@Test
public void matchNotUsingDefaultFilters() throws Exception {
WebMvcTypeExcludeFilter filter = new WebMvcTypeExcludeFilter(
NotUsingDefaultFilters.class);
WebMvcTypeExcludeFilter filter = new WebMvcTypeExcludeFilter(NotUsingDefaultFilters.class);
assertThat(excludes(filter, Controller1.class)).isTrue();
assertThat(excludes(filter, Controller2.class)).isTrue();
assertThat(excludes(filter, ExampleControllerAdvice.class)).isTrue();
@@ -88,8 +85,7 @@ public class WebMvcTypeExcludeFilterTests {
@Test
public void matchWithIncludeFilter() throws Exception {
WebMvcTypeExcludeFilter filter = new WebMvcTypeExcludeFilter(
WithIncludeFilter.class);
WebMvcTypeExcludeFilter filter = new WebMvcTypeExcludeFilter(WithIncludeFilter.class);
assertThat(excludes(filter, Controller1.class)).isFalse();
assertThat(excludes(filter, Controller2.class)).isFalse();
assertThat(excludes(filter, ExampleControllerAdvice.class)).isFalse();
@@ -101,8 +97,7 @@ public class WebMvcTypeExcludeFilterTests {
@Test
public void matchWithExcludeFilter() throws Exception {
WebMvcTypeExcludeFilter filter = new WebMvcTypeExcludeFilter(
WithExcludeFilter.class);
WebMvcTypeExcludeFilter filter = new WebMvcTypeExcludeFilter(WithExcludeFilter.class);
assertThat(excludes(filter, Controller1.class)).isTrue();
assertThat(excludes(filter, Controller2.class)).isFalse();
assertThat(excludes(filter, ExampleControllerAdvice.class)).isFalse();
@@ -115,8 +110,7 @@ public class WebMvcTypeExcludeFilterTests {
@Test
public void matchWhenSecureFalse() throws Exception {
WebMvcTypeExcludeFilter filter = new WebMvcTypeExcludeFilter(
WithSecureFalse.class);
WebMvcTypeExcludeFilter filter = new WebMvcTypeExcludeFilter(WithSecureFalse.class);
assertThat(excludes(filter, Controller1.class)).isFalse();
assertThat(excludes(filter, Controller2.class)).isFalse();
assertThat(excludes(filter, ExampleControllerAdvice.class)).isFalse();
@@ -127,10 +121,8 @@ public class WebMvcTypeExcludeFilterTests {
assertThat(excludes(filter, ExampleWebSecurityConfigurer.class)).isTrue();
}
private boolean excludes(WebMvcTypeExcludeFilter filter, Class<?> type)
throws IOException {
MetadataReader metadataReader = this.metadataReaderFactory
.getMetadataReader(type.getName());
private boolean excludes(WebMvcTypeExcludeFilter filter, Class<?> type) throws IOException {
MetadataReader metadataReader = this.metadataReaderFactory.getMetadataReader(type.getName());
return filter.match(metadataReader, this.metadataReaderFactory);
}
@@ -154,8 +146,7 @@ public class WebMvcTypeExcludeFilterTests {
}
@WebMvcTest(excludeFilters = @Filter(type = FilterType.ASSIGNABLE_TYPE,
classes = Controller1.class))
@WebMvcTest(excludeFilters = @Filter(type = FilterType.ASSIGNABLE_TYPE, classes = Controller1.class))
static class WithExcludeFilter {
}

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,10 +40,8 @@ public class ExampleControllerAdvice {
@ExceptionHandler(NoHandlerFoundException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
public ResponseEntity<String> noHandlerFoundHandler(
NoHandlerFoundException exception) {
return ResponseEntity.badRequest()
.body("Invalid request: " + exception.getRequestURL());
public ResponseEntity<String> noHandlerFoundHandler(NoHandlerFoundException exception) {
return ResponseEntity.badRequest().body("Invalid request: " + exception.getRequestURL());
}
}

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,8 @@ public class ExampleFilter implements Filter {
}
@Override
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
chain.doFilter(request, response);
((HttpServletResponse) response).addHeader("x-test", "abc");
}

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.
@@ -36,8 +36,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
public class ExampleWebMvcConfigurer implements WebMvcConfigurer {
@Override
public void addArgumentResolvers(
List<HandlerMethodArgumentResolver> argumentResolvers) {
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
argumentResolvers.add(new HandlerMethodArgumentResolver() {
@Override
@@ -46,9 +45,8 @@ public class ExampleWebMvcConfigurer implements WebMvcConfigurer {
}
@Override
public Object resolveArgument(MethodParameter parameter,
ModelAndViewContainer mavContainer, NativeWebRequest webRequest,
WebDataBinderFactory binderFactory) throws Exception {
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
return new ExampleArgument("hello");
}

View File

@@ -35,8 +35,7 @@ class HateoasController {
@RequestMapping("/resource")
public Resource<Map<String, String>> resource() {
return new Resource<>(new HashMap<String, String>(),
new Link("self", "https://api.example.com"));
return new Resource<>(new HashMap<String, String>(), new Link("self", "https://api.example.com"));
}
@RequestMapping("/plain")

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.
@@ -62,21 +62,18 @@ public class MockMvcSpringBootTestIntegrationTests {
@Test
public void shouldFindController1() throws Exception {
this.mvc.perform(get("/one")).andExpect(content().string("one"))
.andExpect(status().isOk());
this.mvc.perform(get("/one")).andExpect(content().string("one")).andExpect(status().isOk());
assertThat(this.output.toString()).contains("Request URI = /one");
}
@Test
public void shouldFindController2() throws Exception {
this.mvc.perform(get("/two")).andExpect(content().string("hellotwo"))
.andExpect(status().isOk());
this.mvc.perform(get("/two")).andExpect(content().string("hellotwo")).andExpect(status().isOk());
}
@Test
public void shouldFindControllerAdvice() throws Exception {
this.mvc.perform(get("/error")).andExpect(content().string("recovered"))
.andExpect(status().isOk());
this.mvc.perform(get("/error")).andExpect(content().string("recovered")).andExpect(status().isOk());
}
@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.
@@ -54,26 +54,22 @@ public class WebMvcTestAllControllersIntegrationTests {
@Test
public void shouldFindController1() throws Exception {
this.mvc.perform(get("/one")).andExpect(content().string("one"))
.andExpect(status().isOk());
this.mvc.perform(get("/one")).andExpect(content().string("one")).andExpect(status().isOk());
}
@Test
public void shouldFindController2() throws Exception {
this.mvc.perform(get("/two")).andExpect(content().string("hellotwo"))
.andExpect(status().isOk());
this.mvc.perform(get("/two")).andExpect(content().string("hellotwo")).andExpect(status().isOk());
}
@Test
public void shouldFindControllerAdvice() throws Exception {
this.mvc.perform(get("/error")).andExpect(content().string("recovered"))
.andExpect(status().isOk());
this.mvc.perform(get("/error")).andExpect(content().string("recovered")).andExpect(status().isOk());
}
@Test
public void shouldRunValidationSuccess() throws Exception {
this.mvc.perform(get("/three/OK")).andExpect(status().isOk())
.andExpect(content().string("Hello OK"));
this.mvc.perform(get("/three/OK")).andExpect(status().isOk()).andExpect(content().string("Hello OK"));
}
@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.
@@ -47,8 +47,7 @@ public class WebMvcTestConverterIntegrationTests {
@Test
public void shouldFindConverter() throws Exception {
String id = UUID.randomUUID().toString();
this.mvc.perform(get("/two/" + id)).andExpect(content().string(id + "two"))
.andExpect(status().isOk());
this.mvc.perform(get("/two/" + id)).andExpect(content().string(id + "two")).andExpect(status().isOk());
}
}

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,14 +44,14 @@ public class WebMvcTestHateoasIntegrationTests {
@Test
public void plainResponse() throws Exception {
this.mockMvc.perform(get("/hateoas/plain")).andExpect(header()
.string(HttpHeaders.CONTENT_TYPE, "application/json;charset=UTF-8"));
this.mockMvc.perform(get("/hateoas/plain"))
.andExpect(header().string(HttpHeaders.CONTENT_TYPE, "application/json;charset=UTF-8"));
}
@Test
public void hateoasResponse() throws Exception {
this.mockMvc.perform(get("/hateoas/resource")).andExpect(header()
.string(HttpHeaders.CONTENT_TYPE, "application/hal+json;charset=UTF-8"));
this.mockMvc.perform(get("/hateoas/resource"))
.andExpect(header().string(HttpHeaders.CONTENT_TYPE, "application/hal+json;charset=UTF-8"));
}
}

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 WebMvcTestOneControllerIntegrationTests {
@Test
public void shouldFindController2() throws Exception {
this.mvc.perform(get("/two")).andExpect(content().string("hellotwo"))
.andExpect(status().isOk());
this.mvc.perform(get("/two")).andExpect(content().string("hellotwo")).andExpect(status().isOk());
}
}

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,8 @@ public class WebMvcTestPageableIntegrationTests {
@Test
public void shouldSupportPageable() throws Exception {
this.mvc.perform(get("/paged").param("page", "2").param("size", "42"))
.andExpect(status().isOk()).andExpect(content().string("2:42"));
this.mvc.perform(get("/paged").param("page", "2").param("size", "42")).andExpect(status().isOk())
.andExpect(content().string("2:42"));
}
}

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,7 @@ public class WebMvcTestPrintAlwaysIntegrationTests {
@Test
public void shouldPrint() throws Exception {
this.mvc.perform(get("/one")).andExpect(content().string("one"))
.andExpect(status().isOk());
this.mvc.perform(get("/one")).andExpect(content().string("one")).andExpect(status().isOk());
assertThat(this.output.toString()).contains("Request URI = /one");
}

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.
@@ -45,14 +45,12 @@ public class WebMvcTestPrintDefaultIntegrationTests {
@Test
public void shouldNotPrint() throws Exception {
this.mvc.perform(get("/one")).andExpect(content().string("one"))
.andExpect(status().isOk());
this.mvc.perform(get("/one")).andExpect(content().string("one")).andExpect(status().isOk());
}
@Test
public void shouldPrint() throws Exception {
this.mvc.perform(get("/one")).andExpect(content().string("none"))
.andExpect(status().isOk());
this.mvc.perform(get("/one")).andExpect(content().string("none")).andExpect(status().isOk());
}
}

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,7 @@ public class WebMvcTestPrintDefaultOverrideIntegrationTests {
@Test
public void shouldFindController1() throws Exception {
this.mvc.perform(get("/one")).andExpect(content().string("one"))
.andExpect(status().isOk());
this.mvc.perform(get("/one")).andExpect(content().string("one")).andExpect(status().isOk());
assertThat(this.output.toString()).doesNotContain("Request URI = /one");
}

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.
@@ -53,8 +53,7 @@ public class WebMvcTestPrintOverrideIntegrationTests {
@Test
public void shouldNotPrint() throws Exception {
this.mvc.perform(get("/one")).andExpect(content().string("one"))
.andExpect(status().isOk());
this.mvc.perform(get("/one")).andExpect(content().string("one")).andExpect(status().isOk());
assertThat(this.output.toString()).doesNotContain("Request URI = /one");
}

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,10 +51,8 @@ public class WebMvcTestServletFilterRegistrationDisabledIntegrationTests {
static class DisabledRegistrationConfiguration {
@Bean
public FilterRegistrationBean<ExampleFilter> exampleFilterRegistration(
ExampleFilter filter) {
FilterRegistrationBean<ExampleFilter> registration = new FilterRegistrationBean<>(
filter);
public FilterRegistrationBean<ExampleFilter> exampleFilterRegistration(ExampleFilter filter) {
FilterRegistrationBean<ExampleFilter> registration = new FilterRegistrationBean<>(filter);
registration.setEnabled(false);
return registration;
}

View File

@@ -62,8 +62,7 @@ public class WebMvcTestWebDriverIntegrationTests {
this.webDriver.get("/html");
WebElement element = this.webDriver.findElement(By.tagName("body"));
assertThat(element.getText()).isEqualTo("Hello");
assertThatExceptionOfType(NoSuchWindowException.class)
.isThrownBy(previousWebDriver::getWindowHandle);
assertThatExceptionOfType(NoSuchWindowException.class).isThrownBy(previousWebDriver::getWindowHandle);
assertThat(previousWebDriver).isNotNull().isNotSameAs(this.webDriver);
}

View File

@@ -41,8 +41,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
*/
@RunWith(SpringRunner.class)
@WebMvcTest
@AutoConfigureMockMvc(addFilters = false, webClientEnabled = false,
webDriverEnabled = false)
@AutoConfigureMockMvc(addFilters = false, webClientEnabled = false, webDriverEnabled = false)
public class WebMvcTestWithAutoConfigureMockMvcIntegrationTests {
@Autowired