Polish
This commit is contained in:
@@ -95,7 +95,8 @@ public class RabbitAutoConfiguration {
|
||||
@Bean
|
||||
public CachingConnectionFactory rabbitConnectionFactory(
|
||||
RabbitProperties properties,
|
||||
ObjectProvider<ConnectionNameStrategy> connectionNameStrategy) throws Exception {
|
||||
ObjectProvider<ConnectionNameStrategy> connectionNameStrategy)
|
||||
throws Exception {
|
||||
PropertyMapper map = PropertyMapper.get();
|
||||
CachingConnectionFactory factory = new CachingConnectionFactory(
|
||||
getRabbitConnectionFactoryBean(properties).getObject());
|
||||
|
||||
@@ -91,9 +91,8 @@ class DataSourceInitializedPublisher implements BeanPostProcessor {
|
||||
if (this.properties == null) {
|
||||
return true; // better safe than sorry
|
||||
}
|
||||
Supplier<String> defaultDdlAuto = () ->
|
||||
EmbeddedDatabaseConnection.isEmbedded(dataSource) ? "create-drop"
|
||||
: "none";
|
||||
Supplier<String> defaultDdlAuto = () -> EmbeddedDatabaseConnection
|
||||
.isEmbedded(dataSource) ? "create-drop" : "none";
|
||||
Map<String, Object> hibernate = this.properties
|
||||
.getHibernateProperties(new HibernateSettings().ddlAuto(defaultDdlAuto));
|
||||
if (hibernate.containsKey("hibernate.hbm2ddl.auto")) {
|
||||
|
||||
@@ -168,7 +168,8 @@ public class RabbitAutoConfigurationTests {
|
||||
DirectFieldAccessor dfa = new DirectFieldAccessor(connectionFactory);
|
||||
Address[] addresses = (Address[]) dfa.getPropertyValue("addresses");
|
||||
assertThat(addresses).hasSize(1);
|
||||
com.rabbitmq.client.ConnectionFactory rcf = mock(com.rabbitmq.client.ConnectionFactory.class);
|
||||
com.rabbitmq.client.ConnectionFactory rcf = mock(
|
||||
com.rabbitmq.client.ConnectionFactory.class);
|
||||
given(rcf.newConnection(isNull(), eq(addresses), anyString()))
|
||||
.willReturn(mock(Connection.class));
|
||||
dfa.setPropertyValue("rabbitConnectionFactory", rcf);
|
||||
@@ -787,7 +788,7 @@ public class RabbitAutoConfigurationTests {
|
||||
|
||||
@Bean
|
||||
public ConnectionNameStrategy myConnectionNameStrategy() {
|
||||
return c -> "test#" + this.counter.getAndIncrement();
|
||||
return (connectionFactory) -> "test#" + this.counter.getAndIncrement();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -68,8 +68,8 @@ public class CustomHibernateJpaAutoConfigurationTests {
|
||||
+ "org.hibernate.cfg.naming.ImprovedNamingStrategyDelegator")
|
||||
.run((context) -> {
|
||||
JpaProperties bean = context.getBean(JpaProperties.class);
|
||||
Map<String, Object> hibernateProperties = bean.getHibernateProperties(
|
||||
new HibernateSettings());
|
||||
Map<String, Object> hibernateProperties = bean
|
||||
.getHibernateProperties(new HibernateSettings());
|
||||
assertThat(hibernateProperties.get("hibernate.ejb.naming_strategy"))
|
||||
.isNull();
|
||||
});
|
||||
|
||||
@@ -29,7 +29,10 @@ import javax.sql.DataSource;
|
||||
import org.hibernate.boot.model.naming.ImplicitNamingStrategy;
|
||||
import org.hibernate.boot.model.naming.PhysicalNamingStrategy;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy;
|
||||
@@ -57,6 +60,14 @@ public class JpaPropertiesTests {
|
||||
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
.withUserConfiguration(TestConfiguration.class);
|
||||
|
||||
@Mock
|
||||
private Supplier<String> ddlAutoSupplier;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noCustomNamingStrategy() {
|
||||
this.contextRunner.run(assertJpaProperties((properties) -> {
|
||||
@@ -80,8 +91,7 @@ public class JpaPropertiesTests {
|
||||
"spring.jpa.hibernate.naming.physical-strategy:com.example.Physical")
|
||||
.run(assertJpaProperties((properties) -> {
|
||||
Map<String, Object> hibernateProperties = properties
|
||||
.getHibernateProperties(
|
||||
new HibernateSettings());
|
||||
.getHibernateProperties(new HibernateSettings());
|
||||
assertThat(hibernateProperties).contains(
|
||||
entry("hibernate.implicit_naming_strategy",
|
||||
"com.example.Implicit"),
|
||||
@@ -97,9 +107,8 @@ public class JpaPropertiesTests {
|
||||
this.contextRunner.run(assertJpaProperties((properties) -> {
|
||||
ImplicitNamingStrategy implicitStrategy = mock(ImplicitNamingStrategy.class);
|
||||
PhysicalNamingStrategy physicalStrategy = mock(PhysicalNamingStrategy.class);
|
||||
Map<String, Object> hibernateProperties = properties
|
||||
.getHibernateProperties(new HibernateSettings()
|
||||
.implicitNamingStrategy(implicitStrategy)
|
||||
Map<String, Object> hibernateProperties = properties.getHibernateProperties(
|
||||
new HibernateSettings().implicitNamingStrategy(implicitStrategy)
|
||||
.physicalNamingStrategy(physicalStrategy));
|
||||
assertThat(hibernateProperties).contains(
|
||||
entry("hibernate.implicit_naming_strategy", implicitStrategy),
|
||||
@@ -120,10 +129,9 @@ public class JpaPropertiesTests {
|
||||
PhysicalNamingStrategy physicalStrategy = mock(
|
||||
PhysicalNamingStrategy.class);
|
||||
Map<String, Object> hibernateProperties = properties
|
||||
.getHibernateProperties(
|
||||
new HibernateSettings()
|
||||
.implicitNamingStrategy(implicitStrategy)
|
||||
.physicalNamingStrategy(physicalStrategy));
|
||||
.getHibernateProperties(new HibernateSettings()
|
||||
.implicitNamingStrategy(implicitStrategy)
|
||||
.physicalNamingStrategy(physicalStrategy));
|
||||
assertThat(hibernateProperties).contains(
|
||||
entry("hibernate.implicit_naming_strategy", implicitStrategy),
|
||||
entry("hibernate.physical_naming_strategy",
|
||||
@@ -154,12 +162,11 @@ public class JpaPropertiesTests {
|
||||
effectivePhysicalStrategy);
|
||||
};
|
||||
Map<String, Object> hibernateProperties = properties
|
||||
.getHibernateProperties(
|
||||
new HibernateSettings()
|
||||
.implicitNamingStrategy(implicitStrategy)
|
||||
.physicalNamingStrategy(physicalStrategy)
|
||||
.hibernatePropertiesCustomizers(
|
||||
Collections.singleton(customizer)));
|
||||
.getHibernateProperties(new HibernateSettings()
|
||||
.implicitNamingStrategy(implicitStrategy)
|
||||
.physicalNamingStrategy(physicalStrategy)
|
||||
.hibernatePropertiesCustomizers(
|
||||
Collections.singleton(customizer)));
|
||||
assertThat(hibernateProperties).contains(
|
||||
entry("hibernate.implicit_naming_strategy",
|
||||
effectiveImplicitStrategy),
|
||||
@@ -177,8 +184,7 @@ public class JpaPropertiesTests {
|
||||
"spring.jpa.properties.hibernate.physical_naming_strategy:com.example.Physical")
|
||||
.run(assertJpaProperties((properties) -> {
|
||||
Map<String, Object> hibernateProperties = properties
|
||||
.getHibernateProperties(
|
||||
new HibernateSettings());
|
||||
.getHibernateProperties(new HibernateSettings());
|
||||
// You can override them as we don't provide any default
|
||||
assertThat(hibernateProperties).contains(
|
||||
entry("hibernate.implicit_naming_strategy",
|
||||
@@ -207,8 +213,7 @@ public class JpaPropertiesTests {
|
||||
"spring.jpa.hibernate.use-new-id-generator-mappings:false")
|
||||
.run(assertJpaProperties((properties) -> {
|
||||
Map<String, Object> hibernateProperties = properties
|
||||
.getHibernateProperties(
|
||||
new HibernateSettings());
|
||||
.getHibernateProperties(new HibernateSettings());
|
||||
assertThat(hibernateProperties).containsEntry(
|
||||
AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, "false");
|
||||
}));
|
||||
@@ -251,8 +256,7 @@ public class JpaPropertiesTests {
|
||||
|
||||
@Test
|
||||
public void defaultDdlAutoIsNotInvokedIfPropertyIsSet() {
|
||||
this.contextRunner
|
||||
.withPropertyValues("spring.jpa.hibernate.ddl-auto=validate")
|
||||
this.contextRunner.withPropertyValues("spring.jpa.hibernate.ddl-auto=validate")
|
||||
.run(assertDefaultDdlAutoNotInvoked("validate"));
|
||||
}
|
||||
|
||||
@@ -266,13 +270,11 @@ public class JpaPropertiesTests {
|
||||
private ContextConsumer<AssertableApplicationContext> assertDefaultDdlAutoNotInvoked(
|
||||
String expectedDdlAuto) {
|
||||
return assertJpaProperties((properties) -> {
|
||||
Supplier<String> ddlAutoSupplier = mock(Supplier.class);
|
||||
Map<String, Object> hibernateProperties = properties
|
||||
.getHibernateProperties(new HibernateSettings()
|
||||
.ddlAuto(ddlAutoSupplier));
|
||||
assertThat(hibernateProperties).containsEntry(
|
||||
"hibernate.hbm2ddl.auto", expectedDdlAuto);
|
||||
verify(ddlAutoSupplier, never()).get();
|
||||
Map<String, Object> hibernateProperties = properties.getHibernateProperties(
|
||||
new HibernateSettings().ddlAuto(this.ddlAutoSupplier));
|
||||
assertThat(hibernateProperties).containsEntry("hibernate.hbm2ddl.auto",
|
||||
expectedDdlAuto);
|
||||
verify(this.ddlAutoSupplier, never()).get();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -48,11 +48,11 @@ public class ResourcePropertiesBindingTests {
|
||||
"spring.resources.static-locations[3]=classpath:/four",
|
||||
"spring.resources.static-locations[4]=classpath:/five/",
|
||||
"spring.resources.static-locations[5]=classpath:/six")
|
||||
.run(assertResourceProperties((properties) ->
|
||||
assertThat(properties.getStaticLocations()).contains(
|
||||
"classpath:/one/", "classpath:/two/", "classpath:/three/",
|
||||
"classpath:/four/", "classpath:/five/",
|
||||
"classpath:/six/")));
|
||||
.run(assertResourceProperties(
|
||||
(properties) -> assertThat(properties.getStaticLocations())
|
||||
.contains("classpath:/one/", "classpath:/two/",
|
||||
"classpath:/three/", "classpath:/four/",
|
||||
"classpath:/five/", "classpath:/six/")));
|
||||
}
|
||||
|
||||
private ContextConsumer<AssertableApplicationContext> assertResourceProperties(
|
||||
|
||||
@@ -90,9 +90,11 @@ public class ReactiveWebServerFactoryAutoConfigurationTests {
|
||||
@Test
|
||||
public void defaultWebServerIsTomcat() {
|
||||
// Tomcat should be chosen over Netty if the Tomcat library is present.
|
||||
this.contextRunner.withUserConfiguration(HttpHandlerConfiguration.class).run(
|
||||
(context) -> assertThat(context.getBean(ReactiveWebServerFactory.class))
|
||||
.isInstanceOf(TomcatReactiveWebServerFactory.class));
|
||||
this.contextRunner.withUserConfiguration(HttpHandlerConfiguration.class)
|
||||
.withPropertyValues("server.port=0")
|
||||
.run((context) -> assertThat(
|
||||
context.getBean(ReactiveWebServerFactory.class))
|
||||
.isInstanceOf(TomcatReactiveWebServerFactory.class));
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
||||
@@ -812,12 +812,12 @@ public class WebMvcAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void customConfigurerAppliedAfterAutoConfig() {
|
||||
this.contextRunner
|
||||
.withUserConfiguration(CustomConfigurer.class)
|
||||
this.contextRunner.withUserConfiguration(CustomConfigurer.class)
|
||||
.run((context) -> {
|
||||
ContentNegotiationManager manager = context.getBean(ContentNegotiationManager.class);
|
||||
assertThat(manager.getStrategies()).anyMatch(strategy ->
|
||||
WebMvcAutoConfiguration.OptionalPathExtensionContentNegotiationStrategy.class
|
||||
ContentNegotiationManager manager = context
|
||||
.getBean(ContentNegotiationManager.class);
|
||||
assertThat(manager.getStrategies()).anyMatch(
|
||||
strategy -> WebMvcAutoConfiguration.OptionalPathExtensionContentNegotiationStrategy.class
|
||||
.isAssignableFrom(strategy.getClass()));
|
||||
});
|
||||
}
|
||||
@@ -1106,6 +1106,7 @@ public class WebMvcAutoConfigurationTests {
|
||||
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
|
||||
configurer.favorPathExtension(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -67,8 +67,10 @@ public class WelcomePageHandlerMappingTests {
|
||||
public void isOrderedAtLowPriority() {
|
||||
this.contextRunner.withUserConfiguration(StaticResourceConfiguration.class)
|
||||
.run((context) -> {
|
||||
WelcomePageHandlerMapping handler = context.getBean(WelcomePageHandlerMapping.class);
|
||||
assertThat(handler.getOrder()).isEqualTo(Ordered.LOWEST_PRECEDENCE - 1);
|
||||
WelcomePageHandlerMapping handler = context
|
||||
.getBean(WelcomePageHandlerMapping.class);
|
||||
assertThat(handler.getOrder())
|
||||
.isEqualTo(Ordered.LOWEST_PRECEDENCE - 1);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user