From 4b1389179dda83097f2abd1455b1d7ef1beed361 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Fri, 2 Oct 2015 10:52:03 +0100 Subject: [PATCH] Attempt to fix test failures caused by ordering issues --- .../health/DataSourceHealthIndicatorTests.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/DataSourceHealthIndicatorTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/DataSourceHealthIndicatorTests.java index 563382739b..39af41d647 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/DataSourceHealthIndicatorTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/DataSourceHealthIndicatorTests.java @@ -20,12 +20,12 @@ import java.sql.Connection; import javax.sql.DataSource; +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.springframework.boot.actuate.health.DataSourceHealthIndicator.Product; import org.springframework.boot.autoconfigure.jdbc.EmbeddedDatabaseConnection; import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.jdbc.datasource.DriverManagerDataSource; import org.springframework.jdbc.datasource.SingleConnectionDataSource; import static org.hamcrest.Matchers.equalTo; @@ -48,15 +48,23 @@ public class DataSourceHealthIndicatorTests { private final DataSourceHealthIndicator indicator = new DataSourceHealthIndicator(); - private DriverManagerDataSource dataSource; + private SingleConnectionDataSource dataSource; @Before public void init() { EmbeddedDatabaseConnection db = EmbeddedDatabaseConnection.HSQL; - this.dataSource = new SingleConnectionDataSource(db.getUrl(), "sa", "", false); + this.dataSource = new SingleConnectionDataSource(db.getUrl() + ";shutdown=true", + "sa", "", false); this.dataSource.setDriverClassName(db.getDriverClassName()); } + @After + public void close() { + if (this.dataSource != null) { + this.dataSource.destroy(); + } + } + @Test public void database() { this.indicator.setDataSource(this.dataSource); @@ -91,8 +99,8 @@ public class DataSourceHealthIndicatorTests { public void connectionClosed() throws Exception { DataSource dataSource = mock(DataSource.class); Connection connection = mock(Connection.class); - given(connection.getMetaData()).willReturn( - this.dataSource.getConnection().getMetaData()); + given(connection.getMetaData()) + .willReturn(this.dataSource.getConnection().getMetaData()); given(dataSource.getConnection()).willReturn(connection); this.indicator.setDataSource(dataSource); Health health = this.indicator.health();