diff --git a/dropwizard-testing/src/main/java/io/dropwizard/testing/common/DAOTest.java b/dropwizard-testing/src/main/java/io/dropwizard/testing/common/DAOTest.java index 409e8103d43..c31c82890db 100644 --- a/dropwizard-testing/src/main/java/io/dropwizard/testing/common/DAOTest.java +++ b/dropwizard-testing/src/main/java/io/dropwizard/testing/common/DAOTest.java @@ -17,10 +17,6 @@ import java.util.function.Consumer; public class DAOTest { - static { - BootstrapLogging.bootstrap(); - } - @SuppressWarnings("unchecked") public static abstract class Builder> { private String url = "jdbc:h2:mem:" + UUID.randomUUID(); @@ -30,6 +26,7 @@ public static abstract class Builder> { private String hbm2ddlAuto = "create"; private boolean showSql = false; private boolean useSqlComments = false; + private boolean bootstrapLogging = true; private Set> entityClasses = new LinkedHashSet<>(); private Map properties = new HashMap<>(); private Consumer configurationCustomizer = c -> { @@ -65,6 +62,11 @@ public B useSqlComments(boolean useSqlComments) { return (B) this; } + public B bootstrapLogging(boolean value){ + bootstrapLogging = value; + return (B) this; + } + public B addEntityClass(Class entityClass) { this.entityClasses.add(entityClass); return (B) this; @@ -81,6 +83,10 @@ public B customizeConfiguration(Consumer configurationCustomizer) } protected DAOTest buildDAOTest() { + if (bootstrapLogging) { + BootstrapLogging.bootstrap(); + } + final Configuration config = new Configuration(); config.setProperty(AvailableSettings.URL, url); config.setProperty(AvailableSettings.USER, username); diff --git a/dropwizard-testing/src/test/java/io/dropwizard/testing/app/ResourceTestRuleWithoutLoggingBootstrap.java b/dropwizard-testing/src/test/java/io/dropwizard/testing/app/ResourceTestRuleWithoutLoggingBootstrapTest.java similarity index 91% rename from dropwizard-testing/src/test/java/io/dropwizard/testing/app/ResourceTestRuleWithoutLoggingBootstrap.java rename to dropwizard-testing/src/test/java/io/dropwizard/testing/app/ResourceTestRuleWithoutLoggingBootstrapTest.java index 00af5910248..423c8ab6a27 100644 --- a/dropwizard-testing/src/test/java/io/dropwizard/testing/app/ResourceTestRuleWithoutLoggingBootstrap.java +++ b/dropwizard-testing/src/test/java/io/dropwizard/testing/app/ResourceTestRuleWithoutLoggingBootstrapTest.java @@ -6,7 +6,7 @@ import static org.assertj.core.api.Assertions.assertThat; -public class ResourceTestRuleWithoutLoggingBootstrap { +public class ResourceTestRuleWithoutLoggingBootstrapTest { @SuppressWarnings("deprecation") @Rule public final ResourceTestRule resourceTestRule = ResourceTestRule.builder() diff --git a/dropwizard-testing/src/test/java/io/dropwizard/testing/junit/DAOTestRuleWithoutLoggingBootstrapTest.java b/dropwizard-testing/src/test/java/io/dropwizard/testing/junit/DAOTestRuleWithoutLoggingBootstrapTest.java new file mode 100644 index 00000000000..9d1805dde78 --- /dev/null +++ b/dropwizard-testing/src/test/java/io/dropwizard/testing/junit/DAOTestRuleWithoutLoggingBootstrapTest.java @@ -0,0 +1,24 @@ +package io.dropwizard.testing.junit; + +import io.dropwizard.testing.app.TestEntity; +import org.hibernate.SessionFactory; +import org.junit.Rule; +import org.junit.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +public class DAOTestRuleWithoutLoggingBootstrapTest { + @SuppressWarnings("deprecation") + @Rule + public final DAOTestRule daoTestRule = DAOTestRule.newBuilder() + .addEntityClass(TestEntity.class) + .bootstrapLogging(false) + .build(); + + @Test + public void ruleCreatedSessionFactory() { + final SessionFactory sessionFactory = daoTestRule.getSessionFactory(); + + assertThat(sessionFactory).isNotNull(); + } +}