From 4f7107aeb2b7a6f93135a7cb25f4843347b0d401 Mon Sep 17 00:00:00 2001 From: David Schlosnagle Date: Fri, 11 Nov 2022 08:53:25 -0500 Subject: [PATCH 1/4] Mirgrate from JUnit 4 to JUnit 5 --- dialogue-client-verifier/build.gradle | 5 +- .../verification/AutoDeserializeTest.java | 77 ++++++++----------- .../verification/SingleParamServicesTest.java | 53 ++++++------- ....java => VerificationServerExtension.java} | 12 +-- versions.props | 2 - 5 files changed, 62 insertions(+), 87 deletions(-) rename dialogue-client-verifier/src/test/java/com/palantir/verification/{VerificationServerRule.java => VerificationServerExtension.java} (91%) diff --git a/dialogue-client-verifier/build.gradle b/dialogue-client-verifier/build.gradle index d7861102d..3f558403f 100644 --- a/dialogue-client-verifier/build.gradle +++ b/dialogue-client-verifier/build.gradle @@ -30,7 +30,6 @@ dependencies { testImplementation project('verification-server-api') testImplementation project(':dialogue-clients') testImplementation project(':dialogue-example:dialogue-example-dialogue') - testImplementation 'junit:junit' testImplementation 'org.assertj:assertj-core' testImplementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml' testImplementation 'com.palantir.conjure.java.runtime:conjure-java-jackson-serialization' @@ -42,9 +41,7 @@ dependencies { testRuntimeOnly 'org.apache.logging.log4j:log4j-core' testImplementation 'com.palantir.safe-logging:logger' testImplementation 'org.junit.jupiter:junit-jupiter' - testRuntimeOnly 'org.junit.vintage:junit-vintage-engine', { - because 'allows JUnit 3 and JUnit 4 tests to run' - } + testImplementation 'org.junit.jupiter:junit-jupiter-api' } subprojects { diff --git a/dialogue-client-verifier/src/test/java/com/palantir/verification/AutoDeserializeTest.java b/dialogue-client-verifier/src/test/java/com/palantir/verification/AutoDeserializeTest.java index 65f874143..4ad1fe17b 100644 --- a/dialogue-client-verifier/src/test/java/com/palantir/verification/AutoDeserializeTest.java +++ b/dialogue-client-verifier/src/test/java/com/palantir/verification/AutoDeserializeTest.java @@ -30,17 +30,16 @@ import java.util.List; import java.util.Optional; import java.util.stream.IntStream; -import org.junit.Assume; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.api.Assumptions; +import org.junit.jupiter.api.extension.RegisterExtension; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; -@RunWith(Parameterized.class) public class AutoDeserializeTest { - @ClassRule - public static final VerificationServerRule server = new VerificationServerRule(); + @RegisterExtension + public static final VerificationServerExtension server = new VerificationServerExtension(); private static final SafeLogger log = SafeLoggerFactory.get(AutoDeserializeTest.class); private static final AutoDeserializeServiceBlocking testService = @@ -48,61 +47,49 @@ public class AutoDeserializeTest { private static final AutoDeserializeConfirmServiceBlocking confirmService = server.client(AutoDeserializeConfirmServiceBlocking.class); - @Parameterized.Parameter(0) - public EndpointName endpointName; - - @Parameterized.Parameter(1) - public int index; - - @Parameterized.Parameter(2) - public boolean shouldSucceed; - - @Parameterized.Parameter(3) - public String jsonString; - - @Parameterized.Parameters(name = "{0}({3}) -> should succeed {2}") - public static Collection data() { - List objects = new ArrayList<>(); + public static Collection data() { + List objects = new ArrayList<>(); Cases.TEST_CASES.getAutoDeserialize().forEach((endpointName, positiveAndNegativeTestCases) -> { int positiveSize = positiveAndNegativeTestCases.getPositive().size(); int negativeSize = positiveAndNegativeTestCases.getNegative().size(); IntStream.range(0, positiveSize) - .forEach(i -> objects.add(new Object[] { - endpointName, - i, - true, - positiveAndNegativeTestCases.getPositive().get(i) - })); + .forEach(i -> objects.add(Arguments.of( + endpointName, + i, + true, + positiveAndNegativeTestCases.getPositive().get(i)))); IntStream.range(0, negativeSize) - .forEach(i -> objects.add(new Object[] { - endpointName, - positiveSize + i, - false, - positiveAndNegativeTestCases.getNegative().get(i) - })); + .forEach(i -> objects.add(Arguments.of( + endpointName, + positiveSize + i, + false, + positiveAndNegativeTestCases.getNegative().get(i)))); }); return objects; } - @Test + @ParameterizedTest(name = "{0}({3}) -> should succeed {2}") + @MethodSource("data") @SuppressWarnings("IllegalThrows") - public void runTestCase() throws Error, NoSuchMethodException { + public void runTestCase(EndpointName endpointName, int index, boolean shouldSucceed, String jsonString) + throws Error, NoSuchMethodException { boolean shouldIgnore = Cases.shouldIgnore(endpointName, jsonString); Method method = testService.getClass().getMethod(endpointName.get(), int.class); // Need to set accessible true work around dialogues anonymous class impl method.setAccessible(true); - System.out.println(String.format( - "[%s%s test case %s]: %s(%s), expected client to %s", + System.out.printf( + "[%s%s test case %s]: %s(%s), expected client to %s%n", shouldIgnore ? "ignored " : "", shouldSucceed ? "positive" : "negative", index, endpointName, jsonString, - shouldSucceed ? "succeed" : "fail")); + shouldSucceed ? "succeed" : "fail"); - Optional expectationFailure = shouldSucceed ? expectSuccess(method) : expectFailure(method); + Optional expectationFailure = + shouldSucceed ? expectSuccess(method, endpointName, index) : expectFailure(method, index); if (shouldIgnore) { assertThat(expectationFailure) @@ -111,14 +98,14 @@ public void runTestCase() throws Error, NoSuchMethodException { .isNotEmpty(); } - Assume.assumeFalse(shouldIgnore); + Assumptions.assumeFalse(shouldIgnore); if (expectationFailure.isPresent()) { throw expectationFailure.get(); } } - private Optional expectSuccess(Method method) { + private Optional expectSuccess(Method method, EndpointName endpointName, int index) { try { Object resultFromServer = method.invoke(testService, index); log.info( @@ -133,13 +120,13 @@ private Optional expectSuccess(Method method) { } } - private Optional expectFailure(Method method) { + private Optional expectFailure(Method method, Object index) { try { Object result = method.invoke(testService, index); return Optional.of(new AssertionError( String.format("Result should have caused an exception but deserialized to: %s", result))); } catch (Exception e) { - return Optional.empty(); // we expected the method to throw and it did, so this expectation was satisifed + return Optional.empty(); // we expected the method to throw, and it did, so this expectation was satisfied } } } diff --git a/dialogue-client-verifier/src/test/java/com/palantir/verification/SingleParamServicesTest.java b/dialogue-client-verifier/src/test/java/com/palantir/verification/SingleParamServicesTest.java index 5ac59ae0d..8ba5d2468 100644 --- a/dialogue-client-verifier/src/test/java/com/palantir/verification/SingleParamServicesTest.java +++ b/dialogue-client-verifier/src/test/java/com/palantir/verification/SingleParamServicesTest.java @@ -16,6 +16,8 @@ package com.palantir.verification; +import static org.assertj.core.api.Assertions.assertThat; + import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.collect.ImmutableMap; import com.palantir.conjure.java.api.errors.RemoteException; @@ -35,21 +37,20 @@ import java.util.List; import java.util.stream.IntStream; import org.apache.commons.lang3.ClassUtils; -import org.junit.Assume; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.api.Assumptions; +import org.junit.jupiter.api.extension.RegisterExtension; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; -@RunWith(Parameterized.class) public class SingleParamServicesTest { - @ClassRule - public static final VerificationServerRule server = new VerificationServerRule(); + @RegisterExtension + public static final VerificationServerExtension server = new VerificationServerExtension(); private static final SafeLogger log = SafeLoggerFactory.get(SingleParamServicesTest.class); private static final ObjectMapper objectMapper = ObjectMappers.newClientObjectMapper(); - private static ImmutableMap servicesMaps = ImmutableMap.of( + private static final ImmutableMap servicesMaps = ImmutableMap.of( "singlePathParamService", server.client(SinglePathParamServiceBlocking.class), "singleHeaderService", @@ -57,48 +58,37 @@ public class SingleParamServicesTest { "singleQueryParamService", server.client(SingleQueryParamServiceBlocking.class)); - @Parameterized.Parameter(0) - public String serviceName; - - @Parameterized.Parameter(1) - public EndpointName endpointName; - - @Parameterized.Parameter(2) - public int index; - - @Parameterized.Parameter(3) - public String jsonString; - - @Parameterized.Parameters(name = "{0}/{1}({3})") - public static Collection data() { - List objects = new ArrayList<>(); + static Collection data() { + List objects = new ArrayList<>(); Cases.TEST_CASES.getSingleHeaderService().forEach((endpointName, singleHeaderTestCases) -> { int size = singleHeaderTestCases.size(); IntStream.range(0, size) .forEach(i -> objects.add( - new Object[] {"singleHeaderService", endpointName, i, singleHeaderTestCases.get(i)})); + Arguments.of("singleHeaderService", endpointName, i, singleHeaderTestCases.get(i)))); }); Cases.TEST_CASES.getSinglePathParamService().forEach((endpointName, singleHeaderTestCases) -> { int size = singleHeaderTestCases.size(); IntStream.range(0, size) .forEach(i -> objects.add( - new Object[] {"singlePathParamService", endpointName, i, singleHeaderTestCases.get(i)})); + Arguments.of("singlePathParamService", endpointName, i, singleHeaderTestCases.get(i)))); }); Cases.TEST_CASES.getSingleQueryParamService().forEach((endpointName, singleQueryTestCases) -> { int size = singleQueryTestCases.size(); IntStream.range(0, size) .forEach(i -> objects.add( - new Object[] {"singleQueryParamService", endpointName, i, singleQueryTestCases.get(i)})); + Arguments.of("singleQueryParamService", endpointName, i, singleQueryTestCases.get(i)))); }); return objects; } - @Test - public void runTestCase() throws Exception { - Assume.assumeFalse(Cases.shouldIgnore(endpointName, jsonString)); + @ParameterizedTest(name = "{0}/{1}({3})") + @MethodSource("data") + public void runTestCase(String serviceName, EndpointName endpointName, int index, String jsonString) + throws Exception { + Assumptions.assumeFalse(Cases.shouldIgnore(endpointName, jsonString)); log.info( "Invoking {} {}({})", @@ -107,7 +97,8 @@ public void runTestCase() throws Exception { SafeArg.of("jsonString", jsonString)); Object service = servicesMaps.get(serviceName); - for (Method method : servicesMaps.get(serviceName).getClass().getMethods()) { + assertThat(service).as("Invalid service: '%s'", serviceName).isNotNull(); + for (Method method : service.getClass().getMethods()) { String name = method.getName(); // Need to set accessible true work around dialogues anonymous class impl method.setAccessible(true); diff --git a/dialogue-client-verifier/src/test/java/com/palantir/verification/VerificationServerRule.java b/dialogue-client-verifier/src/test/java/com/palantir/verification/VerificationServerExtension.java similarity index 91% rename from dialogue-client-verifier/src/test/java/com/palantir/verification/VerificationServerRule.java rename to dialogue-client-verifier/src/test/java/com/palantir/verification/VerificationServerExtension.java index c513d4d96..34c00d742 100644 --- a/dialogue-client-verifier/src/test/java/com/palantir/verification/VerificationServerRule.java +++ b/dialogue-client-verifier/src/test/java/com/palantir/verification/VerificationServerExtension.java @@ -33,14 +33,16 @@ import java.nio.file.Paths; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; -import org.junit.rules.ExternalResource; +import org.junit.jupiter.api.extension.AfterAllCallback; +import org.junit.jupiter.api.extension.BeforeAllCallback; +import org.junit.jupiter.api.extension.ExtensionContext; /** * Spins up the 'verification-server' executable which will bind to port 8000, and tears it down at the end of the test. */ -public final class VerificationServerRule extends ExternalResource { +public final class VerificationServerExtension implements BeforeAllCallback, AfterAllCallback { - private static final SafeLogger log = SafeLoggerFactory.get(VerificationServerRule.class); + private static final SafeLogger log = SafeLoggerFactory.get(VerificationServerExtension.class); private static final SslConfiguration TRUST_STORE_CONFIGURATION = new SslConfiguration.Builder() .trustStorePath(Paths.get("../dialogue-test-common/src/main/resources/trustStore.jks")) .build(); @@ -61,7 +63,7 @@ public T client(Class service) { } @Override - public void before() throws Exception { + public void beforeAll(ExtensionContext _context) throws Exception { ProcessBuilder processBuilder = new ProcessBuilder( "build/verification/verifier", "build/test-cases/test-cases.json", @@ -106,7 +108,7 @@ private static void blockUntilServerStarted(InputStream inputStream) throws Inte } @Override - protected void after() { + public void afterAll(ExtensionContext _context) { process.destroyForcibly(); try { process.waitFor(5, TimeUnit.SECONDS); diff --git a/versions.props b/versions.props index c45af933f..bf50e4292 100644 --- a/versions.props +++ b/versions.props @@ -27,9 +27,7 @@ com.palantir.goethe:* = 0.8.0 com.github.ben-manes.caffeine:caffeine = 3.1.1 # test deps -junit:junit = 4.13.2 org.junit.jupiter:* = 5.8.2 -org.junit.vintage:* = 5.8.2 org.apache.logging.log4j:* = 2.18.0 org.assertj:assertj-core = 3.23.1 org.assertj:assertj-guava = 3.3.0 From d0a2d72e928ee6ded7d7bc412e96a22ff02b887c Mon Sep 17 00:00:00 2001 From: David Schlosnagle Date: Fri, 11 Nov 2022 08:56:11 -0500 Subject: [PATCH 2/4] JUnit 5.9.1 --- versions.lock | 19 +++++++++---------- versions.props | 2 +- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/versions.lock b/versions.lock index 3bff7ff89..3a23b7e2d 100644 --- a/versions.lock +++ b/versions.lock @@ -79,7 +79,7 @@ commons-logging:commons-logging:1.2 (2 constraints: 8215ead1) de.erichseifert.vectorgraphics2d:VectorGraphics2D:0.13 (1 constraints: 8c0a80bb) de.rototor.pdfbox:graphics2d:0.25 (1 constraints: 8f0a84bb) io.undertow:undertow-core:2.2.18.Final (1 constraints: 57074361) -junit:junit:4.13.2 (6 constraints: 175733ba) +junit:junit:4.13.2 (4 constraints: 2d413ec7) net.bytebuddy:byte-buddy:1.12.10 (2 constraints: e9163f66) net.bytebuddy:byte-buddy-agent:1.12.10 (1 constraints: 6f0ba8e9) net.jcip:jcip-annotations:1.0 (1 constraints: 560ff165) @@ -92,7 +92,7 @@ org.apache.logging.log4j:log4j-core:2.18.0 (2 constraints: 13166525) org.apache.logging.log4j:log4j-slf4j-impl:2.18.0 (1 constraints: 3d05473b) org.apache.pdfbox:fontbox:2.0.17 (1 constraints: 180b71d8) org.apache.pdfbox:pdfbox:2.0.17 (1 constraints: b40c5915) -org.apiguardian:apiguardian-api:1.1.2 (7 constraints: 9d791b5f) +org.apiguardian:apiguardian-api:1.1.2 (6 constraints: 24695e60) org.assertj:assertj-core:3.23.1 (3 constraints: 5025194c) org.assertj:assertj-guava:3.3.0 (1 constraints: 08050336) org.awaitility:awaitility:4.2.0 (1 constraints: 08050536) @@ -105,14 +105,13 @@ org.jboss.xnio:xnio-api:3.8.7.Final (2 constraints: 771a3146) org.jboss.xnio:xnio-nio:3.8.7.Final (1 constraints: c80dcb30) org.jmock:jmock:2.12.0 (1 constraints: 3705353b) org.jmock:jmock-testjar:2.12.0 (1 constraints: a507a272) -org.junit.jupiter:junit-jupiter:5.8.2 (1 constraints: 11051e36) -org.junit.jupiter:junit-jupiter-api:5.8.2 (6 constraints: 6e58c98f) -org.junit.jupiter:junit-jupiter-engine:5.8.2 (1 constraints: 0c0edf3b) -org.junit.jupiter:junit-jupiter-migrationsupport:5.8.2 (1 constraints: 11051e36) -org.junit.jupiter:junit-jupiter-params:5.8.2 (2 constraints: 1c138c3c) -org.junit.platform:junit-platform-commons:1.8.2 (2 constraints: dd200b4b) -org.junit.platform:junit-platform-engine:1.8.2 (2 constraints: 2b21d273) -org.junit.vintage:junit-vintage-engine:5.8.2 (1 constraints: 11051e36) +org.junit.jupiter:junit-jupiter:5.9.1 (1 constraints: 11052036) +org.junit.jupiter:junit-jupiter-api:5.9.1 (6 constraints: 6e58d38f) +org.junit.jupiter:junit-jupiter-engine:5.9.1 (1 constraints: 0c0ee13b) +org.junit.jupiter:junit-jupiter-migrationsupport:5.9.1 (1 constraints: 11052036) +org.junit.jupiter:junit-jupiter-params:5.9.1 (2 constraints: 1c13903c) +org.junit.platform:junit-platform-commons:1.9.1 (2 constraints: dd200f4b) +org.junit.platform:junit-platform-engine:1.9.1 (1 constraints: ab1029b4) org.knowm.xchart:xchart:3.6.1 (1 constraints: 0c050d36) org.mockito:mockito-core:4.6.1 (2 constraints: d213aa65) org.mockito:mockito-junit-jupiter:4.6.1 (1 constraints: 0d051236) diff --git a/versions.props b/versions.props index bf50e4292..7ca64f977 100644 --- a/versions.props +++ b/versions.props @@ -27,7 +27,7 @@ com.palantir.goethe:* = 0.8.0 com.github.ben-manes.caffeine:caffeine = 3.1.1 # test deps -org.junit.jupiter:* = 5.8.2 +org.junit.jupiter:* = 5.9.1 org.apache.logging.log4j:* = 2.18.0 org.assertj:assertj-core = 3.23.1 org.assertj:assertj-guava = 3.3.0 From 0b9c3468141d1d507860cd08aab69582f2a6a16c Mon Sep 17 00:00:00 2001 From: David Schlosnagle Date: Fri, 11 Nov 2022 09:24:59 -0500 Subject: [PATCH 3/4] MockWebServer JUnit 5 --- dialogue-annotations-processor/build.gradle | 2 +- .../hc5/ApacheHttpClientChannelsTest.java | 9 ++++++- .../dialogue/hc5/ApacheProxyConfigTest.java | 8 ++++++ dialogue-test-common/build.gradle | 3 +-- .../dialogue/AbstractChannelTest.java | 21 +++++++--------- .../dialogue/AbstractProxyConfigTest.java | 23 +++++++++-------- .../AbstractSampleServiceClientTest.java | 25 +++++++++---------- versions.lock | 21 ++++++++++------ versions.props | 2 +- 9 files changed, 66 insertions(+), 48 deletions(-) diff --git a/dialogue-annotations-processor/build.gradle b/dialogue-annotations-processor/build.gradle index 696c30838..f24856765 100644 --- a/dialogue-annotations-processor/build.gradle +++ b/dialogue-annotations-processor/build.gradle @@ -43,7 +43,7 @@ dependencies { testImplementation 'com.google.guava:guava' testImplementation 'com.google.testing.compile:compile-testing' testImplementation 'com.palantir.safe-logging:preconditions-assertj' - testImplementation 'com.squareup.okhttp3:mockwebserver' + testImplementation 'com.squareup.okhttp3:mockwebserver3-junit5' testImplementation 'org.assertj:assertj-core' testImplementation 'org.junit.jupiter:junit-jupiter' } diff --git a/dialogue-apache-hc5-client/src/test/java/com/palantir/dialogue/hc5/ApacheHttpClientChannelsTest.java b/dialogue-apache-hc5-client/src/test/java/com/palantir/dialogue/hc5/ApacheHttpClientChannelsTest.java index 34c457b44..994640305 100644 --- a/dialogue-apache-hc5-client/src/test/java/com/palantir/dialogue/hc5/ApacheHttpClientChannelsTest.java +++ b/dialogue-apache-hc5-client/src/test/java/com/palantir/dialogue/hc5/ApacheHttpClientChannelsTest.java @@ -47,10 +47,17 @@ import java.util.Map; import java.util.Optional; import java.util.OptionalLong; -import okhttp3.mockwebserver.RecordedRequest; +import mockwebserver3.MockWebServer; +import mockwebserver3.RecordedRequest; +import mockwebserver3.junit5.internal.MockWebServerExtension; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +@ExtendWith(MockWebServerExtension.class) public final class ApacheHttpClientChannelsTest extends AbstractChannelTest { + ApacheHttpClientChannelsTest(MockWebServer server) { + super(server); + } @Override protected Channel createChannel(ClientConfiguration config) { diff --git a/dialogue-apache-hc5-client/src/test/java/com/palantir/dialogue/hc5/ApacheProxyConfigTest.java b/dialogue-apache-hc5-client/src/test/java/com/palantir/dialogue/hc5/ApacheProxyConfigTest.java index 326f7ecfe..937ec8a06 100644 --- a/dialogue-apache-hc5-client/src/test/java/com/palantir/dialogue/hc5/ApacheProxyConfigTest.java +++ b/dialogue-apache-hc5-client/src/test/java/com/palantir/dialogue/hc5/ApacheProxyConfigTest.java @@ -18,8 +18,16 @@ import com.palantir.conjure.java.client.config.ClientConfiguration; import com.palantir.dialogue.AbstractProxyConfigTest; import com.palantir.dialogue.Channel; +import mockwebserver3.MockWebServer; +import mockwebserver3.junit5.internal.MockWebServerExtension; +import org.junit.jupiter.api.extension.ExtendWith; +@ExtendWith(MockWebServerExtension.class) public final class ApacheProxyConfigTest extends AbstractProxyConfigTest { + ApacheProxyConfigTest(MockWebServer server, MockWebServer proxyServer) { + super(server, proxyServer); + } + @Override protected Channel create(ClientConfiguration config) { return ApacheHttpClientChannels.create(config); diff --git a/dialogue-test-common/build.gradle b/dialogue-test-common/build.gradle index 4477e5223..5255a5855 100644 --- a/dialogue-test-common/build.gradle +++ b/dialogue-test-common/build.gradle @@ -12,11 +12,10 @@ dependencies { api 'com.palantir.conjure.java.runtime:client-config' api 'com.palantir.conjure.java.runtime:keystores' api 'com.palantir.tracing:tracing-test-utils' - api 'com.squareup.okhttp3:mockwebserver' + api 'com.squareup.okhttp3:mockwebserver3-junit5' api 'org.assertj:assertj-core' api 'org.assertj:assertj-guava' api 'org.junit.jupiter:junit-jupiter' - api 'org.junit.jupiter:junit-jupiter-migrationsupport' api 'org.mockito:mockito-core' api 'org.mockito:mockito-junit-jupiter' api 'io.undertow:undertow-core' diff --git a/dialogue-test-common/src/main/java/com/palantir/dialogue/AbstractChannelTest.java b/dialogue-test-common/src/main/java/com/palantir/dialogue/AbstractChannelTest.java index 8d7dc4565..4571ae013 100644 --- a/dialogue-test-common/src/main/java/com/palantir/dialogue/AbstractChannelTest.java +++ b/dialogue-test-common/src/main/java/com/palantir/dialogue/AbstractChannelTest.java @@ -16,8 +16,6 @@ package com.palantir.dialogue; -// CHECKSTYLE:OFF // static import - import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatCode; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -38,21 +36,17 @@ import java.util.concurrent.CancellationException; import java.util.concurrent.ExecutionException; import java.util.function.BiConsumer; +import mockwebserver3.MockResponse; +import mockwebserver3.MockWebServer; +import mockwebserver3.RecordedRequest; import okhttp3.HttpUrl; -import okhttp3.mockwebserver.MockResponse; -import okhttp3.mockwebserver.MockWebServer; -import okhttp3.mockwebserver.RecordedRequest; import okio.Buffer; import okio.GzipSink; -import org.junit.Rule; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; -import org.junit.jupiter.migrationsupport.rules.EnableRuleMigrationSupport; -// CHECKSTYLE:ON @SuppressWarnings({"checkstyle:avoidstaticimport", "checkstyle:VisibilityModifier", "FutureReturnValueIgnored"}) -@EnableRuleMigrationSupport public abstract class AbstractChannelTest { protected static final byte[] CONTENT = "test".getBytes(StandardCharsets.UTF_8); @@ -63,9 +57,6 @@ private Channel createChannel(URL baseUrl) { return createChannel(TestConfigurations.create(baseUrl.toString())); } - @Rule - public final MockWebServer server = new MockWebServer(); - protected final RequestBody body = new RequestBody() { @Override public void writeTo(OutputStream output) throws IOException { @@ -97,6 +88,12 @@ public void close() {} protected Channel channel; + protected final MockWebServer server; + + protected AbstractChannelTest(MockWebServer server) { + this.server = server; + } + @BeforeEach public void before() { channel = createChannel(server.url("").url()); diff --git a/dialogue-test-common/src/main/java/com/palantir/dialogue/AbstractProxyConfigTest.java b/dialogue-test-common/src/main/java/com/palantir/dialogue/AbstractProxyConfigTest.java index 1299c2466..d36765958 100644 --- a/dialogue-test-common/src/main/java/com/palantir/dialogue/AbstractProxyConfigTest.java +++ b/dialogue-test-common/src/main/java/com/palantir/dialogue/AbstractProxyConfigTest.java @@ -30,14 +30,14 @@ import java.net.URI; import java.nio.charset.StandardCharsets; import java.util.List; -import okhttp3.mockwebserver.MockResponse; -import okhttp3.mockwebserver.MockWebServer; -import okhttp3.mockwebserver.RecordedRequest; -import org.junit.Rule; +import mockwebserver3.MockResponse; +import mockwebserver3.MockWebServer; +import mockwebserver3.RecordedRequest; +import mockwebserver3.junit5.internal.MockWebServerExtension; import org.junit.jupiter.api.Test; -import org.junit.jupiter.migrationsupport.rules.EnableRuleMigrationSupport; +import org.junit.jupiter.api.extension.ExtendWith; -@EnableRuleMigrationSupport +@ExtendWith(MockWebServerExtension.class) public abstract class AbstractProxyConfigTest { private static final Request request = Request.builder() @@ -62,11 +62,14 @@ public void close() {} }) .build(); - @Rule - public final MockWebServer server = new MockWebServer(); + private final MockWebServer server; - @Rule - public final MockWebServer proxyServer = new MockWebServer(); + private final MockWebServer proxyServer; + + protected AbstractProxyConfigTest(MockWebServer server, MockWebServer proxyServer) { + this.server = server; + this.proxyServer = proxyServer; + } protected abstract Channel create(ClientConfiguration config); diff --git a/dialogue-test-common/src/main/java/com/palantir/dialogue/AbstractSampleServiceClientTest.java b/dialogue-test-common/src/main/java/com/palantir/dialogue/AbstractSampleServiceClientTest.java index d576004b7..62765b8a9 100644 --- a/dialogue-test-common/src/main/java/com/palantir/dialogue/AbstractSampleServiceClientTest.java +++ b/dialogue-test-common/src/main/java/com/palantir/dialogue/AbstractSampleServiceClientTest.java @@ -16,8 +16,6 @@ package com.palantir.dialogue; -// CHECKSTYLE:OFF // static import - import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -37,18 +35,16 @@ import java.time.OffsetDateTime; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; -import okhttp3.mockwebserver.MockResponse; -import okhttp3.mockwebserver.MockWebServer; -import okhttp3.mockwebserver.RecordedRequest; -import org.junit.Rule; +import mockwebserver3.MockResponse; +import mockwebserver3.MockWebServer; +import mockwebserver3.RecordedRequest; +import mockwebserver3.junit5.internal.MockWebServerExtension; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Timeout; -import org.junit.jupiter.migrationsupport.rules.EnableRuleMigrationSupport; - -// CHECKSTYLE:ON +import org.junit.jupiter.api.extension.ExtendWith; -@EnableRuleMigrationSupport +@ExtendWith(MockWebServerExtension.class) public abstract class AbstractSampleServiceClientTest { abstract SampleServiceBlocking createBlockingClient(URL baseUrl, Duration timeout); @@ -67,8 +63,11 @@ public abstract class AbstractSampleServiceClientTest { static final SslConfiguration SSL_CONFIG = SslConfiguration.of( Paths.get("src/test/resources/trustStore.jks"), Paths.get("src/test/resources/keyStore.jks"), "keystore"); - @Rule - public final MockWebServer server = new MockWebServer(); + private final MockWebServer server; + + protected AbstractSampleServiceClientTest(MockWebServer server) { + this.server = server; + } private SampleServiceBlocking blockingClient; private SampleServiceAsync asyncClient; @@ -107,7 +106,7 @@ public abstract class AbstractSampleServiceClientTest { @BeforeEach public void before() { - server.useHttps(SslSocketFactories.createSslSocketFactory(SSL_CONFIG), false); + server.useHttps(SslSocketFactories.createSslSocketFactory(SSL_CONFIG)); blockingClient = createBlockingClient(server.url("").url(), Duration.ofSeconds(1)); asyncClient = createAsyncClient(server.url("").url(), Duration.ofSeconds(1)); } diff --git a/versions.lock b/versions.lock index ff2470174..aaaf5e54f 100644 --- a/versions.lock +++ b/versions.lock @@ -57,7 +57,7 @@ org.glassfish.hk2.external:jakarta.inject:2.6.1 (1 constraints: f410fcc2) org.glassfish.jersey.core:jersey-common:2.31 (1 constraints: da04fa30) org.hdrhistogram:HdrHistogram:2.1.12 (1 constraints: 3e103aa2) org.immutables:value:2.8.8 (1 constraints: 14051536) -org.jetbrains:annotations:23.0.0 (1 constraints: 31115ed1) +org.jetbrains:annotations:23.0.0 (2 constraints: 0f20e4ff) org.mpierce.metrics.reservoir:hdrhistogram-metrics-reservoir:1.1.3 (1 constraints: 0d10f991) org.slf4j:slf4j-api:1.7.36 (8 constraints: b280891b) @@ -71,14 +71,16 @@ com.google.truth:truth:1.1 (1 constraints: b71111d7) com.palantir.safe-logging:preconditions-assertj:3.2.0 (1 constraints: 07050036) com.palantir.tracing:tracing-test-utils:6.15.0 (1 constraints: 3e05563b) com.spotify.dataenum:dataenum:1.4.1 (1 constraints: e9105ac1) -com.squareup.okhttp3:mockwebserver:3.13.1 (1 constraints: 3a053f3b) -com.squareup.okhttp3:okhttp:3.13.1 (2 constraints: a014ba9d) -com.squareup.okio:okio:1.17.2 (1 constraints: 850cc309) +com.squareup.okhttp3:mockwebserver3:5.0.0-alpha.10 (1 constraints: b514caae) +com.squareup.okhttp3:mockwebserver3-junit5:5.0.0-alpha.10 (1 constraints: c9071c72) +com.squareup.okhttp3:okhttp:5.0.0-alpha.10 (1 constraints: 3a053f3b) +com.squareup.okhttp3:okhttp-jvm:5.0.0-alpha.10 (2 constraints: 392169c2) +com.squareup.okio:okio-jvm:3.2.0 (1 constraints: c90d9c38) commons-logging:commons-logging:1.2 (2 constraints: 8215ead1) de.erichseifert.vectorgraphics2d:VectorGraphics2D:0.13 (1 constraints: 8c0a80bb) de.rototor.pdfbox:graphics2d:0.25 (1 constraints: 8f0a84bb) io.undertow:undertow-core:2.2.18.Final (1 constraints: 57074361) -junit:junit:4.13.2 (4 constraints: 2d413ec7) +junit:junit:4.13.1 (2 constraints: dc1cc51a) net.bytebuddy:byte-buddy:1.12.16 (2 constraints: ef164566) net.bytebuddy:byte-buddy-agent:1.12.16 (1 constraints: 750baee9) net.jcip:jcip-annotations:1.0 (1 constraints: 560ff165) @@ -91,7 +93,7 @@ org.apache.logging.log4j:log4j-core:2.19.0 (2 constraints: 15169e25) org.apache.logging.log4j:log4j-slf4j-impl:2.19.0 (1 constraints: 3e054a3b) org.apache.pdfbox:fontbox:2.0.17 (1 constraints: 180b71d8) org.apache.pdfbox:pdfbox:2.0.17 (1 constraints: b40c5915) -org.apiguardian:apiguardian-api:1.1.2 (6 constraints: 24695e60) +org.apiguardian:apiguardian-api:1.1.2 (5 constraints: 105480ac) org.assertj:assertj-core:3.23.1 (3 constraints: 5025194c) org.assertj:assertj-guava:3.3.0 (1 constraints: 08050336) org.awaitility:awaitility:4.2.0 (1 constraints: 08050536) @@ -102,12 +104,15 @@ org.jboss.logging:jboss-logging:3.4.1.Final (3 constraints: f03036d7) org.jboss.threads:jboss-threads:3.1.0.Final (2 constraints: 561a9b42) org.jboss.xnio:xnio-api:3.8.7.Final (2 constraints: 771a3146) org.jboss.xnio:xnio-nio:3.8.7.Final (1 constraints: c80dcb30) +org.jetbrains.kotlin:kotlin-stdlib:1.6.21 (3 constraints: bd2f9e82) +org.jetbrains.kotlin:kotlin-stdlib-common:1.6.21 (3 constraints: 3929d928) +org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.6.21 (1 constraints: e110f6d2) +org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.21 (3 constraints: bc2d5d81) org.jmock:jmock:2.12.0 (1 constraints: 3705353b) org.jmock:jmock-testjar:2.12.0 (1 constraints: a507a272) org.junit.jupiter:junit-jupiter:5.9.1 (1 constraints: 11052036) -org.junit.jupiter:junit-jupiter-api:5.9.1 (6 constraints: 6e58d58f) +org.junit.jupiter:junit-jupiter-api:5.9.1 (6 constraints: 4b55e412) org.junit.jupiter:junit-jupiter-engine:5.9.1 (1 constraints: 0c0ee13b) -org.junit.jupiter:junit-jupiter-migrationsupport:5.9.1 (1 constraints: 11052036) org.junit.jupiter:junit-jupiter-params:5.9.1 (2 constraints: 1c13903c) org.junit.platform:junit-platform-commons:1.9.1 (2 constraints: dd200f4b) org.junit.platform:junit-platform-engine:1.9.1 (1 constraints: ab1029b4) diff --git a/versions.props b/versions.props index 1fce6ca92..fbe567b24 100644 --- a/versions.props +++ b/versions.props @@ -40,7 +40,7 @@ org.jmock:jmock = 2.12.0 org.knowm.xchart:xchart = 3.6.1 com.palantir.conjure.verification:* = 0.19.0 io.undertow:undertow-core = 2.2.18.Final -com.squareup.okhttp3:mockwebserver = 3.13.1 +com.squareup.okhttp3:mockwebserver3-junit5 = 5.0.0-alpha.10 org.openjdk.jmh:* = 1.35 # dependency-upgrader:OFF From 16d477816bf2dc6efbe89cd53723462371af3893 Mon Sep 17 00:00:00 2001 From: David Schlosnagle Date: Fri, 11 Nov 2022 12:09:11 -0500 Subject: [PATCH 4/4] write-locks --- versions.lock | 6 ------ 1 file changed, 6 deletions(-) diff --git a/versions.lock b/versions.lock index 620574935..aaaf5e54f 100644 --- a/versions.lock +++ b/versions.lock @@ -81,7 +81,6 @@ de.erichseifert.vectorgraphics2d:VectorGraphics2D:0.13 (1 constraints: 8c0a80bb) de.rototor.pdfbox:graphics2d:0.25 (1 constraints: 8f0a84bb) io.undertow:undertow-core:2.2.18.Final (1 constraints: 57074361) junit:junit:4.13.1 (2 constraints: dc1cc51a) -junit:junit:4.13.2 (4 constraints: 2d413ec7) net.bytebuddy:byte-buddy:1.12.16 (2 constraints: ef164566) net.bytebuddy:byte-buddy-agent:1.12.16 (1 constraints: 750baee9) net.jcip:jcip-annotations:1.0 (1 constraints: 560ff165) @@ -95,7 +94,6 @@ org.apache.logging.log4j:log4j-slf4j-impl:2.19.0 (1 constraints: 3e054a3b) org.apache.pdfbox:fontbox:2.0.17 (1 constraints: 180b71d8) org.apache.pdfbox:pdfbox:2.0.17 (1 constraints: b40c5915) org.apiguardian:apiguardian-api:1.1.2 (5 constraints: 105480ac) -org.apiguardian:apiguardian-api:1.1.2 (6 constraints: 24695e60) org.assertj:assertj-core:3.23.1 (3 constraints: 5025194c) org.assertj:assertj-guava:3.3.0 (1 constraints: 08050336) org.awaitility:awaitility:4.2.0 (1 constraints: 08050536) @@ -114,12 +112,8 @@ org.jmock:jmock:2.12.0 (1 constraints: 3705353b) org.jmock:jmock-testjar:2.12.0 (1 constraints: a507a272) org.junit.jupiter:junit-jupiter:5.9.1 (1 constraints: 11052036) org.junit.jupiter:junit-jupiter-api:5.9.1 (6 constraints: 4b55e412) -org.junit.jupiter:junit-jupiter:5.9.1 (1 constraints: 11052036) -org.junit.jupiter:junit-jupiter-api:5.9.1 (6 constraints: 6e58d58f) org.junit.jupiter:junit-jupiter-engine:5.9.1 (1 constraints: 0c0ee13b) org.junit.jupiter:junit-jupiter-params:5.9.1 (2 constraints: 1c13903c) -org.junit.jupiter:junit-jupiter-migrationsupport:5.9.1 (1 constraints: 11052036) -org.junit.jupiter:junit-jupiter-params:5.9.1 (2 constraints: 1c13903c) org.junit.platform:junit-platform-commons:1.9.1 (2 constraints: dd200f4b) org.junit.platform:junit-platform-engine:1.9.1 (1 constraints: ab1029b4) org.knowm.xchart:xchart:3.6.1 (1 constraints: 0c050d36)