mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-26 08:59:09 +00:00
Convert various test classes to @ParameterizedClass
See gh-35833
This commit is contained in:
+13
-4
@@ -20,7 +20,9 @@ import java.util.stream.Stream;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.Parameter;
|
||||
import org.junit.jupiter.params.ParameterizedClass;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
@@ -45,14 +47,21 @@ import static org.junit.jupiter.params.provider.Arguments.argumentSet;
|
||||
* @author Sam Brannen
|
||||
* @since 2.5
|
||||
*/
|
||||
@ParameterizedClass
|
||||
@MethodSource("contextConfigurationLocationsData")
|
||||
class GenericXmlContextLoaderResourceLocationsTests {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(GenericXmlContextLoaderResourceLocationsTests.class);
|
||||
|
||||
@Parameter(0)
|
||||
Class<?> testClass;
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("contextConfigurationLocationsData")
|
||||
void assertContextConfigurationLocations(Class<?> testClass, String[] expectedLocations) {
|
||||
@Parameter(1)
|
||||
String[] expectedLocations;
|
||||
|
||||
|
||||
@Test
|
||||
void assertContextConfigurationLocations() {
|
||||
ContextConfiguration contextConfig = testClass.getAnnotation(ContextConfiguration.class);
|
||||
String[] configuredLocations = contextConfig.value();
|
||||
ContextConfigurationAttributes configAttributes =
|
||||
|
||||
+8
-7
@@ -18,7 +18,8 @@ package org.springframework.test.context.testng;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedClass;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import org.testng.TestNG;
|
||||
@@ -48,13 +49,13 @@ import static org.junit.jupiter.params.provider.Arguments.argumentSet;
|
||||
* @author Sam Brannen
|
||||
* @since 2.5
|
||||
*/
|
||||
class FailingBeforeAndAfterMethodsTestNGTests {
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("testData")
|
||||
void runTestAndAssertCounters(Class<?> clazz, int expectedTestStartCount,
|
||||
int expectedTestSuccessCount, int expectedFailureCount, int expectedFailedConfigurationsCount) throws Exception {
|
||||
@ParameterizedClass
|
||||
@MethodSource("testData")
|
||||
record FailingBeforeAndAfterMethodsTestNGTests(Class<?> clazz, int expectedTestStartCount,
|
||||
int expectedTestSuccessCount, int expectedFailureCount, int expectedFailedConfigurationsCount) {
|
||||
|
||||
@Test
|
||||
void runTestAndAssertCounters() {
|
||||
TrackingTestNGTestListener listener = new TrackingTestNGTestListener();
|
||||
TestNG testNG = new TestNG();
|
||||
testNG.addListener(listener);
|
||||
|
||||
+10
-18
@@ -17,17 +17,14 @@
|
||||
package org.springframework.test.web.servlet.client;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import mockwebserver3.MockResponse;
|
||||
import mockwebserver3.MockWebServer;
|
||||
import org.junit.jupiter.api.AutoClose;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedClass;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
@@ -43,15 +40,10 @@ import static org.junit.jupiter.params.provider.Arguments.argumentSet;
|
||||
/**
|
||||
* Integration tests for {@link RestTestClient} against a live server.
|
||||
*/
|
||||
@ParameterizedClass
|
||||
@MethodSource("clientHttpRequestFactories")
|
||||
class RestTestClientIntegrationTests {
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.METHOD)
|
||||
@ParameterizedTest
|
||||
@MethodSource("clientHttpRequestFactories")
|
||||
@interface ParameterizedRestClientTest {
|
||||
}
|
||||
|
||||
static Stream<Arguments> clientHttpRequestFactories() {
|
||||
return Stream.of(
|
||||
argumentSet("JDK HttpURLConnection", new SimpleClientHttpRequestFactory()),
|
||||
@@ -62,22 +54,22 @@ class RestTestClientIntegrationTests {
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@AutoClose
|
||||
private MockWebServer server = new MockWebServer();
|
||||
private final MockWebServer server = new MockWebServer();
|
||||
|
||||
private RestTestClient testClient;
|
||||
private final RestTestClient testClient;
|
||||
|
||||
|
||||
private void startServer(ClientHttpRequestFactory requestFactory) throws IOException {
|
||||
RestTestClientIntegrationTests(ClientHttpRequestFactory requestFactory) throws IOException {
|
||||
this.server.start();
|
||||
this.testClient = RestTestClient.bindToServer(requestFactory)
|
||||
.baseUrl(this.server.url("/").toString())
|
||||
.build();
|
||||
}
|
||||
|
||||
@ParameterizedRestClientTest // gh-35784
|
||||
void sequentialRequestsNotConsumingBody(ClientHttpRequestFactory requestFactory) throws IOException {
|
||||
startServer(requestFactory);
|
||||
@Test // gh-35784
|
||||
void sequentialRequestsNotConsumingBody() {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
prepareResponse(builder ->
|
||||
builder.setHeader("Content-Type", "text/plain").body("Hello Spring!"));
|
||||
|
||||
Reference in New Issue
Block a user