Use new features from JUnit Jupiter 5.11
This commit primarily migrates to the new argumentSet() feature but also applies additional polishing to our use of parameterized tests. See gh-33395
This commit is contained in:
@@ -40,8 +40,7 @@ import org.springframework.test.context.web.WebTestContextBootstrapper;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
import static org.junit.jupiter.api.Named.named;
|
||||
import static org.junit.jupiter.params.provider.Arguments.arguments;
|
||||
import static org.junit.jupiter.params.provider.Arguments.argumentSet;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.springframework.test.context.BootstrapUtils.resolveTestContextBootstrapper;
|
||||
import static org.springframework.test.context.NestedTestConfiguration.EnclosingConfiguration.INHERIT;
|
||||
@@ -105,7 +104,7 @@ class BootstrapUtilsTests {
|
||||
/**
|
||||
* @since 5.3
|
||||
*/
|
||||
@ParameterizedTest(name = "[{index}] {0}")
|
||||
@ParameterizedTest
|
||||
@MethodSource
|
||||
void resolveTestContextBootstrapperInEnclosingClassHierarchy(Class<?> testClass, Class<?> expectedBootstrapper) {
|
||||
assertBootstrapper(testClass, expectedBootstrapper);
|
||||
@@ -130,7 +129,7 @@ class BootstrapUtilsTests {
|
||||
}
|
||||
|
||||
private static Arguments args(Class<?> testClass, Class<? extends TestContextBootstrapper> expectedBootstrapper) {
|
||||
return arguments(named(testClass.getSimpleName(), testClass), expectedBootstrapper);
|
||||
return argumentSet(testClass.getSimpleName(), testClass, expectedBootstrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -18,12 +18,11 @@ package org.springframework.test.context.bean.override.mockito;
|
||||
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.junit.jupiter.api.Named;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.FieldSource;
|
||||
import org.junit.platform.testkit.engine.EngineTestKit;
|
||||
import org.junit.platform.testkit.engine.Events;
|
||||
import org.mockito.Mockito;
|
||||
@@ -33,6 +32,7 @@ import org.mockito.quality.Strictness;
|
||||
import org.springframework.test.context.bean.override.mockito.MockitoBeanForByNameLookupIntegrationTests.Config;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
|
||||
import static org.junit.jupiter.params.provider.Arguments.argumentSet;
|
||||
import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClass;
|
||||
import static org.junit.platform.testkit.engine.EventConditions.event;
|
||||
import static org.junit.platform.testkit.engine.EventConditions.finishedWithFailure;
|
||||
@@ -50,7 +50,7 @@ import static org.junit.platform.testkit.engine.TestExecutionResultConditions.me
|
||||
class MockitoBeanSettingsStrictIntegrationTests {
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("strictCases")
|
||||
@FieldSource("strictCases")
|
||||
void unusedStubbingIsReported(Class<?> forCase) {
|
||||
Events events = EngineTestKit.engine("junit-jupiter")
|
||||
.selectors(selectClass(forCase))
|
||||
@@ -65,12 +65,10 @@ class MockitoBeanSettingsStrictIntegrationTests {
|
||||
message(msg -> msg.contains("Unnecessary stubbings detected.")))));
|
||||
}
|
||||
|
||||
private static Stream<Named<Class<?>>> strictCases() {
|
||||
return Stream.of(
|
||||
Named.of("explicit strictness", ExplicitStrictness.class),
|
||||
Named.of("implicit strictness with @MockitoBean on field", ImplicitStrictnessWithMockitoBean.class)
|
||||
static final List<Arguments> strictCases = List.of(
|
||||
argumentSet("explicit strictness", ExplicitStrictness.class),
|
||||
argumentSet("implicit strictness with @MockitoBean on field", ImplicitStrictnessWithMockitoBean.class)
|
||||
);
|
||||
}
|
||||
|
||||
abstract static class BaseCase {
|
||||
|
||||
|
||||
@@ -30,8 +30,7 @@ import org.springframework.test.context.SmartContextLoader;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Named.named;
|
||||
import static org.junit.jupiter.params.provider.Arguments.arguments;
|
||||
import static org.junit.jupiter.params.provider.Arguments.argumentSet;
|
||||
|
||||
/**
|
||||
* Unit test which verifies proper
|
||||
@@ -51,7 +50,7 @@ class GenericXmlContextLoaderResourceLocationsTests {
|
||||
private static final Log logger = LogFactory.getLog(GenericXmlContextLoaderResourceLocationsTests.class);
|
||||
|
||||
|
||||
@ParameterizedTest(name = "[{index}] {0}")
|
||||
@ParameterizedTest
|
||||
@MethodSource("contextConfigurationLocationsData")
|
||||
void assertContextConfigurationLocations(Class<?> testClass, String[] expectedLocations) {
|
||||
ContextConfiguration contextConfig = testClass.getAnnotation(ContextConfiguration.class);
|
||||
@@ -98,7 +97,7 @@ class GenericXmlContextLoaderResourceLocationsTests {
|
||||
}
|
||||
|
||||
private static Arguments args(Class<?> testClass, String[] expectedLocations) {
|
||||
return arguments(named(testClass.getSimpleName(), testClass), expectedLocations);
|
||||
return argumentSet(testClass.getSimpleName(), testClass, expectedLocations);
|
||||
}
|
||||
|
||||
private static String[] array(String... elements) {
|
||||
|
||||
Reference in New Issue
Block a user