Polishing

pull/7499/merge
Andy Wilkinson 7 years ago
parent 0fc3e3d166
commit 5616915621

@ -62,8 +62,7 @@ public class ElasticsearchAutoConfigurationTests {
PropertyPlaceholderAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class,
ElasticsearchAutoConfiguration.class); ElasticsearchAutoConfiguration.class);
this.context.refresh(); this.context.refresh();
assertThat(this.context.getBeanNamesForType(Client.class).length) assertThat(this.context.getBeanNamesForType(Client.class).length).isEqualTo(1);
.isEqualTo(1);
assertThat(this.context.getBean("myClient")) assertThat(this.context.getBean("myClient"))
.isSameAs(this.context.getBean(Client.class)); .isSameAs(this.context.getBean(Client.class));
} }

@ -63,8 +63,8 @@ public class Neo4jDataAutoConfigurationTests {
public void defaultConfiguration() { public void defaultConfiguration() {
this.context.withPropertyValues("spring.data.neo4j.uri=http://localhost:8989") this.context.withPropertyValues("spring.data.neo4j.uri=http://localhost:8989")
.run((loaded) -> { .run((loaded) -> {
assertThat(loaded).hasSingleBean( assertThat(loaded)
org.neo4j.ogm.config.Configuration.class); .hasSingleBean(org.neo4j.ogm.config.Configuration.class);
assertThat(loaded).hasSingleBean(SessionFactory.class); assertThat(loaded).hasSingleBean(SessionFactory.class);
assertThat(loaded).hasSingleBean(Neo4jTransactionManager.class); assertThat(loaded).hasSingleBean(Neo4jTransactionManager.class);
assertThat(loaded).hasSingleBean(OpenSessionInViewInterceptor.class); assertThat(loaded).hasSingleBean(OpenSessionInViewInterceptor.class);
@ -73,13 +73,15 @@ public class Neo4jDataAutoConfigurationTests {
@Test @Test
public void customNeo4jTransactionManagerUsingProperties() { public void customNeo4jTransactionManagerUsingProperties() {
this.context.withPropertyValues("spring.transaction.default-timeout=30", this.context
"spring.transaction.rollback-on-commit-failure:true").run((loaded) -> { .withPropertyValues("spring.transaction.default-timeout=30",
Neo4jTransactionManager transactionManager = loaded "spring.transaction.rollback-on-commit-failure:true")
.getBean(Neo4jTransactionManager.class); .run((loaded) -> {
assertThat(transactionManager.getDefaultTimeout()).isEqualTo(30); Neo4jTransactionManager transactionManager = loaded
assertThat(transactionManager.isRollbackOnCommitFailure()).isTrue(); .getBean(Neo4jTransactionManager.class);
}); assertThat(transactionManager.getDefaultTimeout()).isEqualTo(30);
assertThat(transactionManager.isRollbackOnCommitFailure()).isTrue();
});
} }
@Test @Test
@ -121,8 +123,8 @@ public class Neo4jDataAutoConfigurationTests {
@Test @Test
public void openSessionInViewInterceptorCanBeDisabled() { public void openSessionInViewInterceptorCanBeDisabled() {
this.context.withPropertyValues("spring.data.neo4j.open-in-view:false") this.context.withPropertyValues("spring.data.neo4j.open-in-view:false")
.run((loaded) -> assertThat(loaded).doesNotHaveBean( .run((loaded) -> assertThat(loaded)
OpenSessionInViewInterceptor.class)); .doesNotHaveBean(OpenSessionInViewInterceptor.class));
} }
@Test @Test
@ -130,7 +132,8 @@ public class Neo4jDataAutoConfigurationTests {
this.context.withUserConfiguration(EventListenerConfiguration.class) this.context.withUserConfiguration(EventListenerConfiguration.class)
.run((loaded) -> { .run((loaded) -> {
Session session = loaded.getBean(SessionFactory.class).openSession(); Session session = loaded.getBean(SessionFactory.class).openSession();
session.notifyListeners(new PersistenceEvent(null, Event.TYPE.PRE_SAVE)); session.notifyListeners(
new PersistenceEvent(null, Event.TYPE.PRE_SAVE));
verify(loaded.getBean("eventListenerOne", EventListener.class)) verify(loaded.getBean("eventListenerOne", EventListener.class))
.onPreSave(any(Event.class)); .onPreSave(any(Event.class));
verify(loaded.getBean("eventListenerTwo", EventListener.class)) verify(loaded.getBean("eventListenerTwo", EventListener.class))

@ -123,7 +123,7 @@ public class HazelcastAutoConfigurationClientTests {
} }
private Condition<HazelcastInstance> nameStartingWith(String prefix) { private Condition<HazelcastInstance> nameStartingWith(String prefix) {
return new Condition<HazelcastInstance>((o) -> o.getName().startsWith(prefix), return new Condition<>((o) -> o.getName().startsWith(prefix),
"Name starts with " + prefix); "Name starts with " + prefix);
} }

@ -46,16 +46,17 @@ public class InfluxDbAutoConfigurationTests {
@Test @Test
public void influxDbRequiresUrl() { public void influxDbRequiresUrl() {
this.context.run((loaded) -> this.context.run(
assertThat(loaded.getBeansOfType(InfluxDB.class)).isEmpty()); (loaded) -> assertThat(loaded.getBeansOfType(InfluxDB.class)).isEmpty());
} }
@Test @Test
public void influxDbCanBeCustomized() { public void influxDbCanBeCustomized() {
this.context.withPropertyValues("spring.influx.url=http://localhost", this.context
"spring.influx.password:password", "spring.influx.user:user") .withPropertyValues("spring.influx.url=http://localhost",
.run((loaded -> "spring.influx.password:password", "spring.influx.user:user")
assertThat(loaded.getBeansOfType(InfluxDB.class)).hasSize(1))); .run((loaded -> assertThat(loaded.getBeansOfType(InfluxDB.class))
.hasSize(1)));
} }
@Test @Test
@ -71,11 +72,12 @@ public class InfluxDbAutoConfigurationTests {
@Test @Test
public void influxDbWithoutCredentialsAndOkHttpClientBuilder() { public void influxDbWithoutCredentialsAndOkHttpClientBuilder() {
this.context.withUserConfiguration(CustomOkHttpClientBuilderConfig.class) this.context.withUserConfiguration(CustomOkHttpClientBuilderConfig.class)
.withPropertyValues("spring.influx.url=http://localhost").run((loaded) -> { .withPropertyValues("spring.influx.url=http://localhost")
assertThat(loaded.getBeansOfType(InfluxDB.class)).hasSize(1); .run((loaded) -> {
int readTimeout = getReadTimeoutProperty(loaded); assertThat(loaded.getBeansOfType(InfluxDB.class)).hasSize(1);
assertThat(readTimeout).isEqualTo(30_000); int readTimeout = getReadTimeoutProperty(loaded);
}); assertThat(readTimeout).isEqualTo(30_000);
});
} }
@Test @Test

@ -126,8 +126,7 @@ public class KafkaAutoConfigurationTests {
public void producerProperties() { public void producerProperties() {
load("spring.kafka.clientId=cid", load("spring.kafka.clientId=cid",
"spring.kafka.properties.foo.bar.baz=qux.fiz.buz", "spring.kafka.properties.foo.bar.baz=qux.fiz.buz",
"spring.kafka.producer.acks=all", "spring.kafka.producer.acks=all", "spring.kafka.producer.batch-size=20",
"spring.kafka.producer.batch-size=20",
"spring.kafka.producer.bootstrap-servers=bar:1234", // test override "spring.kafka.producer.bootstrap-servers=bar:1234", // test override
"spring.kafka.producer.buffer-memory=12345", "spring.kafka.producer.buffer-memory=12345",
"spring.kafka.producer.compression-type=gzip", "spring.kafka.producer.compression-type=gzip",

@ -87,8 +87,7 @@ public class RemoteClientConfigurationTests {
@Test @Test
public void warnIfRestartDisabled() throws Exception { public void warnIfRestartDisabled() throws Exception {
configure("spring.devtools.remote.restart.enabled:false"); configure("spring.devtools.remote.restart.enabled:false");
assertThat(this.output.toString()) assertThat(this.output.toString()).contains("Remote restart is disabled");
.contains("Remote restart is disabled");
} }
@Test @Test

@ -134,8 +134,8 @@ class AssertProviderApplicationContextInvocationHandler implements InvocationHan
} }
private Object getAssertThat(Object proxy) { private Object getAssertThat(Object proxy) {
return new ApplicationContextAssert<ApplicationContext>( return new ApplicationContextAssert<>((ApplicationContext) proxy,
(ApplicationContext) proxy, this.startupFailure); this.startupFailure);
} }
private boolean isCloseMethod(Method method) { private boolean isCloseMethod(Method method) {

@ -20,8 +20,8 @@ import java.net.URL;
import java.net.URLClassLoader; import java.net.URLClassLoader;
/** /**
* Test {@link URLClassLoader} that hides configurable packages. No class * Test {@link URLClassLoader} that hides configurable packages. No class in one of those
* in one of those packages or sub-packages are visible. * packages or sub-packages are visible.
* *
* @author Andy Wilkinson * @author Andy Wilkinson
* @author Stephane Nicoll * @author Stephane Nicoll

@ -53,7 +53,8 @@ public class NoUnboundElementsBindHandler extends AbstractBindHandler {
this(parent, (configurationPropertySource) -> true); this(parent, (configurationPropertySource) -> true);
} }
public NoUnboundElementsBindHandler(BindHandler parent, Function<ConfigurationPropertySource, Boolean> filter) { public NoUnboundElementsBindHandler(BindHandler parent,
Function<ConfigurationPropertySource, Boolean> filter) {
super(parent); super(parent);
this.filter = filter; this.filter = filter;
} }
@ -77,7 +78,8 @@ public class NoUnboundElementsBindHandler extends AbstractBindHandler {
BindContext context) { BindContext context) {
Set<ConfigurationProperty> unbound = new TreeSet<>(); Set<ConfigurationProperty> unbound = new TreeSet<>();
for (ConfigurationPropertySource source : context.getSources()) { for (ConfigurationPropertySource source : context.getSources()) {
if (source instanceof IterableConfigurationPropertySource && this.filter.apply(source)) { if (source instanceof IterableConfigurationPropertySource
&& this.filter.apply(source)) {
collectUnbound(name, unbound, collectUnbound(name, unbound,
(IterableConfigurationPropertySource) source); (IterableConfigurationPropertySource) source);
} }

@ -26,19 +26,21 @@ import org.springframework.core.env.PropertySource;
import org.springframework.core.env.StandardEnvironment; import org.springframework.core.env.StandardEnvironment;
/** /**
* Function used to determine if a {@link ConfigurationPropertySource} should be * Function used to determine if a {@link ConfigurationPropertySource} should be included
* included when determining unbound elements. If the underlying {@link PropertySource} * when determining unbound elements. If the underlying {@link PropertySource} is a
* is a systemEnvironment or systemProperties property source, it will not be considered * systemEnvironment or systemProperties property source, it will not be considered for
* for unbound element failures. * unbound element failures.
* *
* @author Madhura Bhave * @author Madhura Bhave
* @since 2.0.0 * @since 2.0.0
*/ */
public class UnboundElementsSourceFilter implements Function<ConfigurationPropertySource, Boolean> { public class UnboundElementsSourceFilter
implements Function<ConfigurationPropertySource, Boolean> {
private static final Set<String> BENIGN_PROPERTY_SOURCE_NAMES = Collections.unmodifiableSet(new HashSet<>(Arrays.asList( private static final Set<String> BENIGN_PROPERTY_SOURCE_NAMES = Collections
StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME, .unmodifiableSet(new HashSet<>(Arrays.asList(
StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME))); StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME,
StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME)));
@Override @Override
public Boolean apply(ConfigurationPropertySource configurationPropertySource) { public Boolean apply(ConfigurationPropertySource configurationPropertySource) {
@ -52,4 +54,3 @@ public class UnboundElementsSourceFilter implements Function<ConfigurationProper
} }
} }

@ -156,8 +156,8 @@ public class JettyReactiveWebServerFactory extends AbstractReactiveWebServerFact
} }
/** /**
* Returns a mutable collection of Jetty {@link JettyServerCustomizer}s that will be applied * Returns a mutable collection of Jetty {@link JettyServerCustomizer}s that will be
* to the {@link Server} before it is created. * applied to the {@link Server} before it is created.
* @return the Jetty customizers * @return the Jetty customizers
*/ */
public Collection<JettyServerCustomizer> getServerCustomizers() { public Collection<JettyServerCustomizer> getServerCustomizers() {

@ -117,7 +117,8 @@ public class UndertowReactiveWebServerFactory extends AbstractReactiveWebServerF
/** /**
* Set {@link UndertowBuilderCustomizer}s that should be applied to the Undertow * Set {@link UndertowBuilderCustomizer}s that should be applied to the Undertow
* {@link Undertow.Builder}. Calling this method will replace any existing customizers. * {@link Undertow.Builder}. Calling this method will replace any existing
* customizers.
* @param customizers the customizers to set * @param customizers the customizers to set
*/ */
public void setBuilderCustomizers( public void setBuilderCustomizers(

@ -482,7 +482,7 @@ public class UndertowServletWebServerFactory extends AbstractServletWebServerFac
File docBase = getCanonicalDocumentRoot(root); File docBase = getCanonicalDocumentRoot(root);
List<URL> metaInfResourceUrls = getUrlsOfJarsWithMetaInfResources(); List<URL> metaInfResourceUrls = getUrlsOfJarsWithMetaInfResources();
List<URL> resourceJarUrls = new ArrayList<>(); List<URL> resourceJarUrls = new ArrayList<>();
List<ResourceManager> resourceManagers = new ArrayList<ResourceManager>(); List<ResourceManager> resourceManagers = new ArrayList<>();
ResourceManager rootResourceManager = docBase.isDirectory() ResourceManager rootResourceManager = docBase.isDirectory()
? new FileResourceManager(docBase, 0) : new JarResourceManager(docBase); ? new FileResourceManager(docBase, 0) : new JarResourceManager(docBase);
resourceManagers.add(root == null ? rootResourceManager resourceManagers.add(root == null ? rootResourceManager

@ -44,15 +44,19 @@ public class UnboundElementsSourceFilterTests {
} }
@Test @Test
public void filterWhenSourceIsSystemEnvironmentPropertySourceShouldReturnFalse() throws Exception { public void filterWhenSourceIsSystemEnvironmentPropertySourceShouldReturnFalse()
MockPropertySource propertySource = new MockPropertySource(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME); throws Exception {
MockPropertySource propertySource = new MockPropertySource(
StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME);
given(this.source.getUnderlyingSource()).willReturn(propertySource); given(this.source.getUnderlyingSource()).willReturn(propertySource);
assertThat(this.filter.apply(this.source)).isFalse(); assertThat(this.filter.apply(this.source)).isFalse();
} }
@Test @Test
public void filterWhenSourceIsSystemPropertiesPropertySourceShouldReturnTrue() throws Exception { public void filterWhenSourceIsSystemPropertiesPropertySourceShouldReturnTrue()
MockPropertySource propertySource = new MockPropertySource(StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME); throws Exception {
MockPropertySource propertySource = new MockPropertySource(
StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME);
given(this.source.getUnderlyingSource()).willReturn(propertySource); given(this.source.getUnderlyingSource()).willReturn(propertySource);
assertThat(this.filter.apply(this.source)).isFalse(); assertThat(this.filter.apply(this.source)).isFalse();
} }

Loading…
Cancel
Save