diff --git a/core/pom.xml b/core/pom.xml index fea559f..fafa8f2 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -60,7 +60,7 @@ classes true - true + false **/*It.java **/*Test.java diff --git a/core/src/main/java/com/github/dbunit/rules/DBUnitRule.java b/core/src/main/java/com/github/dbunit/rules/DBUnitRule.java index 4f27c17..6cda678 100644 --- a/core/src/main/java/com/github/dbunit/rules/DBUnitRule.java +++ b/core/src/main/java/com/github/dbunit/rules/DBUnitRule.java @@ -27,19 +27,19 @@ public class DBUnitRule implements MethodRule { private DBUnitRule() { } - public final synchronized static DBUnitRule instance(Connection connection) { + public final static DBUnitRule instance(Connection connection) { return instance(new ConnectionHolderImpl(connection)); } - public final synchronized static DBUnitRule instance(String executorName, Connection connection) { + public final static DBUnitRule instance(String executorName, Connection connection) { return instance(executorName,new ConnectionHolderImpl(connection)); } - public final synchronized static DBUnitRule instance(ConnectionHolder connectionHolder) { + public final static DBUnitRule instance(ConnectionHolder connectionHolder) { return instance(DataSetExecutorImpl.DEFAULT_EXECUTOR_ID,connectionHolder); } - public final synchronized static DBUnitRule instance(String executorName, ConnectionHolder connectionHolder) { + public final static DBUnitRule instance(String executorName, ConnectionHolder connectionHolder) { DBUnitRule instance = new DBUnitRule(); instance.init(executorName, connectionHolder); diff --git a/core/src/test/java/com/github/dbunit/rules/DBUnitRulesIt.java b/core/src/test/java/com/github/dbunit/rules/DBUnitRulesIt.java index 78b2220..ec768b0 100644 --- a/core/src/test/java/com/github/dbunit/rules/DBUnitRulesIt.java +++ b/core/src/test/java/com/github/dbunit/rules/DBUnitRulesIt.java @@ -2,13 +2,17 @@ import com.github.dbunit.rules.api.dataset.DataSet; import com.github.dbunit.rules.api.dataset.SeedStrategy; +import com.github.dbunit.rules.dataset.DataSetExecutorImpl; import com.github.dbunit.rules.model.Follower; import com.github.dbunit.rules.model.User; +import org.junit.After; +import org.junit.AfterClass; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; +import java.sql.SQLException; import java.util.List; import static org.assertj.core.api.Assertions.assertThat; @@ -127,4 +131,9 @@ public void shouldLoadDataFromMultipleDataSets(){ assertThat(user.getFollowers()).contains(expectedFollower); } + @AfterClass//optional + public static void close() throws SQLException { + DataSetExecutorImpl.getExecutorById(DataSetExecutorImpl.DEFAULT_EXECUTOR_ID).getConnection().close(); + } + } diff --git a/core/src/test/java/com/github/dbunit/rules/MultipleDataSetsIt.java b/core/src/test/java/com/github/dbunit/rules/MultipleDataSetsIt.java index 885940f..3fdc21c 100644 --- a/core/src/test/java/com/github/dbunit/rules/MultipleDataSetsIt.java +++ b/core/src/test/java/com/github/dbunit/rules/MultipleDataSetsIt.java @@ -3,8 +3,11 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; +import java.sql.SQLException; import java.util.List; +import com.github.dbunit.rules.dataset.DataSetExecutorImpl; +import org.junit.AfterClass; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; @@ -36,9 +39,6 @@ public class MultipleDataSetsIt { @Rule public DBUnitRule exec2Rule = DBUnitRule.instance("exec2",emProvider2.getConnection()); - @Rule - public DBUnitRule defaultExecutorRule = DBUnitRule.instance(emProvider.getConnection()); - @Test @DataSet(value = "datasets/yml/users.yml",disableConstraints = true, executorId = "exec1") @@ -148,18 +148,6 @@ public void shouldSeedUserDataSet2() { assertThat(user.getId()).isEqualTo(1); } - @Test - @DataSet(value = "datasets/yml/users.yml") - public void shouldLoadUserFollowersWithDefaultExecutor() { - User user = (User) emProvider.em().createQuery("select u from User u left join fetch u.followers where u.id = 1").getSingleResult(); - assertThat(user).isNotNull(); - assertThat(user.getId()).isEqualTo(1); - assertThat(user.getTweets()).hasSize(1); - assertEquals(user.getTweets().get(0).getContent(), "dbunit rules!"); - assertThat(user.getFollowers()).isNotNull().hasSize(1); - Follower expectedFollower = new Follower(2,1); - assertThat(user.getFollowers()).contains(expectedFollower); - } @Test @DataSet(value = "datasets/yml/users.yml", executorId = "exec1") @@ -241,4 +229,11 @@ public void shouldLoadUsersFromXmlDataset2() { assertThat(user.getFollowers()).contains(expectedFollower); } + + @AfterClass//optional + public static void close() throws SQLException { + DataSetExecutorImpl.getExecutorById("exec1").getConnection().close(); + DataSetExecutorImpl.getExecutorById("exec2").getConnection().close(); + } + }