Merge branch '1.5.x'

This commit is contained in:
Stephane Nicoll 2017-10-25 13:59:54 +02:00
commit b23f68b0d5
2 changed files with 18 additions and 1 deletions

View File

@ -16,9 +16,12 @@
package org.springframework.boot.autoconfigure.jdbc;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.boot.jdbc.EmbeddedDatabaseConnection;
import org.springframework.boot.test.context.HidePackagesClassLoader;
import static org.assertj.core.api.Assertions.assertThat;
@ -31,6 +34,9 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
public class DataSourcePropertiesTests {
@Rule
public final ExpectedException thrown = ExpectedException.none();
@Test
public void determineDriver() {
DataSourceProperties properties = new DataSourceProperties();
@ -59,6 +65,17 @@ public class DataSourcePropertiesTests {
.isEqualTo(EmbeddedDatabaseConnection.H2.getUrl());
}
@Test
public void determineUrlWithNoEmbeddedSupport() throws Exception {
DataSourceProperties properties = new DataSourceProperties();
properties.setBeanClassLoader(new HidePackagesClassLoader("org.h2",
"org.apache.derby", "org.hsqldb"));
properties.afterPropertiesSet();
this.thrown.expect(DataSourceProperties.DataSourceBeanCreationException.class);
this.thrown.expectMessage("Cannot determine embedded database url");
properties.determineUrl();
}
@Test
public void determineUrlWithExplicitConfig() throws Exception {
DataSourceProperties properties = new DataSourceProperties();

View File

@ -106,7 +106,7 @@ public enum EmbeddedDatabaseConnection {
*/
public String getUrl(String databaseName) {
Assert.hasText(databaseName, "DatabaseName must not be null.");
return String.format(this.url, databaseName);
return this.url != null ? String.format(this.url, databaseName) : null;
}
/**