Skip to content

Commit

Permalink
Deprecate JUnit 4.x helper classes
Browse files Browse the repository at this point in the history
  • Loading branch information
joschi committed Mar 2, 2019
1 parent 8a3cc32 commit 923db86
Show file tree
Hide file tree
Showing 17 changed files with 42 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package io.dropwizard.testing;

import java.util.function.Supplier;
import io.dropwizard.testing.junit.DropwizardAppRule;

/**
* An override for a field in dropwizard configuration intended for use with
* {@link DropwizardAppRule}.
* {@link io.dropwizard.testing.junit5.DropwizardAppExtension}.
* <p>
* Given a configuration file containing
* <pre>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.dropwizard.testing.common;

import io.dropwizard.logging.BootstrapLogging;
import io.dropwizard.testing.junit.DAOTestRule;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
Expand Down Expand Up @@ -113,7 +112,7 @@ protected DAOTest buildDAOTest() {
private final SessionFactory sessionFactory;

/**
* Use {@link DAOTestRule#newBuilder()}
* Use {@link io.dropwizard.testing.junit5.DAOTestExtension#newBuilder()}
*/
private DAOTest(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@ public void createPerson() {
}
* </code></pre>
* </p>
*
* @deprecated Deprecated since Dropwizard 2.0.0. Please migrate to JUnit 5 and {@link io.dropwizard.testing.junit5.DAOTestExtension}.
*/
//@formatter:on
@Deprecated
public class DAOTestRule extends ExternalResource {
private final DAOTest daoTest;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
* started and stopped once, regardless of whether the entire suite or a single test is executed.
* </p>
*
* <p>
* <pre>
* public class FooTest {
* &#064;ClassRule public static final DropwizardAppRule&lt;MyConfig> DROPWIZARD = MySuite.DROPWIZARD;
Expand All @@ -62,14 +63,14 @@
* public void testBar() { ... }
* }
* </pre>
*
* <p>
*
* </p>
*
* @param <C> the configuration type
*
* @deprecated Deprecated since Dropwizard 2.0.0. Please migrate to JUnit 5 and {@link io.dropwizard.testing.junit5.DropwizardAppExtension}.
*/
//@formatter:on
@Deprecated
public class DropwizardAppRule<C extends Configuration> extends ExternalResource {

private static final int DEFAULT_CONNECT_TIMEOUT_MS = 1000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,11 @@ public void shouldPing() throws IOException {
* <li>Stopping the application.</li>
* </ul>
* </p>
*
* @deprecated Deprecated since Dropwizard 2.0.0. Please migrate to JUnit 5 and {@link io.dropwizard.testing.junit5.DropwizardClientExtension}.
*/
//@formatter:off
@Deprecated
public class DropwizardClientRule extends ExternalResource {
private final DropwizardClient client;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@
* @see org.junit.rules.RuleChain
* @see <a href="https://github.com/junit-team/junit4/issues/351">#351: missing current instance in TestRule apply()</a>
* @see <a href="https://github.com/mockito/mockito/issues/997">#997: ClassRule/TestRule version of Mockito's JUnitRule</a>
*
* @deprecated Deprecated since Dropwizard 2.0.0. Please migrate to JUnit 5.
*/
@Deprecated
public class MockitoTestRule implements TestRule {
private final Object testInstance;
private final MockitoRule delegate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@

/**
* A JUnit {@link TestRule} for testing Jersey resources.
*
* @deprecated Deprecated since Dropwizard 2.0.0. Please migrate to JUnit 5 and {@link io.dropwizard.testing.junit5.ResourceExtension}.
*/
@Deprecated
public class ResourceTestRule implements TestRule {
/**
* A {@link ResourceTestRule} builder which enables configuration of a Jersey testing environment.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.dropwizard.testing.junit5;

import io.dropwizard.testing.common.DAOTest;
import io.dropwizard.testing.junit.DAOTestRule;
import org.hibernate.SessionFactory;

import java.util.concurrent.Callable;
Expand Down Expand Up @@ -45,17 +44,17 @@ public DAOTestExtension build() {
}

/**
* Creates a new builder for {@link DAOTestRule}, which allows to customize a {@link SessionFactory}
* Creates a new builder for {@link DAOTestExtension}, which allows to customize a {@link SessionFactory}
* by different parameters. By default uses the H2 database in the memory mode.
*
* @return a new {@link DAOTestRule.Builder}
* @return a new {@link DAOTestExtension.Builder}
*/
public static Builder newBuilder() {
return new Builder();
}

/**
* Use {@link DAOTestRule#newBuilder()}
* Use {@link DAOTestExtension#newBuilder()}
*/
private DAOTestExtension(DAOTest daoTest) {
this.daoTest = daoTest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import static org.assertj.core.api.Assertions.assertThat;

public class DAOTestRuleConfigTest {

@SuppressWarnings("deprecation")
@Rule
public final DAOTestRule database = DAOTestRule.newBuilder()
.setUrl("jdbc:h2:mem:rule-config-test")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import static org.assertj.core.api.Assertions.failBecauseExceptionWasNotThrown;

public class DAOTestRuleTest {

@SuppressWarnings("deprecation")
@Rule
public final DAOTestRule daoTestRule = DAOTestRule.newBuilder().addEntityClass(TestEntity.class).build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import static org.assertj.core.api.Assertions.assertThat;

public class DropwizardAppRuleConfigOverrideTest {

@SuppressWarnings("deprecation")
@ClassRule
public static final DropwizardAppRule<TestConfiguration> RULE =
new DropwizardAppRule<>(TestApplication.class, resourceFilePath("test-config.yaml"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,33 @@

import io.dropwizard.testing.DropwizardTestSupport;
import io.dropwizard.testing.app.TestConfiguration;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.RuleChain;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;

import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;

public class DropwizardAppRuleReentrantTest {
@Rule
public final MockitoRule mockitoRule = MockitoJUnit.rule();

@SuppressWarnings("unchecked")
DropwizardTestSupport<TestConfiguration> testSupport = mock(DropwizardTestSupport.class);
Statement statement = mock(Statement.class);
Description description = mock(Description.class);
@SuppressWarnings("NullAway")
@Mock
DropwizardTestSupport<TestConfiguration> testSupport;
private Statement statement = mock(Statement.class);
private Description description = mock(Description.class);

@Test
public void testReentrantRuleStartsApplicationOnlyOnce() throws Throwable {
@SuppressWarnings("deprecation")
DropwizardAppRule<TestConfiguration> dropwizardAppRule = new DropwizardAppRule<>(testSupport);

RuleChain.outerRule(dropwizardAppRule)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import static org.assertj.core.api.Assertions.assertThat;

public class DropwizardAppRuleResetConfigOverrideTest {
@SuppressWarnings("deprecation")
private final DropwizardAppRule<TestConfiguration> dropwizardAppRule = new DropwizardAppRule<>(
TestApplication.class,
resourceFilePath("test-config.yaml"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import static org.assertj.core.api.Assertions.assertThat;

public class DropwizardAppRuleTest {

@SuppressWarnings("deprecation")
@ClassRule
public static final DropwizardAppRule<TestConfiguration> RULE =
new DropwizardAppRule<>(DropwizardTestApplication.class, resourceFilePath("test-config.yaml"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.entry;

@SuppressWarnings("deprecation")
public class DropwizardAppRuleWithExplicitTest {

@ClassRule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import static org.assertj.core.api.Assertions.entry;

public class DropwizardAppRuleWithoutConfigTest {

@SuppressWarnings("deprecation")
@ClassRule
public static final DropwizardAppRule<Configuration> RULE = new DropwizardAppRule<>(TestApplication.class, null,
ConfigOverride.config("server.applicationConnectors[0].port", "0"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
import static org.assertj.core.api.Assertions.assertThat;

public class DropwizardClientRuleTest {
@SuppressWarnings("deprecation")
@ClassRule
public static final DropwizardClientRule RULE_WITH_INSTANCE = new DropwizardClientRule(new TestResource("foo"));

@SuppressWarnings("deprecation")
@ClassRule
public static final DropwizardClientRule RULE_WITH_CLASS = new DropwizardClientRule(TestResource.class);

Expand Down

0 comments on commit 923db86

Please sign in to comment.