Merge branch '7.0.x'

This commit is contained in:
Sam Brannen
2026-03-18 18:19:31 +01:00
591 changed files with 3284 additions and 3306 deletions
@@ -69,7 +69,7 @@ class DynamicPropertyRegistrarIntegrationTests {
}
@Test
void testReceivesDynamicProperties(@Value("${api.url.1}") String apiUrl1, @Value("${api.url.2}") String apiUrl2) {
void receivesDynamicProperties(@Value("${api.url.1}") String apiUrl1, @Value("${api.url.2}") String apiUrl2) {
assertApiUrlIsDynamic1(apiUrl1);
assertApiUrlIsDynamic2(apiUrl2);
}
@@ -22,7 +22,7 @@ import java.util.List;
import org.junit.jupiter.api.Test;
import org.springframework.util.ReflectionUtils;
import org.springframework.util.ClassUtils;
import static org.assertj.core.api.Assertions.assertThat;
@@ -40,7 +40,7 @@ class TestContextManagerListenerExecutionOrderTests {
private final TestContextManager testContextManager = new TestContextManager(TestCase.class);
private final Method testMethod = ReflectionUtils.findMethod(TestCase.class, "testMethod");
private final Method testMethod = ClassUtils.getMethod(TestCase.class, "testMethod");
@Test
@@ -105,7 +105,7 @@ class TestContextManagerListenerExecutionOrderTests {
private static class TestCase {
@SuppressWarnings("unused")
void testMethod() {
public void testMethod() {
}
}
@@ -20,7 +20,7 @@ import java.lang.reflect.Method;
import org.junit.jupiter.api.Test;
import org.springframework.util.ReflectionUtils;
import org.springframework.util.ClassUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.test.context.MethodInvoker.DEFAULT_INVOKER;
@@ -38,7 +38,7 @@ class TestContextManagerMethodInvokerTests {
private final TestContextManager testContextManager = new TestContextManager(TestCase.class);
private final Method testMethod = ReflectionUtils.findMethod(TestCase.class, "testMethod");
private final Method testMethod = ClassUtils.getMethod(TestCase.class, "testMethod");
@Test
@@ -71,7 +71,7 @@ class TestContextManagerMethodInvokerTests {
private static class TestCase {
@SuppressWarnings("unused")
void testMethod() {
public void testMethod() {
}
}
@@ -47,7 +47,7 @@ class TestPropertySourceRuntimeHintsTests {
@Test
void testPropertySourceWithClassPathStarLocationPattern() {
void propertySourceWithClassPathStarLocationPattern() {
Class<?> testClass = ClassPathStarLocationPatternTestCase.class;
// We can effectively only assert that an exception is not thrown; however,
@@ -63,7 +63,7 @@ class TestPropertySourceRuntimeHintsTests {
}
@Test
void testPropertySourceWithWildcardLocationPattern() {
void propertySourceWithWildcardLocationPattern() {
Class<?> testClass = WildcardLocationPatternTestCase.class;
// We can effectively only assert that an exception is not thrown; however,
@@ -141,13 +141,13 @@ public class TestBeanInheritanceIntegrationTests {
}
@Test // gh-34194, gh-34204
void testBeanInSubclassOverridesTestBeanInSuperclass() {
void beanInSubclassOverridesTestBeanInSuperclass() {
assertThat(ctx.getBean("enigmaBean")).as("applicationContext").hasToString("enigma in subclass");
assertThat(this.enigmaBean.value()).as("injection point").isEqualTo("enigma in subclass");
}
@Test // gh-34194, gh-34204
void testBeanInNestedClassOverridesTestBeanInEnclosingClass() {
void beanInNestedClassOverridesTestBeanInEnclosingClass() {
assertThat(ctx.getBean("puzzleBean")).as("applicationContext").hasToString("puzzle in nested class");
assertThat(this.puzzleBean.value()).as("injection point").isEqualTo("puzzle in nested class");
}
@@ -59,7 +59,7 @@ class TestBeanWithDirtiesContextBeforeMethodIntegrationTests {
@RepeatedTest(2)
@DirtiesContext(methodMode = BEFORE_METHOD)
void testOverride() {
void override() {
assertThat(service).isSameAs(autowiredService);
given(service.greeting()).willReturn("Spring");
@@ -61,7 +61,7 @@ public class MockitoBeanAndScopedProxyIntegrationTests {
}
@Test
void testMocking() {
void mocking() {
assertThat(serviceCaller.sayGreeting()).isEqualTo("I say mock");
}
@@ -56,7 +56,7 @@ class MockitoBeanWithDirtiesContextBeforeMethodIntegrationTests {
@RepeatedTest(2)
@DirtiesContext(methodMode = BEFORE_METHOD)
void testMocking() {
void mocking() {
assertThat(service).isSameAs(autowiredService);
given(service.greeting()).willReturn("Spring");
@@ -52,7 +52,7 @@ class MockitoBeanWithGenericsOnTestFieldForNewBeanIntegrationTests {
@Test
void testMocking() {
void mocking() {
given(stringService.greeting()).willReturn("Hello");
given(integerService.greeting()).willReturn(42);
assertThat(caller.sayGreeting()).isEqualTo("I say Hello 42");
@@ -58,7 +58,7 @@ class MockitoSpyBeanWithDirtiesContextBeforeMethodIntegrationTests {
@RepeatedTest(2)
@DirtiesContext(methodMode = BEFORE_METHOD)
void testSpying() {
void spying() {
assertThat(service).isSameAs(autowiredService);
assertThat(caller.sayGreeting()).isEqualTo("I say simple");
@@ -53,7 +53,7 @@ class MockitoSpyBeanWithGenericsOnTestFieldForExistingGenericBeanIntegrationTest
@Test
void testSpying() {
void spying() {
assertThat(caller.sayGreeting()).isEqualTo("I say Enigma 123");
then(service).should().greeting();
}
@@ -54,7 +54,7 @@ class MockitoSpyBeanWithGenericsOnTestFieldForExistingGenericBeanProducedByFacto
@Test
void testSpying() {
void spying() {
assertIsSpy(exampleService);
Object spiedInstance = mockingDetails(exampleService).getMockCreationSettings().getSpiedInstance();
@@ -56,7 +56,7 @@ class MockitoSpyBeanWithMultipleExistingBeansAndOnePrimaryIntegrationTests {
@Test
void testSpying() {
void spying() {
assertIsSpy(spy);
assertMockName(spy, "two");
@@ -54,7 +54,7 @@ class AotMergedContextConfigurationTests {
@Test
void testEquals() {
void equals() {
assertThat(aotMergedConfig1).isEqualTo(aotMergedConfig1);
assertThat(aotMergedConfig1).isEqualTo(aotMergedConfig2);
@@ -63,7 +63,7 @@ class AotMergedContextConfigurationTests {
}
@Test
void testHashCode() {
void hashCodeBehavior() {
assertThat(aotMergedConfig1).hasSameHashCodeAs(aotMergedConfig2);
assertThat(aotMergedConfig1).doesNotHaveSameHashCodeAs(mergedConfig);
@@ -95,7 +95,7 @@ class DirtiesContextInterfaceTests {
@Test
public void verifyContextWasAutowired() {
void verifyContextWasAutowired() {
assertThat(this.applicationContext).as("The application context should have been autowired.").isNotNull();
}
@@ -56,7 +56,7 @@ public class CustomTestEventTests {
}
@Test
public void customTestEventPublished() {
void customTestEventPublished() {
assertThat(events).hasSize(1);
CustomEvent customEvent = events.get(0);
assertThat(customEvent.getSource()).isEqualTo(getClass());
@@ -198,17 +198,17 @@ class DirtiesContextEventPublishingTests {
static class Config {
@BeforeTestClass
public void beforeTestClass(BeforeTestClassEvent e) {
void beforeTestClass(BeforeTestClassEvent e) {
events.add(e.getClass());
}
@PrepareTestInstance
public void prepareTestInstance(PrepareTestInstanceEvent e) {
void prepareTestInstance(PrepareTestInstanceEvent e) {
events.add(e.getClass());
}
@BeforeTestMethod
public void beforeTestMethod(BeforeTestMethodEvent e) {
void beforeTestMethod(BeforeTestMethodEvent e) {
events.add(e.getClass());
}
@@ -141,7 +141,7 @@ class EagerTestExecutionEventPublishingTests {
static class Config {
@BeforeTestClass
public void beforeTestClass(BeforeTestClassEvent e) {
void beforeTestClass(BeforeTestClassEvent e) {
events.add(e.getClass());
}
@@ -93,19 +93,19 @@ public class EventPublishingTestExecutionListenerIntegrationTests {
}
@Test
public void beforeTestClassAnnotation() throws Exception {
void beforeTestClassAnnotation() throws Exception {
testContextManager.beforeTestClass();
verify(listener, only()).beforeTestClass(testContext);
}
@Test
public void prepareTestInstanceAnnotation() throws Exception {
void prepareTestInstanceAnnotation() throws Exception {
testContextManager.prepareTestInstance(testInstance);
verify(listener, only()).prepareTestInstance(testContext);
}
@Test
public void beforeTestMethodAnnotation() throws Exception {
void beforeTestMethodAnnotation() throws Exception {
testContextManager.beforeTestMethod(testInstance, traceableTestMethod);
verify(listener, only()).beforeTestMethod(testContext);
}
@@ -117,7 +117,7 @@ public class EventPublishingTestExecutionListenerIntegrationTests {
* {@link ExampleTestCase#standardTest()} is not.
*/
@Test
public void beforeTestMethodAnnotationWithFailingCondition() throws Exception {
void beforeTestMethodAnnotationWithFailingCondition() throws Exception {
Method standardTest = ReflectionUtils.findMethod(ExampleTestCase.class, "standardTest");
testContextManager.beforeTestMethod(testInstance, standardTest);
verify(listener, never()).beforeTestMethod(testContext);
@@ -128,8 +128,8 @@ public class EventPublishingTestExecutionListenerIntegrationTests {
* should fail the test method.
*/
@Test
public void beforeTestMethodAnnotationWithFailingEventListener() throws Exception {
Method method = ReflectionUtils.findMethod(ExampleTestCase.class, "testWithFailingEventListener");
void beforeTestMethodAnnotationWithFailingEventListener() throws Exception {
Method method = ReflectionUtils.findMethod(ExampleTestCase.class, "withFailingEventListener");
assertThatRuntimeException()
.isThrownBy(() -> testContextManager.beforeTestMethod(testInstance, method))
.withMessageContaining("Boom!");
@@ -141,10 +141,10 @@ public class EventPublishingTestExecutionListenerIntegrationTests {
* should not fail the test method.
*/
@Test
public void beforeTestMethodAnnotationWithFailingAsyncEventListener() throws Exception {
void beforeTestMethodAnnotationWithFailingAsyncEventListener() throws Exception {
TrackingAsyncUncaughtExceptionHandler.asyncException = null;
String methodName = "testWithFailingAsyncEventListener";
String methodName = "withFailingAsyncEventListener";
Method method = ReflectionUtils.findMethod(ExampleTestCase.class, methodName);
testContextManager.beforeTestMethod(testInstance, method);
@@ -157,25 +157,25 @@ public class EventPublishingTestExecutionListenerIntegrationTests {
}
@Test
public void beforeTestExecutionAnnotation() throws Exception {
void beforeTestExecutionAnnotation() throws Exception {
testContextManager.beforeTestExecution(testInstance, traceableTestMethod);
verify(listener, only()).beforeTestExecution(testContext);
}
@Test
public void afterTestExecutionAnnotation() throws Exception {
void afterTestExecutionAnnotation() throws Exception {
testContextManager.afterTestExecution(testInstance, traceableTestMethod, null);
verify(listener, only()).afterTestExecution(testContext);
}
@Test
public void afterTestMethodAnnotation() throws Exception {
void afterTestMethodAnnotation() throws Exception {
testContextManager.afterTestMethod(testInstance, traceableTestMethod, null);
verify(listener, only()).afterTestMethod(testContext);
}
@Test
public void afterTestClassAnnotation() throws Exception {
void afterTestClassAnnotation() throws Exception {
testContextManager.afterTestClass();
verify(listener, only()).afterTestClass(testContext);
}
@@ -192,22 +192,22 @@ public class EventPublishingTestExecutionListenerIntegrationTests {
@Traceable
@Test
public void traceableTest() {
void traceableTest() {
/* no-op */
}
@Test
public void standardTest() {
void standardTest() {
/* no-op */
}
@Test
public void testWithFailingEventListener() {
void withFailingEventListener() {
/* no-op */
}
@Test
public void testWithFailingAsyncEventListener() {
void withFailingAsyncEventListener() {
/* no-op */
}
@@ -260,7 +260,7 @@ public class EventPublishingTestExecutionListenerIntegrationTests {
listener().beforeTestMethod(e.getSource());
}
@BeforeTestMethod("event.testContext.testMethod.name == 'testWithFailingEventListener'")
@BeforeTestMethod("event.testContext.testMethod.name == 'withFailingEventListener'")
public void beforeTestMethodWithFailure(BeforeTestMethodEvent event) throws Exception {
listener().beforeTestMethod(event.getSource());
throw new RuntimeException("Boom!");
@@ -305,7 +305,7 @@ public class EventPublishingTestExecutionListenerIntegrationTests {
this.listener = listener;
}
@BeforeTestMethod("event.testContext.testMethod.name == 'testWithFailingAsyncEventListener'")
@BeforeTestMethod("event.testContext.testMethod.name == 'withFailingAsyncEventListener'")
@Async
public void beforeTestMethodWithAsyncFailure(BeforeTestMethodEvent event) throws Exception {
this.listener.beforeTestMethod(event.getSource());
@@ -49,7 +49,7 @@ class ExpressionUsageTests {
@Test
void testSpr5906() {
void spr5906() {
// verify the property values have been evaluated as expressions
assertThat(props.getProperty("user.name")).isEqualTo("Dave");
assertThat(props.getProperty("username")).isEqualTo("Andy");
@@ -60,7 +60,7 @@ class ExpressionUsageTests {
}
@Test
void testSpr5847() {
void spr5847() {
assertThat(andy2.getName()).isEqualTo("Andy");
assertThat(andy.getName()).isEqualTo("Andy");
}
@@ -66,7 +66,7 @@ public class InitializerConfiguredViaMetaAnnotationTests {
@Test
public void beansFromInitializerAndComposedAnnotation() {
void beansFromInitializerAndComposedAnnotation() {
assertThat(strings).hasSize(2);
assertThat(foo).isEqualTo("foo");
assertThat(bar).isEqualTo("bar");
@@ -43,7 +43,7 @@ public class InitializerWithoutConfigFilesOrClassesTests {
@Test
public void foo() {
void foo() {
assertThat(foo).isEqualTo("foo");
}
@@ -37,7 +37,7 @@ public class MergedInitializersAnnotationConfigTests extends SingleInitializerAn
@Override
@Test
public void activeBeans() {
void activeBeans() {
assertThat(foo).isEqualTo("foo");
assertThat(bar).isEqualTo("foo");
assertThat(baz).isEqualTo("dev profile config");
@@ -43,7 +43,7 @@ public class MultipleInitializersAnnotationConfigTests {
@Test
public void activeBeans() {
void activeBeans() {
assertThat(foo).isEqualTo("foo");
assertThat(bar).isEqualTo("foo");
assertThat(baz).isEqualTo("dev profile config");
@@ -61,7 +61,7 @@ public class OrderedInitializersAnnotationConfigTests {
@Test
public void activeBeans() {
void activeBeans() {
assertThat(foo).isEqualTo(PROFILE_GLOBAL);
assertThat(bar).isEqualTo(PROFILE_GLOBAL);
assertThat(baz).isEqualTo(PROFILE_TWO);
@@ -74,12 +74,12 @@ public class OrderedInitializersAnnotationConfigTests {
static class GlobalConfig {
@Bean
public String foo() {
String foo() {
return PROFILE_GLOBAL;
}
@Bean
public String bar() {
String bar() {
return PROFILE_GLOBAL;
}
@@ -37,7 +37,7 @@ public class OverriddenInitializersAnnotationConfigTests extends SingleInitializ
@Test
@Override
public void activeBeans() {
void activeBeans() {
assertThat(foo).isEqualTo("foo");
assertThat(bar).isNull();
assertThat(baz).isEqualTo("dev profile config");
@@ -63,7 +63,7 @@ public class PropertySourcesInitializerTests {
@Test
public void customPropertySourceConfiguredViaContextInitializer() {
void customPropertySourceConfiguredViaContextInitializer() {
assertThat(enigma).isEqualTo("foo");
}
@@ -49,7 +49,7 @@ public class SingleInitializerAnnotationConfigTests {
@Test
public void activeBeans() {
void activeBeans() {
assertThat(foo).isEqualTo("foo");
assertThat(bar).isEqualTo("foo");
assertThat(baz).isEqualTo("global config");
@@ -42,7 +42,7 @@ public class MultipleInitializersXmlConfigTests {
@Test
public void activeBeans() {
void activeBeans() {
assertThat(foo).isEqualTo("foo");
assertThat(bar).isEqualTo("foo");
assertThat(baz).isEqualTo("dev profile config");
@@ -90,7 +90,7 @@ class FailingBeforeAndAfterMethodsSpringExtensionTests {
// something else like an error in the @Configuration class, etc.
if (getExpectedFailedCount(testClass) > 0) {
events.assertThatEvents().haveExactly(1,
event(test("testNothing"),
event(test("dummyTest"),
finishedWithFailure(
instanceOf(AssertionError.class),
message(msg -> msg.contains("always failing")))));
@@ -177,7 +177,7 @@ class FailingBeforeAndAfterMethodsSpringExtensionTests {
private abstract static class BaseTestCase {
@Test
void testNothing() {
void dummyTest() {
}
}
@@ -215,7 +215,7 @@ class FailingBeforeAndAfterMethodsSpringExtensionTests {
static class FailingBeforeTransactionTestCase {
@Test
void testNothing() {
void dummyTest() {
}
@BeforeTransaction
@@ -230,7 +230,7 @@ class FailingBeforeAndAfterMethodsSpringExtensionTests {
static class FailingAfterTransactionTestCase {
@Test
void testNothing() {
void dummyTest() {
}
@AfterTransaction
@@ -84,7 +84,7 @@ class AnnotatedConfigClassesWithoutAtConfigurationTests {
@Test
void testSPR_9051() {
void spr_9051() {
assertThat(enigma).isNotNull();
assertThat(lifecycleBean).isNotNull();
assertThat(lifecycleBean.isInitialized()).isTrue();
@@ -209,7 +209,7 @@ class BootstrapTestUtilsMergedConfigTests extends AbstractContextConfigurationUt
* @since 5.3
*/
@Test
public void buildMergedConfigForNestedTestClassWithInheritedConfig() {
void buildMergedConfigForNestedTestClassWithInheritedConfig() {
Class<?> testClass = OuterTestCase.NestedTestCaseWithInheritedConfig.class;
Class<?>[] expectedClasses = array(FooConfig.class);
MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClass);
@@ -222,7 +222,7 @@ class BootstrapTestUtilsMergedConfigTests extends AbstractContextConfigurationUt
* @since 5.3
*/
@Test
public void buildMergedConfigForNestedTestClassWithMergedInheritedConfig() {
void buildMergedConfigForNestedTestClassWithMergedInheritedConfig() {
Class<?> testClass = OuterTestCase.NestedTestCaseWithMergedInheritedConfig.class;
Class<?>[] expectedClasses = array(FooConfig.class, BarConfig.class);
MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClass);
@@ -235,7 +235,7 @@ class BootstrapTestUtilsMergedConfigTests extends AbstractContextConfigurationUt
* @since 5.3
*/
@Test
public void buildMergedConfigForNestedTestClassWithOverriddenConfig() {
void buildMergedConfigForNestedTestClassWithOverriddenConfig() {
Class<?> testClass = OuterTestCase.NestedTestCaseWithOverriddenConfig.class;
Class<?>[] expectedClasses = array(BarConfig.class);
MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClass);
@@ -248,7 +248,7 @@ class BootstrapTestUtilsMergedConfigTests extends AbstractContextConfigurationUt
* @since 5.3
*/
@Test
public void buildMergedConfigForDoubleNestedTestClassWithInheritedOverriddenConfig() {
void buildMergedConfigForDoubleNestedTestClassWithInheritedOverriddenConfig() {
Class<?> testClass = OuterTestCase.NestedTestCaseWithOverriddenConfig.DoubleNestedTestCaseWithInheritedOverriddenConfig.class;
Class<?>[] expectedClasses = array(BarConfig.class);
MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClass);
@@ -261,7 +261,7 @@ class BootstrapTestUtilsMergedConfigTests extends AbstractContextConfigurationUt
* @since 5.3
*/
@Test
public void buildMergedConfigForContextHierarchy() {
void buildMergedConfigForContextHierarchy() {
Class<?> testClass = ContextHierarchyOuterTestCase.class;
Class<?>[] expectedClasses = array(BarConfig.class);
@@ -280,7 +280,7 @@ class BootstrapTestUtilsMergedConfigTests extends AbstractContextConfigurationUt
* @since 5.3
*/
@Test
public void buildMergedConfigForNestedTestClassWithInheritedConfigForContextHierarchy() {
void buildMergedConfigForNestedTestClassWithInheritedConfigForContextHierarchy() {
Class<?> enclosingTestClass = ContextHierarchyOuterTestCase.class;
Class<?> testClass = ContextHierarchyOuterTestCase.NestedTestCaseWithInheritedConfig.class;
Class<?>[] expectedClasses = array(BarConfig.class);
@@ -300,7 +300,7 @@ class BootstrapTestUtilsMergedConfigTests extends AbstractContextConfigurationUt
* @since 5.3
*/
@Test
public void buildMergedConfigForNestedTestClassWithMergedInheritedConfigForContextHierarchy() {
void buildMergedConfigForNestedTestClassWithMergedInheritedConfigForContextHierarchy() {
Class<?> testClass = ContextHierarchyOuterTestCase.NestedTestCaseWithMergedInheritedConfig.class;
Class<?>[] expectedClasses = array(BarConfig.class, BazConfig.class);
@@ -319,7 +319,7 @@ class BootstrapTestUtilsMergedConfigTests extends AbstractContextConfigurationUt
* @since 5.3
*/
@Test
public void buildMergedConfigForNestedTestClassWithOverriddenConfigForContextHierarchy() {
void buildMergedConfigForNestedTestClassWithOverriddenConfigForContextHierarchy() {
Class<?> testClass = ContextHierarchyOuterTestCase.NestedTestCaseWithOverriddenConfig.class;
MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClass);
assertThat(mergedConfig).as("merged config").isNotNull();
@@ -60,12 +60,12 @@ class TestConstructorUtilsTests {
}
@Test
void testConstructorAnnotation() throws Exception {
void constructorAnnotation() throws Exception {
assertAutowirable(TestConstructorAnnotationTestCase.class);
}
@Test
void testConstructorAsMetaAnnotation() throws Exception {
void constructorAsMetaAnnotation() throws Exception {
assertAutowirable(TestConstructorAsMetaAnnotationTestCase.class);
}
@@ -146,7 +146,7 @@ class FailingBeforeAndAfterMethodsTestNGTests {
abstract static class BaseTestCase extends AbstractTestNGSpringContextTests {
@org.testng.annotations.Test
void testNothing() {
void nothing() {
}
}
@@ -182,7 +182,7 @@ class FailingBeforeAndAfterMethodsTestNGTests {
static class FailingBeforeTransactionTestCase extends AbstractTransactionalTestNGSpringContextTests {
@org.testng.annotations.Test
void testNothing() {
void nothing() {
}
@BeforeTransaction
@@ -195,7 +195,7 @@ class FailingBeforeAndAfterMethodsTestNGTests {
static class FailingAfterTransactionTestCase extends AbstractTransactionalTestNGSpringContextTests {
@org.testng.annotations.Test
void testNothing() {
void nothing() {
}
@AfterTransaction
@@ -58,52 +58,52 @@ class TestNGConcurrencyTests {
static class ConcurrentTestCase extends AbstractTestNGSpringContextTests {
@Test(expectedExceptions = RuntimeException.class, expectedExceptionsMessageRegExp = "Message1")
public void message1() {
void message1() {
throw new RuntimeException("Message1");
}
@Test(expectedExceptions = RuntimeException.class, expectedExceptionsMessageRegExp = "Message2")
public void message2() {
void message2() {
throw new RuntimeException("Message2");
}
@Test(expectedExceptions = RuntimeException.class, expectedExceptionsMessageRegExp = "Message3")
public void message3() {
void message3() {
throw new RuntimeException("Message3");
}
@Test(expectedExceptions = RuntimeException.class, expectedExceptionsMessageRegExp = "Message4")
public void message4() {
void message4() {
throw new RuntimeException("Message4");
}
@Test(expectedExceptions = RuntimeException.class, expectedExceptionsMessageRegExp = "Message5")
public void message5() {
void message5() {
throw new RuntimeException("Message5");
}
@Test(expectedExceptions = RuntimeException.class, expectedExceptionsMessageRegExp = "Message6")
public void message6() {
void message6() {
throw new RuntimeException("Message6");
}
@Test(expectedExceptions = RuntimeException.class, expectedExceptionsMessageRegExp = "Message7")
public void message7() {
void message7() {
throw new RuntimeException("Message7");
}
@Test(expectedExceptions = RuntimeException.class, expectedExceptionsMessageRegExp = "Message8")
public void message8() {
void message8() {
throw new RuntimeException("Message8");
}
@Test(expectedExceptions = RuntimeException.class, expectedExceptionsMessageRegExp = "Message9")
public void message9() {
void message9() {
throw new RuntimeException("Message9");
}
@Test(expectedExceptions = RuntimeException.class, expectedExceptionsMessageRegExp = "Message10")
public void message10() {
void message10() {
throw new RuntimeException("Message10");
}
@@ -43,7 +43,7 @@ public class ContentRequestMatchersTests {
@Test
public void testContentType() throws Exception {
void contentType() throws Exception {
this.request.getHeaders().setContentType(MediaType.APPLICATION_JSON);
MockRestRequestMatchers.content().contentType("application/json").match(this.request);
@@ -51,7 +51,7 @@ public class ContentRequestMatchersTests {
}
@Test
public void testContentTypeNoMatch1() {
void contentTypeNoMatch1() {
this.request.getHeaders().setContentType(MediaType.APPLICATION_JSON);
assertThatExceptionOfType(AssertionError.class).isThrownBy(() ->
@@ -59,7 +59,7 @@ public class ContentRequestMatchersTests {
}
@Test
public void testContentTypeNoMatch2() {
void contentTypeNoMatch2() {
this.request.getHeaders().setContentType(MediaType.APPLICATION_JSON);
assertThatExceptionOfType(AssertionError.class).isThrownBy(() ->
@@ -67,14 +67,14 @@ public class ContentRequestMatchersTests {
}
@Test
public void testString() throws Exception {
void string() throws Exception {
this.request.getBody().write("test".getBytes());
MockRestRequestMatchers.content().string("test").match(this.request);
}
@Test
public void testStringNoMatch() throws Exception {
void stringNoMatch() throws Exception {
this.request.getBody().write("test".getBytes());
assertThatExceptionOfType(AssertionError.class).isThrownBy(() ->
@@ -82,7 +82,7 @@ public class ContentRequestMatchersTests {
}
@Test
public void testBytes() throws Exception {
void bytes() throws Exception {
byte[] content = "test".getBytes();
this.request.getBody().write(content);
@@ -90,7 +90,7 @@ public class ContentRequestMatchersTests {
}
@Test
public void testBytesNoMatch() throws Exception {
void bytesNoMatch() throws Exception {
this.request.getBody().write("test".getBytes());
assertThatExceptionOfType(AssertionError.class).isThrownBy(() ->
@@ -98,7 +98,7 @@ public class ContentRequestMatchersTests {
}
@Test
public void testFormData() throws Exception {
void formData() throws Exception {
String contentType = "application/x-www-form-urlencoded;charset=UTF-8";
String body = "name+1=value+1&name+2=value+A&name+2=value+B&name+3";
@@ -114,7 +114,7 @@ public class ContentRequestMatchersTests {
}
@Test
public void testFormDataContains() throws Exception {
void formDataContains() throws Exception {
String contentType = "application/x-www-form-urlencoded;charset=UTF-8";
String body = "name+1=value+1&name+2=value+A&name+2=value+B&name+3";
@@ -127,7 +127,7 @@ public class ContentRequestMatchersTests {
}
@Test
public void testMultipartData() throws Exception {
void multipartData() throws Exception {
String contentType = "multipart/form-data;boundary=1234567890";
String body = """
--1234567890\r
@@ -161,7 +161,7 @@ public class ContentRequestMatchersTests {
}
@Test
public void testMultipartDataContains() throws Exception {
void multipartDataContains() throws Exception {
String contentType = "multipart/form-data;boundary=1234567890";
String body = """
--1234567890\r
@@ -197,7 +197,7 @@ public class ContentRequestMatchersTests {
}
@Test
public void testXml() throws Exception {
void xml() throws Exception {
String content = "<foo><bar>baz</bar><bar>bazz</bar></foo>";
this.request.getBody().write(content.getBytes());
@@ -205,7 +205,7 @@ public class ContentRequestMatchersTests {
}
@Test
public void testXmlNoMatch() throws Exception {
void xmlNoMatch() throws Exception {
this.request.getBody().write("<foo>11</foo>".getBytes());
assertThatExceptionOfType(AssertionError.class).isThrownBy(() ->
@@ -213,7 +213,7 @@ public class ContentRequestMatchersTests {
}
@Test
public void testNodeMatcher() throws Exception {
void nodeMatcher() throws Exception {
String content = "<foo><bar>baz</bar></foo>";
this.request.getBody().write(content.getBytes());
@@ -221,7 +221,7 @@ public class ContentRequestMatchersTests {
}
@Test
public void testNodeMatcherNoMatch() throws Exception {
void nodeMatcherNoMatch() throws Exception {
String content = "<foo><bar>baz</bar></foo>";
this.request.getBody().write(content.getBytes());
assertThatExceptionOfType(AssertionError.class).isThrownBy(() ->
@@ -229,7 +229,7 @@ public class ContentRequestMatchersTests {
}
@Test
public void testJsonLenientMatch() throws Exception {
void jsonLenientMatch() throws Exception {
String content = "{\n \"foo array\":[\"first\",\"second\"] , \"someExtraProperty\": \"which is allowed\" \n}";
this.request.getBody().write(content.getBytes());
@@ -241,7 +241,7 @@ public class ContentRequestMatchersTests {
@Test
@Deprecated
public void testJsonLenientMatchWithDeprecatedBooleanFlag() throws Exception {
void jsonLenientMatchWithDeprecatedBooleanFlag() throws Exception {
String content = "{\n \"foo array\":[\"first\",\"second\"] , \"someExtraProperty\": \"which is allowed\" \n}";
this.request.getBody().write(content.getBytes());
@@ -250,7 +250,7 @@ public class ContentRequestMatchersTests {
}
@Test
public void testJsonStrictMatch() throws Exception {
void jsonStrictMatch() throws Exception {
String content = "{\n \"foo\": \"bar\", \"foo array\":[\"first\",\"second\"] \n}";
this.request.getBody().write(content.getBytes());
@@ -262,7 +262,7 @@ public class ContentRequestMatchersTests {
@Test
@Deprecated
public void testJsonStrictMatchWithDeprecatedBooleanFlag() throws Exception {
void jsonStrictMatchWithDeprecatedBooleanFlag() throws Exception {
String content = "{\n \"foo\": \"bar\", \"foo array\":[\"first\",\"second\"] \n}";
this.request.getBody().write(content.getBytes());
@@ -273,7 +273,7 @@ public class ContentRequestMatchersTests {
}
@Test
public void testJsonLenientNoMatch() throws Exception {
void jsonLenientNoMatch() throws Exception {
String content = "{\n \"bar\" : \"foo\" \n}";
this.request.getBody().write(content.getBytes());
@@ -291,7 +291,7 @@ public class ContentRequestMatchersTests {
@Test
@Deprecated
public void testJsonLenientNoMatchWithDeprecatedBooleanFlag() throws Exception {
void jsonLenientNoMatchWithDeprecatedBooleanFlag() throws Exception {
String content = "{\n \"bar\" : \"foo\" \n}";
this.request.getBody().write(content.getBytes());
@@ -303,7 +303,7 @@ public class ContentRequestMatchersTests {
}
@Test
public void testJsonStrictNoMatch() throws Exception {
void jsonStrictNoMatch() throws Exception {
String content = "{\n \"foo array\":[\"first\",\"second\"] , \"someExtraProperty\": \"which is NOT allowed\" \n}";
this.request.getBody().write(content.getBytes());
@@ -316,7 +316,7 @@ public class ContentRequestMatchersTests {
@Test
@Deprecated
public void testJsonStrictNoMatchWithDeprecatedBooleanFlag() throws Exception {
void jsonStrictNoMatchWithDeprecatedBooleanFlag() throws Exception {
String content = "{\n \"foo array\":[\"first\",\"second\"] , \"someExtraProperty\": \"which is NOT allowed\" \n}";
this.request.getBody().write(content.getBytes());
@@ -58,200 +58,200 @@ public class JsonPathRequestMatchersTests {
@Test
public void valueWithMismatch() {
void valueWithMismatch() {
assertThatExceptionOfType(AssertionError.class).isThrownBy(() ->
new JsonPathRequestMatchers("$.str").value("bogus").match(request));
}
@Test
public void valueWithDirectMatch() throws Exception {
void valueWithDirectMatch() throws Exception {
new JsonPathRequestMatchers("$.str").value("foo").match(request);
}
@Test // SPR-14498
public void valueWithNumberConversion() throws Exception {
void valueWithNumberConversion() throws Exception {
new JsonPathRequestMatchers("$.num").value(5.0f).match(request);
}
@Test
public void valueWithMatcher() throws Exception {
void valueWithMatcher() throws Exception {
new JsonPathRequestMatchers("$.str").value(equalTo("foo")).match(request);
}
@Test // SPR-14498
public void valueWithMatcherAndNumberConversion() throws Exception {
void valueWithMatcherAndNumberConversion() throws Exception {
new JsonPathRequestMatchers("$.num").value(equalTo(5.0f), Float.class).match(request);
}
@Test
public void valueWithMatcherAndMismatch() {
void valueWithMatcherAndMismatch() {
assertThatExceptionOfType(AssertionError.class).isThrownBy(() ->
new JsonPathRequestMatchers("$.str").value(equalTo("bogus")).match(request));
}
@Test
public void exists() throws Exception {
void exists() throws Exception {
new JsonPathRequestMatchers("$.str").exists().match(request);
}
@Test
public void existsForAnEmptyArray() throws Exception {
void existsForAnEmptyArray() throws Exception {
new JsonPathRequestMatchers("$.emptyArray").exists().match(request);
}
@Test
public void existsForAnEmptyMap() throws Exception {
void existsForAnEmptyMap() throws Exception {
new JsonPathRequestMatchers("$.emptyMap").exists().match(request);
}
@Test
public void existsNoMatch() {
void existsNoMatch() {
assertThatExceptionOfType(AssertionError.class).isThrownBy(() ->
new JsonPathRequestMatchers("$.bogus").exists().match(request));
}
@Test
public void doesNotExist() throws Exception {
void doesNotExist() throws Exception {
new JsonPathRequestMatchers("$.bogus").doesNotExist().match(request);
}
@Test
public void doesNotExistNoMatch() {
void doesNotExistNoMatch() {
assertThatExceptionOfType(AssertionError.class).isThrownBy(() ->
new JsonPathRequestMatchers("$.str").doesNotExist().match(request));
}
@Test
public void doesNotExistForAnEmptyArray() {
void doesNotExistForAnEmptyArray() {
assertThatExceptionOfType(AssertionError.class).isThrownBy(() ->
new JsonPathRequestMatchers("$.emptyArray").doesNotExist().match(request));
}
@Test
public void doesNotExistForAnEmptyMap() {
void doesNotExistForAnEmptyMap() {
assertThatExceptionOfType(AssertionError.class).isThrownBy(() ->
new JsonPathRequestMatchers("$.emptyMap").doesNotExist().match(request));
}
@Test
public void isEmptyForAnEmptyString() throws Exception {
void isEmptyForAnEmptyString() throws Exception {
new JsonPathRequestMatchers("$.emptyString").isEmpty().match(request);
}
@Test
public void isEmptyForAnEmptyArray() throws Exception {
void isEmptyForAnEmptyArray() throws Exception {
new JsonPathRequestMatchers("$.emptyArray").isEmpty().match(request);
}
@Test
public void isEmptyForAnEmptyMap() throws Exception {
void isEmptyForAnEmptyMap() throws Exception {
new JsonPathRequestMatchers("$.emptyMap").isEmpty().match(request);
}
@Test
public void isNotEmptyForString() throws Exception {
void isNotEmptyForString() throws Exception {
new JsonPathRequestMatchers("$.str").isNotEmpty().match(request);
}
@Test
public void isNotEmptyForNumber() throws Exception {
void isNotEmptyForNumber() throws Exception {
new JsonPathRequestMatchers("$.num").isNotEmpty().match(request);
}
@Test
public void isNotEmptyForBoolean() throws Exception {
void isNotEmptyForBoolean() throws Exception {
new JsonPathRequestMatchers("$.bool").isNotEmpty().match(request);
}
@Test
public void isNotEmptyForArray() throws Exception {
void isNotEmptyForArray() throws Exception {
new JsonPathRequestMatchers("$.arr").isNotEmpty().match(request);
}
@Test
public void isNotEmptyForMap() throws Exception {
void isNotEmptyForMap() throws Exception {
new JsonPathRequestMatchers("$.colorMap").isNotEmpty().match(request);
}
@Test
public void isNotEmptyForAnEmptyString() {
void isNotEmptyForAnEmptyString() {
assertThatExceptionOfType(AssertionError.class).isThrownBy(() ->
new JsonPathRequestMatchers("$.emptyString").isNotEmpty().match(request));
}
@Test
public void isNotEmptyForAnEmptyArray() {
void isNotEmptyForAnEmptyArray() {
assertThatExceptionOfType(AssertionError.class).isThrownBy(() ->
new JsonPathRequestMatchers("$.emptyArray").isNotEmpty().match(request));
}
@Test
public void isNotEmptyForAnEmptyMap() {
void isNotEmptyForAnEmptyMap() {
assertThatExceptionOfType(AssertionError.class).isThrownBy(() ->
new JsonPathRequestMatchers("$.emptyMap").isNotEmpty().match(request));
}
@Test
public void isArray() throws Exception {
void isArray() throws Exception {
new JsonPathRequestMatchers("$.arr").isArray().match(request);
}
@Test
public void isArrayForAnEmptyArray() throws Exception {
void isArrayForAnEmptyArray() throws Exception {
new JsonPathRequestMatchers("$.emptyArray").isArray().match(request);
}
@Test
public void isArrayNoMatch() {
void isArrayNoMatch() {
assertThatExceptionOfType(AssertionError.class).isThrownBy(() ->
new JsonPathRequestMatchers("$.str").isArray().match(request));
}
@Test
public void isMap() throws Exception {
void isMap() throws Exception {
new JsonPathRequestMatchers("$.colorMap").isMap().match(request);
}
@Test
public void isMapForAnEmptyMap() throws Exception {
void isMapForAnEmptyMap() throws Exception {
new JsonPathRequestMatchers("$.emptyMap").isMap().match(request);
}
@Test
public void isMapNoMatch() {
void isMapNoMatch() {
assertThatExceptionOfType(AssertionError.class).isThrownBy(() ->
new JsonPathRequestMatchers("$.str").isMap().match(request));
}
@Test
public void isBoolean() throws Exception {
void isBoolean() throws Exception {
new JsonPathRequestMatchers("$.bool").isBoolean().match(request);
}
@Test
public void isBooleanNoMatch() {
void isBooleanNoMatch() {
assertThatExceptionOfType(AssertionError.class).isThrownBy(() ->
new JsonPathRequestMatchers("$.str").isBoolean().match(request));
}
@Test
public void isNumber() throws Exception {
void isNumber() throws Exception {
new JsonPathRequestMatchers("$.num").isNumber().match(request);
}
@Test
public void isNumberNoMatch() {
void isNumberNoMatch() {
assertThatExceptionOfType(AssertionError.class).isThrownBy(() ->
new JsonPathRequestMatchers("$.str").isNumber().match(request));
}
@Test
public void isString() throws Exception {
void isString() throws Exception {
new JsonPathRequestMatchers("$.str").isString().match(request);
}
@Test
public void isStringNoMatch() {
void isStringNoMatch() {
assertThatExceptionOfType(AssertionError.class).isThrownBy(() ->
new JsonPathRequestMatchers("$.arr").isString().match(request));
}
@@ -60,7 +60,7 @@ public class MultipartRequestMatchersTests {
@Test
public void testContains() throws Exception {
void contains() throws Exception {
this.input.add("foo", "bar");
this.input.add("foo", "baz");
this.input.add("lorem", "ipsum");
@@ -71,7 +71,7 @@ public class MultipartRequestMatchersTests {
}
@Test
public void testDoesNotContain() {
void doesNotContain() {
this.input.add("foo", "bar");
this.input.add("foo", "baz");
this.input.add("lorem", "ipsum");
@@ -82,7 +82,7 @@ public class MultipartRequestMatchersTests {
}
@Test
public void testParamsMatch() throws Exception {
void paramsMatch() throws Exception {
this.input.add("foo", "value 1");
this.input.add("bar", "value A");
this.input.add("baz", "value B");
@@ -93,7 +93,7 @@ public class MultipartRequestMatchersTests {
}
@Test
public void testResourceMatch() throws Exception {
void resourceMatch() throws Exception {
MultipartFile f1 = new MockMultipartFile("f1", "foo.txt", "text/plain", "Foo Lorem ipsum".getBytes());
MultipartFile f2 = new MockMultipartFile("f2", "bar.txt", "text/plain", "Bar Lorem ipsum".getBytes());
MultipartFile f3 = new MockMultipartFile("f3", "foobar.txt", "text/plain", "Foobar Lorem ipsum".getBytes());
@@ -110,7 +110,7 @@ public class MultipartRequestMatchersTests {
}
@Test
public void testResourceNoMatch() {
void resourceNoMatch() {
MockMultipartFile foo = new MockMultipartFile("f1", "foo.txt", "text/plain", "Foo Lorem ipsum".getBytes());
MockMultipartFile bar = new MockMultipartFile("f2", "bar.txt", "text/plain", "Bar Lorem ipsum".getBytes());
@@ -126,7 +126,7 @@ public class MultipartRequestMatchersTests {
}
@Test
public void testByteArrayMatch() throws Exception {
void byteArrayMatch() throws Exception {
MultipartFile f1 = new MockMultipartFile("f1", "foo.txt", "text/plain", "Foo Lorem ipsum".getBytes());
MultipartFile f2 = new MockMultipartFile("f2", "bar.txt", "text/plain", "Bar Lorem ipsum".getBytes());
MultipartFile f3 = new MockMultipartFile("f3", "foobar.txt", "text/plain", "Foobar Lorem ipsum".getBytes());
@@ -146,7 +146,7 @@ public class MultipartRequestMatchersTests {
}
@Test
public void testByteArrayNoMatch() throws Exception {
void byteArrayNoMatch() throws Exception {
MultipartFile f1 = new MockMultipartFile("f1", "foo.txt", "text/plain", "Foo Lorem ipsum".getBytes());
MultipartFile f2 = new MockMultipartFile("f2", "bar.txt", "text/plain", "Bar Lorem ipsum".getBytes());
@@ -162,7 +162,7 @@ public class MultipartRequestMatchersTests {
}
@Test // gh-36154
public void testHttpEntityMatch() throws Exception {
void httpEntityMatch() throws Exception {
String contentType = "text/plain";
MultipartFile file = new MockMultipartFile("file", "foo.txt", contentType, "Foo Lorem ipsum".getBytes());
@@ -46,78 +46,78 @@ public class XpathRequestMatchersTests {
@Test
public void testNodeMatcher() throws Exception {
void nodeMatcher() throws Exception {
new XpathRequestMatchers("/foo/bar", null).node(Matchers.notNullValue()).match(this.request);
}
@Test
public void testNodeMatcherNoMatch() {
void nodeMatcherNoMatch() {
assertThatExceptionOfType(AssertionError.class).isThrownBy(() ->
new XpathRequestMatchers("/foo/bar", null).node(Matchers.nullValue()).match(this.request));
}
@Test
public void testExists() throws Exception {
void exists() throws Exception {
new XpathRequestMatchers("/foo/bar", null).exists().match(this.request);
}
@Test
public void testExistsNoMatch() {
void existsNoMatch() {
assertThatExceptionOfType(AssertionError.class).isThrownBy(() ->
new XpathRequestMatchers("/foo/Bar", null).exists().match(this.request));
}
@Test
public void testDoesNotExist() throws Exception {
void doesNotExist() throws Exception {
new XpathRequestMatchers("/foo/Bar", null).doesNotExist().match(this.request);
}
@Test
public void testDoesNotExistNoMatch() {
void doesNotExistNoMatch() {
assertThatExceptionOfType(AssertionError.class).isThrownBy(() ->
new XpathRequestMatchers("/foo/bar", null).doesNotExist().match(this.request));
}
@Test
public void testNodeCount() throws Exception {
void nodeCount() throws Exception {
new XpathRequestMatchers("/foo/bar", null).nodeCount(2).match(this.request);
}
@Test
public void testNodeCountNoMatch() {
void nodeCountNoMatch() {
assertThatExceptionOfType(AssertionError.class).isThrownBy(() ->
new XpathRequestMatchers("/foo/bar", null).nodeCount(1).match(this.request));
}
@Test
public void testString() throws Exception {
void string() throws Exception {
new XpathRequestMatchers("/foo/bar[1]", null).string("111").match(this.request);
}
@Test
public void testStringNoMatch() {
void stringNoMatch() {
assertThatExceptionOfType(AssertionError.class).isThrownBy(() ->
new XpathRequestMatchers("/foo/bar[1]", null).string("112").match(this.request));
}
@Test
public void testNumber() throws Exception {
void number() throws Exception {
new XpathRequestMatchers("/foo/bar[1]", null).number(111.0).match(this.request);
}
@Test
public void testNumberNoMatch() {
void numberNoMatch() {
assertThatExceptionOfType(AssertionError.class).isThrownBy(() ->
new XpathRequestMatchers("/foo/bar[1]", null).number(111.1).match(this.request));
}
@Test
public void testBoolean() throws Exception {
void booleanCase() throws Exception {
new XpathRequestMatchers("/foo/bar[2]", null).booleanValue(true).match(this.request);
}
@Test
public void testBooleanNoMatch() {
void booleanNoMatch() {
assertThatExceptionOfType(AssertionError.class).isThrownBy(() ->
new XpathRequestMatchers("/foo/bar[2]", null).booleanValue(false).match(this.request));
}
@@ -56,7 +56,7 @@ class HeaderRequestMatchersIntegrationTests {
@Test
void testString() {
void string() {
this.mockServer.expect(requestTo("/person/1"))
.andExpect(header("Accept", "application/json, application/*+json"))
.andRespond(withSuccess(RESPONSE_BODY, MediaType.APPLICATION_JSON));
@@ -65,7 +65,7 @@ class HeaderRequestMatchersIntegrationTests {
}
@Test
void testStringContains() {
void stringContains() {
this.mockServer.expect(requestTo("/person/1"))
.andExpect(header("Accept", containsString("json")))
.andRespond(withSuccess(RESPONSE_BODY, MediaType.APPLICATION_JSON));
@@ -86,7 +86,7 @@ class XmlContentRequestMatchersIntegrationTests {
}
@Test
void testXmlEqualTo() {
void xmlEqualTo() {
this.mockServer.expect(requestTo("/composers"))
.andExpect(content().contentType("application/xml"))
.andExpect(content().xml(PEOPLE_XML))
@@ -96,7 +96,7 @@ class XmlContentRequestMatchersIntegrationTests {
}
@Test
void testHamcrestNodeMatcher() {
void hamcrestNodeMatcher() {
this.mockServer.expect(requestTo("/composers"))
.andExpect(content().contentType("application/xml"))
.andExpect(content().node(hasXPath("/people/composers/composer[1]")))
@@ -91,7 +91,7 @@ public class XpathRequestMatchersIntegrationTests {
@Test
public void testExists() throws Exception {
void exists() throws Exception {
String composer = "/ns:people/composers/composer[%s]";
String performer = "/ns:people/performers/performer[%s]";
@@ -109,7 +109,7 @@ public class XpathRequestMatchersIntegrationTests {
}
@Test
public void testDoesNotExist() throws Exception {
void doesNotExist() throws Exception {
String composer = "/ns:people/composers/composer[%s]";
String performer = "/ns:people/performers/performer[%s]";
@@ -125,7 +125,7 @@ public class XpathRequestMatchersIntegrationTests {
}
@Test
public void testString() throws Exception {
void string() throws Exception {
String composerName = "/ns:people/composers/composer[%s]/name";
String performerName = "/ns:people/performers/performer[%s]/name";
@@ -146,7 +146,7 @@ public class XpathRequestMatchersIntegrationTests {
}
@Test
public void testNumber() throws Exception {
void number() throws Exception {
String composerDouble = "/ns:people/composers/composer[%s]/someDouble";
this.mockServer.expect(requestTo("/composers"))
@@ -163,7 +163,7 @@ public class XpathRequestMatchersIntegrationTests {
}
@Test
public void testBoolean() throws Exception {
void booleanCase() throws Exception {
String performerBooleanValue = "/ns:people/performers/performer[%s]/someBoolean";
@@ -177,7 +177,7 @@ public class XpathRequestMatchersIntegrationTests {
}
@Test
public void testNodeCount() throws Exception {
void nodeCount() throws Exception {
this.mockServer.expect(requestTo("/composers"))
.andExpect(content().contentType("application/xml"))
.andExpect(xpath("/ns:people/composers/composer", NS).nodeCount(4))
@@ -38,7 +38,7 @@ public class ApplicationContextSpecTests {
@Test // SPR-17094
public void sessionManagerBean() {
void sessionManagerBean() {
ApplicationContext context = new AnnotationConfigApplicationContext(WebConfig.class);
ApplicationContextSpec spec = new ApplicationContextSpec(context);
WebTestClient testClient = spec.configureClient().build();
@@ -44,7 +44,7 @@ import static org.assertj.core.api.Assertions.assertThat;
public class DefaultControllerSpecTests {
@Test
public void controller() {
void controller() {
new DefaultControllerSpec(new MyController()).build()
.get().uri("/")
.exchange()
@@ -59,7 +59,7 @@ public class DefaultControllerSpecTests {
}
@Test
public void controllerAdvice() {
void controllerAdvice() {
new DefaultControllerSpec(new MyController())
.controllerAdvice(new MyControllerAdvice())
.build()
@@ -70,7 +70,7 @@ public class DefaultControllerSpecTests {
}
@Test
public void controllerAdviceWithClassArgument() {
void controllerAdviceWithClassArgument() {
new DefaultControllerSpec(MyController.class)
.controllerAdvice(MyControllerAdvice.class)
.build()
@@ -81,7 +81,7 @@ public class DefaultControllerSpecTests {
}
@Test
public void configurerConsumers() {
void configurerConsumers() {
TestConsumer<ArgumentResolverConfigurer> argumentResolverConsumer = new TestConsumer<>();
TestConsumer<RequestedContentTypeResolverBuilder> contentTypeResolverConsumer = new TestConsumer<>();
TestConsumer<CorsRegistry> corsRegistryConsumer = new TestConsumer<>();
@@ -113,7 +113,7 @@ public class DefaultControllerSpecTests {
}
@Test // gh-25854
public void uriTemplate() {
void uriTemplate() {
new DefaultControllerSpec(new MyController()).build()
.get().uri("/")
.exchange()
@@ -33,7 +33,7 @@ import org.springframework.web.reactive.function.server.ServerResponse;
public class DefaultRouterFunctionSpecTests {
@Test
public void webFilter() {
void webFilter() {
RouterFunction<ServerResponse> routerFunction = RouterFunctions.route()
.GET("/", request -> ServerResponse.ok().build())
@@ -55,7 +55,7 @@ public class DefaultRouterFunctionSpecTests {
}
@Test
public void exceptionHandler() {
void exceptionHandler() {
RouterFunction<ServerResponse> routerFunction = RouterFunctions.route()
.GET("/error", request -> Mono.error(new IllegalStateException("boo")))
@@ -51,7 +51,7 @@ import static org.assertj.core.api.Assertions.assertThat;
public class HttpHandlerConnectorTests {
@Test
public void adaptRequest() {
void adaptRequest() {
TestHttpHandler handler = new TestHttpHandler(response -> {
response.setStatusCode(HttpStatus.OK);
@@ -79,7 +79,7 @@ public class HttpHandlerConnectorTests {
}
@Test
public void adaptResponse() {
void adaptResponse() {
ResponseCookie cookie = ResponseCookie.from("custom-cookie", "c0").build();
@@ -105,7 +105,7 @@ public class HttpHandlerConnectorTests {
}
@Test // gh-23936
public void handlerOnNonBlockingThread() {
void handlerOnNonBlockingThread() {
TestHttpHandler handler = new TestHttpHandler(response -> {
@@ -43,7 +43,7 @@ public class MockServerSpecTests {
@Test
public void applyFiltersAfterConfigurerAdded() {
void applyFiltersAfterConfigurerAdded() {
MockServerConfigurer configurer = new MockServerConfigurer() {
@@ -67,7 +67,7 @@ public class MockServerSpecTests {
}
@Test
public void applyFiltersBeforeServerCreated() {
void applyFiltersBeforeServerCreated() {
MockServerConfigurer configurer = new MockServerConfigurer() {
@@ -41,7 +41,7 @@ public class MockServerTests {
@Test // SPR-15674 (in comments)
public void mutateDoesNotCreateNewSession() {
void mutateDoesNotCreateNewSession() {
WebTestClient client = WebTestClient
.bindToWebHandler(exchange -> {
@@ -76,7 +76,7 @@ public class MockServerTests {
}
@Test // SPR-16059
public void mutateDoesCopy() {
void mutateDoesCopy() {
WebTestClient.Builder builder = WebTestClient
.bindToWebHandler(exchange -> exchange.getResponse().setComplete())
@@ -113,7 +113,7 @@ public class MockServerTests {
}
@Test // SPR-16124
public void exchangeResultHasCookieHeaders() {
void exchangeResultHasCookieHeaders() {
ExchangeResult result = WebTestClient
.bindToWebHandler(exchange -> {
@@ -138,7 +138,7 @@ public class MockServerTests {
}
@Test
public void responseBodyContentWithFluxExchangeResult() {
void responseBodyContentWithFluxExchangeResult() {
FluxExchangeResult<String> result = WebTestClient
.bindToWebHandler(exchange -> {
@@ -61,7 +61,7 @@ public class WiretapConnectorTests {
}
@Test
public void captureAndClaim() {
void captureAndClaim() {
ClientHttpRequest request = new MockClientHttpRequest(HttpMethod.GET, "/test");
ClientHttpResponse response = new MockClientHttpResponse(HttpStatus.OK);
ClientHttpConnector connector = createConnector(request, response);
@@ -41,7 +41,7 @@ public class ControllerTests {
@Test
public void test() throws Exception {
void test() throws Exception {
this.client.get().uri("/test")
.exchange()
.expectStatus().isOk()
@@ -64,7 +64,7 @@ public class HttpServerTests {
@Test
public void test() {
void test() {
this.client.get().uri("/test")
.exchange()
.expectStatus().isOk()
@@ -47,7 +47,7 @@ public class RouterFunctionTests {
}
@Test
public void test() throws Exception {
void test() throws Exception {
this.testClient.get().uri("/test")
.exchange()
.expectStatus().isOk()
@@ -34,14 +34,14 @@ public class DefaultMvcResultTests {
private final DefaultMvcResult mvcResult = new DefaultMvcResult(new MockHttpServletRequest(), null);
@Test
public void getAsyncResultSuccess() {
void getAsyncResultSuccess() {
this.mvcResult.setAsyncResult("Foo");
this.mvcResult.setAsyncDispatchLatch(new CountDownLatch(0));
this.mvcResult.getAsyncResult();
}
@Test
public void getAsyncResultFailure() {
void getAsyncResultFailure() {
assertThatIllegalStateException().isThrownBy(() ->
this.mvcResult.getAsyncResult(0));
}
@@ -442,12 +442,12 @@ public class MockMvcTesterIntegrationTests {
private final ByteArrayOutputStream capturedOut = new ByteArrayOutputStream();
@BeforeEach
public void setUp() {
void setUp() {
System.setOut(new PrintStream(capturedOut));
}
@AfterEach
public void tearDown() {
void tearDown() {
System.setOut(standardOut);
}
@@ -26,7 +26,6 @@ import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.hamcrest.MatcherAssert;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
@@ -51,13 +50,7 @@ import static org.hamcrest.Matchers.equalTo;
*/
class RestTestClientTests {
private RestTestClient client;
@BeforeEach
void setUp() {
this.client = RestTestClient.bindToController(new TestController()).build();
}
private RestTestClient client = RestTestClient.bindToController(new TestController()).build();
@Nested
@@ -65,7 +58,7 @@ class RestTestClientTests {
@ParameterizedTest
@ValueSource(strings = {"GET", "POST", "PUT", "DELETE", "PATCH", "HEAD"})
void testMethod(String method) {
void method(String method) {
RestTestClientTests.this.client.method(HttpMethod.valueOf(method)).uri("/test")
.exchange()
.expectStatus().isOk()
@@ -73,7 +66,7 @@ class RestTestClientTests {
}
@Test
void testGet() {
void get() {
RestTestClientTests.this.client.get().uri("/test")
.exchange()
.expectStatus().isOk()
@@ -81,7 +74,7 @@ class RestTestClientTests {
}
@Test
void testPost() {
void post() {
RestTestClientTests.this.client.post().uri("/test")
.exchange()
.expectStatus().isOk()
@@ -89,7 +82,7 @@ class RestTestClientTests {
}
@Test
void testPut() {
void put() {
RestTestClientTests.this.client.put().uri("/test")
.exchange()
.expectStatus().isOk()
@@ -97,7 +90,7 @@ class RestTestClientTests {
}
@Test
void testDelete() {
void delete() {
RestTestClientTests.this.client.delete().uri("/test")
.exchange()
.expectStatus().isOk()
@@ -105,7 +98,7 @@ class RestTestClientTests {
}
@Test
void testPatch() {
void patch() {
RestTestClientTests.this.client.patch().uri("/test")
.exchange()
.expectStatus().isOk()
@@ -113,7 +106,7 @@ class RestTestClientTests {
}
@Test
void testHead() {
void head() {
RestTestClientTests.this.client.head().uri("/test")
.exchange()
.expectStatus().isOk()
@@ -121,7 +114,7 @@ class RestTestClientTests {
}
@Test
void testOptions() {
void options() {
RestTestClientTests.this.client.options().uri("/test")
.exchange()
.expectStatus().isOk()
@@ -167,7 +160,7 @@ class RestTestClientTests {
}
@Test
void testWithPathVariables() {
void withPathVariables() {
RestTestClientTests.this.client.get().uri("/test/{id}", 1)
.exchange()
.expectStatus().isOk()
@@ -175,7 +168,7 @@ class RestTestClientTests {
}
@Test
void testWithParameterMap() {
void withParameterMap() {
RestTestClientTests.this.client.get().uri("/test/{id}", Map.of("id", 1))
.exchange()
.expectStatus().isOk()
@@ -183,7 +176,7 @@ class RestTestClientTests {
}
@Test
void testWithUrlBuilder() {
void withUrlBuilder() {
RestTestClientTests.this.client.get().uri(builder -> builder.path("/test/{id}").build(1))
.exchange()
.expectStatus().isOk()
@@ -191,7 +184,7 @@ class RestTestClientTests {
}
@Test
void testURI() {
void uri() {
RestTestClientTests.this.client.get().uri(URI.create("/test"))
.exchange()
.expectStatus().isOk()
@@ -202,8 +195,9 @@ class RestTestClientTests {
@Nested
class Cookies {
@Test
void testCookie() {
void cookie() {
RestTestClientTests.this.client.get().uri("/test")
.cookie("foo", "bar")
.exchange()
@@ -212,7 +206,7 @@ class RestTestClientTests {
}
@Test
void testCookies() {
void cookies() {
RestTestClientTests.this.client.get().uri("/test")
.cookies(cookies -> cookies.add("foo", "bar"))
.exchange()
@@ -224,8 +218,9 @@ class RestTestClientTests {
@Nested
class Headers {
@Test
void testHeader() {
void header() {
RestTestClientTests.this.client.get().uri("/test")
.header("foo", "bar")
.exchange()
@@ -234,7 +229,7 @@ class RestTestClientTests {
}
@Test
void testHeaders() {
void headers() {
RestTestClientTests.this.client.get().uri("/test")
.headers(headers -> headers.set("foo", "bar"))
.exchange()
@@ -243,7 +238,7 @@ class RestTestClientTests {
}
@Test
void testContentType() {
void contentType() {
RestTestClientTests.this.client.post().uri("/test")
.contentType(MediaType.APPLICATION_JSON)
.exchange()
@@ -252,7 +247,7 @@ class RestTestClientTests {
}
@Test
void testAcceptCharset() {
void acceptCharset() {
RestTestClientTests.this.client.get().uri("/test")
.acceptCharset(StandardCharsets.UTF_8)
.exchange()
@@ -261,7 +256,7 @@ class RestTestClientTests {
}
@Test
void testIfModifiedSince() {
void ifModifiedSince() {
RestTestClientTests.this.client.get().uri("/test")
.ifModifiedSince(ZonedDateTime.of(1970, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC))
.exchange()
@@ -270,7 +265,7 @@ class RestTestClientTests {
}
@Test
void testIfNoneMatch() {
void ifNoneMatch() {
RestTestClientTests.this.client.get().uri("/test")
.ifNoneMatch("foo")
.exchange()
@@ -282,8 +277,9 @@ class RestTestClientTests {
@Nested
class Expectations {
@Test
void testExpectCookie() {
void expectCookie() {
RestTestClientTests.this.client.get().uri("/test")
.exchange()
.expectCookie().value("session", v -> MatcherAssert.assertThat(v, equalTo("abc")));
@@ -293,8 +289,9 @@ class RestTestClientTests {
@Nested
class ReturnResults {
@Test
void testBodyReturnResult() {
void bodyReturnResult() {
var result = RestTestClientTests.this.client.get().uri("/test")
.exchange()
.expectStatus().isOk()
@@ -303,7 +300,7 @@ class RestTestClientTests {
}
@Test
void testReturnResultClass() {
void returnResultClass() {
var result = RestTestClientTests.this.client.get().uri("/test")
.exchange()
.expectStatus().isOk()
@@ -312,7 +309,7 @@ class RestTestClientTests {
}
@Test
void testReturnResultParameterizedTypeReference() {
void returnResultParameterizedTypeReference() {
var result = RestTestClientTests.this.client.get().uri("/test")
.exchange()
.expectStatus().isOk()
@@ -322,7 +319,7 @@ class RestTestClientTests {
}
@Test
void testResultContent() {
void resultContent() {
String body = "body-in";
EntityExchangeResult<String> result = RestTestClientTests.this.client.post().uri("/body")
.body(body)
@@ -357,4 +354,5 @@ class RestTestClientTests {
return body + "-out";
}
}
}
@@ -55,7 +55,7 @@ class RouterFunctionTests {
}
@Test
void testEntityExchangeResult() {
void entityExchangeResult() {
EntityExchangeResult<byte[]> result = this.testClient.get().uri("/test")
.exchange()
.expectStatus().isOk()
@@ -28,28 +28,28 @@ import org.junit.jupiter.api.Test;
public class HostRequestMatcherTests extends AbstractWebRequestMatcherTests {
@Test
public void localhost() throws Exception {
void localhost() throws Exception {
WebRequestMatcher matcher = new HostRequestMatcher("localhost");
assertMatches(matcher, "http://localhost/jquery-1.11.0.min.js");
assertDoesNotMatch(matcher, "http://company.example/jquery-1.11.0.min.js");
}
@Test
public void multipleHosts() throws Exception {
void multipleHosts() throws Exception {
WebRequestMatcher matcher = new HostRequestMatcher("localhost", "example.com");
assertMatches(matcher, "http://localhost/jquery-1.11.0.min.js");
assertMatches(matcher, "https://example.com/jquery-1.11.0.min.js");
}
@Test
public void specificPort() throws Exception {
void specificPort() throws Exception {
WebRequestMatcher matcher = new HostRequestMatcher("localhost:8080");
assertMatches(matcher, "http://localhost:8080/jquery-1.11.0.min.js");
assertDoesNotMatch(matcher, "http://localhost:9090/jquery-1.11.0.min.js");
}
@Test
public void defaultHttpPort() throws Exception {
void defaultHttpPort() throws Exception {
WebRequestMatcher matcher = new HostRequestMatcher("localhost:80");
assertMatches(matcher, "http://localhost:80/jquery-1.11.0.min.js");
assertMatches(matcher, "http://localhost/jquery-1.11.0.min.js");
@@ -58,7 +58,7 @@ public class HostRequestMatcherTests extends AbstractWebRequestMatcherTests {
}
@Test
public void defaultHttpsPort() throws Exception {
void defaultHttpsPort() throws Exception {
WebRequestMatcher matcher = new HostRequestMatcher("localhost:443");
assertMatches(matcher, "https://localhost:443/jquery-1.11.0.min.js");
assertMatches(matcher, "https://localhost/jquery-1.11.0.min.js");
@@ -69,19 +69,19 @@ public class MockMvcConnectionBuilderSupportTests {
@Test
public void constructorMockMvcNull() {
void constructorMockMvcNull() {
assertThatIllegalArgumentException().isThrownBy(() ->
new MockMvcWebConnectionBuilderSupport((MockMvc) null){});
}
@Test
public void constructorContextNull() {
void constructorContextNull() {
assertThatIllegalArgumentException().isThrownBy(() ->
new MockMvcWebConnectionBuilderSupport((WebApplicationContext) null){});
}
@Test
public void context() throws Exception {
void context() throws Exception {
WebConnection conn = this.builder.createConnection(this.client);
assertMockMvcUsed(conn, "http://localhost/");
@@ -89,7 +89,7 @@ public class MockMvcConnectionBuilderSupportTests {
}
@Test
public void mockMvc() throws Exception {
void mockMvc() throws Exception {
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(wac).build();
WebConnection conn = new MockMvcWebConnectionBuilderSupport(mockMvc) {}.createConnection(this.client);
@@ -98,7 +98,7 @@ public class MockMvcConnectionBuilderSupportTests {
}
@Test
public void mockMvcExampleDotCom() throws Exception {
void mockMvcExampleDotCom() throws Exception {
WebConnection conn = this.builder.useMockMvcForHosts("example.com").createConnection(this.client);
assertMockMvcUsed(conn, "http://localhost/");
@@ -107,19 +107,19 @@ public class MockMvcConnectionBuilderSupportTests {
}
@Test
public void mockMvcAlwaysUseMockMvc() throws Exception {
void mockMvcAlwaysUseMockMvc() throws Exception {
WebConnection conn = this.builder.alwaysUseMockMvc().createConnection(this.client);
assertMockMvcUsed(conn, "http://other.example/");
}
@Test
public void defaultContextPathEmpty() throws Exception {
void defaultContextPathEmpty() throws Exception {
WebConnection conn = this.builder.createConnection(this.client);
assertThat(getResponse(conn, "http://localhost/abc").getContentAsString()).isEmpty();
}
@Test
public void defaultContextPathCustom() throws Exception {
void defaultContextPathCustom() throws Exception {
WebConnection conn = this.builder.contextPath("/abc").createConnection(this.client);
assertThat(getResponse(conn, "http://localhost/abc/def").getContentAsString()).isEqualTo("/abc");
}
@@ -46,21 +46,21 @@ public class MockMvcWebConnectionTests {
@Test
public void contextPathNull() throws IOException {
void contextPathNull() throws IOException {
this.webClient.setWebConnection(new MockMvcWebConnection(this.mockMvc, this.webClient, null));
Page page = this.webClient.getPage("http://localhost/context/a");
assertThat(page.getWebResponse().getStatusCode()).isEqualTo(200);
}
@Test
public void contextPathExplicit() throws IOException {
void contextPathExplicit() throws IOException {
this.webClient.setWebConnection(new MockMvcWebConnection(this.mockMvc, this.webClient, "/context"));
Page page = this.webClient.getPage("http://localhost/context/a");
assertThat(page.getWebResponse().getStatusCode()).isEqualTo(200);
}
@Test
public void contextPathEmpty() {
void contextPathEmpty() {
this.webClient.setWebConnection(new MockMvcWebConnection(this.mockMvc, this.webClient, ""));
// Empty context path (root context) should not match to a URL with a context path
assertThatExceptionOfType(FailingHttpStatusCodeException.class)
@@ -75,14 +75,14 @@ public class MockMvcWebConnectionTests {
}
@Test
public void forward() throws IOException {
void forward() throws IOException {
this.webClient.setWebConnection(new MockMvcWebConnection(this.mockMvc, this.webClient, ""));
Page page = this.webClient.getPage("http://localhost/forward");
assertThat(page.getWebResponse().getContentAsString()).isEqualTo("hello");
}
@Test
public void infiniteForward() {
void infiniteForward() {
this.webClient.setWebConnection(new MockMvcWebConnection(this.mockMvc, this.webClient, ""));
assertThatIllegalStateException()
.isThrownBy(() -> this.webClient.getPage("http://localhost/infiniteForward"))
@@ -90,13 +90,13 @@ public class MockMvcWebConnectionTests {
}
@Test
public void contextPathDoesNotStartWithSlash() {
void contextPathDoesNotStartWithSlash() {
assertThatIllegalArgumentException().isThrownBy(() ->
new MockMvcWebConnection(this.mockMvc, this.webClient, "context"));
}
@Test
public void contextPathEndsWithSlash() {
void contextPathEndsWithSlash() {
assertThatIllegalArgumentException().isThrownBy(() ->
new MockMvcWebConnection(this.mockMvc, this.webClient, "/context/"));
}
@@ -55,20 +55,20 @@ public class MockWebResponseBuilderTests {
@Test
public void constructorWithNullWebRequest() {
void constructorWithNullWebRequest() {
assertThatIllegalArgumentException().isThrownBy(() ->
new MockWebResponseBuilder(0L, null, this.response));
}
@Test
public void constructorWithNullResponse() {
void constructorWithNullResponse() {
assertThatIllegalArgumentException().isThrownBy(() ->
new MockWebResponseBuilder(0L,
new WebRequest(new URL("http://company.example:80/test/this/here")), null));
}
@Test
public void buildContent() throws Exception {
void buildContent() throws Exception {
this.response.getWriter().write("expected content");
WebResponse webResponse = this.responseBuilder.build();
@@ -76,7 +76,7 @@ public class MockWebResponseBuilderTests {
}
@Test
public void buildContentCharset() throws Exception {
void buildContentCharset() throws Exception {
this.response.addHeader("Content-Type", "text/html; charset=UTF-8");
WebResponse webResponse = this.responseBuilder.build();
@@ -84,7 +84,7 @@ public class MockWebResponseBuilderTests {
}
@Test
public void buildContentType() throws Exception {
void buildContentType() throws Exception {
this.response.addHeader("Content-Type", "text/html; charset-UTF-8");
WebResponse webResponse = this.responseBuilder.build();
@@ -92,7 +92,7 @@ public class MockWebResponseBuilderTests {
}
@Test
public void buildResponseHeaders() throws Exception {
void buildResponseHeaders() throws Exception {
this.response.addHeader("Content-Type", "text/html");
this.response.addHeader("X-Test", "value");
Cookie cookie = new Cookie("cookieA", "valueA");
@@ -120,7 +120,7 @@ public class MockWebResponseBuilderTests {
}
@Test // SPR-14169
public void buildResponseHeadersNullDomainDefaulted() throws Exception {
void buildResponseHeadersNullDomainDefaulted() throws Exception {
Cookie cookie = new Cookie("cookieA", "valueA");
this.response.addCookie(cookie);
WebResponse webResponse = this.responseBuilder.build();
@@ -133,7 +133,7 @@ public class MockWebResponseBuilderTests {
}
@Test
public void buildStatus() throws Exception {
void buildStatus() throws Exception {
WebResponse webResponse = this.responseBuilder.build();
assertThat(webResponse.getStatusCode()).isEqualTo(200);
@@ -141,7 +141,7 @@ public class MockWebResponseBuilderTests {
}
@Test
public void buildStatusNotOk() throws Exception {
void buildStatusNotOk() throws Exception {
this.response.setStatus(401);
WebResponse webResponse = this.responseBuilder.build();
@@ -150,7 +150,7 @@ public class MockWebResponseBuilderTests {
}
@Test
public void buildStatusWithCustomMessage() throws Exception {
void buildStatusWithCustomMessage() throws Exception {
this.response.sendError(401, "Custom");
WebResponse webResponse = this.responseBuilder.build();
@@ -159,7 +159,7 @@ public class MockWebResponseBuilderTests {
}
@Test
public void buildWebRequest() throws Exception {
void buildWebRequest() throws Exception {
WebResponse webResponse = this.responseBuilder.build();
assertThat(webResponse.getWebRequest()).isEqualTo(this.webRequest);
@@ -28,7 +28,7 @@ import org.junit.jupiter.api.Test;
public class UrlRegexRequestMatcherTests extends AbstractWebRequestMatcherTests {
@Test
public void verifyExampleInClassLevelJavadoc() throws Exception {
void verifyExampleInClassLevelJavadoc() throws Exception {
WebRequestMatcher cdnMatcher = new UrlRegexRequestMatcher(".*?//code.jquery.com/.*");
assertMatches(cdnMatcher, "https://code.jquery.com/jquery-1.11.0.min.js");
assertDoesNotMatch(cdnMatcher, "http://localhost/jquery-1.11.0.min.js");
@@ -66,7 +66,7 @@ class WebConnectionHtmlUnitDriverTests {
}
@Test
public void setWebConnection() {
void setWebConnection() {
this.driver.setWebConnection(this.connection);
assertThat(this.driver.getWebConnection()).isEqualTo(this.connection);
assertThatExceptionOfType(WebDriverException.class).isThrownBy(() -> this.driver.get("https://example.com"));
@@ -29,23 +29,23 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
public class FlashAttributeResultMatchersTests {
@Test
public void attributeExists() throws Exception {
void attributeExists() throws Exception {
new FlashAttributeResultMatchers().attributeExists("good").match(getStubMvcResult());
}
@Test
public void attributeExists_DoesNotExist() {
void attributeExists_DoesNotExist() {
assertThatExceptionOfType(AssertionError.class).isThrownBy(() ->
new FlashAttributeResultMatchers().attributeExists("bad").match(getStubMvcResult()));
}
@Test
public void attribute() throws Exception {
void attribute() throws Exception {
new FlashAttributeResultMatchers().attribute("good", "good").match(getStubMvcResult());
}
@Test
public void attribute_incorrectValue() {
void attribute_incorrectValue() {
assertThatExceptionOfType(AssertionError.class).isThrownBy(() ->
new FlashAttributeResultMatchers().attribute("good", "not good").match(getStubMvcResult()));
}
@@ -43,7 +43,7 @@ public class HeaderResultMatchersTests {
@Test // SPR-17330
public void matchDateFormattedWithHttpHeaders() throws Exception {
void matchDateFormattedWithHttpHeaders() throws Exception {
long epochMilli = ZonedDateTime.of(2018, 10, 5, 0, 0, 0, 0, ZoneOffset.UTC).toInstant().toEpochMilli();
HttpHeaders headers = new HttpHeaders();
@@ -39,98 +39,98 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
public class MockMvcResultMatchersTests {
@Test
public void redirect() throws Exception {
void redirect() throws Exception {
assertThatCode(() -> redirectedUrl("/resource/1").match(redirectedUrlStub("/resource/1")))
.doesNotThrowAnyException();
}
@Test
public void redirectNonMatching() {
void redirectNonMatching() {
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() -> redirectedUrl("/resource/2").match(redirectedUrlStub("/resource/1")))
.withMessageEndingWith("expected:</resource/2> but was:</resource/1>");
}
@Test
public void redirectNonMatchingBecauseNotRedirect() {
void redirectNonMatchingBecauseNotRedirect() {
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() -> redirectedUrl("/resource/1").match(forwardedUrlStub("/resource/1")))
.withMessageEndingWith("expected:</resource/1> but was:<null>");
}
@Test
public void redirectWithUrlTemplate() {
void redirectWithUrlTemplate() {
assertThatCode(() -> redirectedUrlTemplate("/orders/{orderId}/items/{itemId}", 1, 2).match(redirectedUrlStub("/orders/1/items/2")))
.doesNotThrowAnyException();
}
@Test
public void redirectWithMatchingPattern() {
void redirectWithMatchingPattern() {
assertThatCode(() -> redirectedUrlPattern("/resource/*").match(redirectedUrlStub("/resource/1")))
.doesNotThrowAnyException();
}
@Test
public void redirectWithNonMatchingPattern() {
void redirectWithNonMatchingPattern() {
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() -> redirectedUrlPattern("/resource/").match(redirectedUrlStub("/resource/1")))
.withMessage("'/resource/' is not an Ant-style path pattern");
}
@Test
public void redirectWithNonMatchingPatternBecauseNotRedirect() {
void redirectWithNonMatchingPatternBecauseNotRedirect() {
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() -> redirectedUrlPattern("/resource/*").match(forwardedUrlStub("/resource/1")))
.withMessage("Redirected URL 'null' does not match the expected URL pattern '/resource/*'");
}
@Test
public void forward() throws Exception {
void forward() throws Exception {
assertThatCode(() -> forwardedUrl("/api/resource/1").match(forwardedUrlStub("/api/resource/1")))
.doesNotThrowAnyException();
}
@Test
public void forwardNonMatching() {
void forwardNonMatching() {
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() -> forwardedUrlPattern("api/resource/2").match(forwardedUrlStub("api/resource/1")))
.withMessage("'api/resource/2' is not an Ant-style path pattern");
}
@Test
public void forwardNonMatchingBecauseNotForward() {
void forwardNonMatchingBecauseNotForward() {
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() -> forwardedUrlPattern("/resource/*").match(redirectedUrlStub("/resource/1")))
.withMessage("Forwarded URL 'null' does not match the expected URL pattern '/resource/*'");
}
@Test
public void forwardWithQueryString() {
void forwardWithQueryString() {
assertThatCode(() -> forwardedUrl("/api/resource/1?arg=value").match(forwardedUrlStub("/api/resource/1?arg=value")))
.doesNotThrowAnyException();
}
@Test
public void forwardWithUrlTemplate() {
void forwardWithUrlTemplate() {
assertThatCode(() -> forwardedUrlTemplate("/orders/{orderId}/items/{itemId}", 1, 2).match(forwardedUrlStub("/orders/1/items/2")))
.doesNotThrowAnyException();
}
@Test
public void forwardWithMatchingPattern() {
void forwardWithMatchingPattern() {
assertThatCode(() -> forwardedUrlPattern("/api/**/?").match(forwardedUrlStub("/api/resource/1")))
.doesNotThrowAnyException();
}
@Test
public void forwardWithNonMatchingPattern() {
void forwardWithNonMatchingPattern() {
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() -> forwardedUrlPattern("/resource/").match(forwardedUrlStub("/resource/1")))
.withMessage("'/resource/' is not an Ant-style path pattern");
}
@Test
public void forwardWithNonMatchingPatternBecauseNotForward() {
void forwardWithNonMatchingPatternBecauseNotForward() {
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() -> forwardedUrlPattern("/resource/*").match(redirectedUrlStub("/resource/1")))
.withMessage("Forwarded URL 'null' does not match the expected URL pattern '/resource/*'");
@@ -47,7 +47,7 @@ public class StatusResultMatchersTests {
@Test
public void testHttpStatusCodeResultMatchers() throws Exception {
void httpStatusCodeResultMatchers() throws Exception {
List<AssertionError> failures = new ArrayList<>();
for (HttpStatus status : HttpStatus.values()) {
MockHttpServletResponse response = new MockHttpServletResponse();
@@ -79,7 +79,7 @@ public class StatusResultMatchersTests {
}
@Test
public void statusRanges() throws Exception {
void statusRanges() throws Exception {
for (HttpStatus status : HttpStatus.values()) {
MockHttpServletResponse response = new MockHttpServletResponse();
response.setStatus(status.value());
@@ -38,95 +38,95 @@ public class XpathResultMatchersTests {
@Test
public void node() throws Exception {
void node() throws Exception {
new XpathResultMatchers("/foo/bar", null).node(Matchers.notNullValue()).match(getStubMvcResult());
}
@Test
public void nodeNoMatch() {
void nodeNoMatch() {
assertThatExceptionOfType(AssertionError.class).isThrownBy(() ->
new XpathResultMatchers("/foo/bar", null).node(Matchers.nullValue()).match(getStubMvcResult()));
}
@Test
public void nodeList() throws Exception {
void nodeList() throws Exception {
new XpathResultMatchers("/foo/bar", null).nodeList(Matchers.notNullValue()).match(getStubMvcResult());
}
@Test
public void nodeListNoMatch() {
void nodeListNoMatch() {
assertThatExceptionOfType(AssertionError.class).isThrownBy(() ->
new XpathResultMatchers("/foo/bar", null).nodeList(Matchers.nullValue()).match(getStubMvcResult()));
}
@Test
public void exists() throws Exception {
void exists() throws Exception {
new XpathResultMatchers("/foo/bar", null).exists().match(getStubMvcResult());
}
@Test
public void existsNoMatch() {
void existsNoMatch() {
assertThatExceptionOfType(AssertionError.class).isThrownBy(() ->
new XpathResultMatchers("/foo/Bar", null).exists().match(getStubMvcResult()));
}
@Test
public void doesNotExist() throws Exception {
void doesNotExist() throws Exception {
new XpathResultMatchers("/foo/Bar", null).doesNotExist().match(getStubMvcResult());
}
@Test
public void doesNotExistNoMatch() {
void doesNotExistNoMatch() {
assertThatExceptionOfType(AssertionError.class).isThrownBy(() ->
new XpathResultMatchers("/foo/bar", null).doesNotExist().match(getStubMvcResult()));
}
@Test
public void nodeCount() throws Exception {
void nodeCount() throws Exception {
new XpathResultMatchers("/foo/bar", null).nodeCount(2).match(getStubMvcResult());
}
@Test
public void nodeCountNoMatch() {
void nodeCountNoMatch() {
assertThatExceptionOfType(AssertionError.class).isThrownBy(() ->
new XpathResultMatchers("/foo/bar", null).nodeCount(1).match(getStubMvcResult()));
}
@Test
public void string() throws Exception {
void string() throws Exception {
new XpathResultMatchers("/foo/bar[1]", null).string("111").match(getStubMvcResult());
}
@Test
public void stringNoMatch() {
void stringNoMatch() {
assertThatExceptionOfType(AssertionError.class).isThrownBy(() ->
new XpathResultMatchers("/foo/bar[1]", null).string("112").match(getStubMvcResult()));
}
@Test
public void number() throws Exception {
void number() throws Exception {
new XpathResultMatchers("/foo/bar[1]", null).number(111.0).match(getStubMvcResult());
}
@Test
public void numberNoMatch() {
void numberNoMatch() {
assertThatExceptionOfType(AssertionError.class).isThrownBy(() ->
new XpathResultMatchers("/foo/bar[1]", null).number(111.1).match(getStubMvcResult()));
}
@Test
public void booleanValue() throws Exception {
void booleanValue() throws Exception {
new XpathResultMatchers("/foo/bar[2]", null).booleanValue(true).match(getStubMvcResult());
}
@Test
public void booleanValueNoMatch() {
void booleanValueNoMatch() {
assertThatExceptionOfType(AssertionError.class).isThrownBy(() ->
new XpathResultMatchers("/foo/bar[2]", null).booleanValue(false).match(getStubMvcResult()));
}
@Test
public void stringEncodingDetection() throws Exception {
void stringEncodingDetection() throws Exception {
String content = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" +
"<person><name>Jürgen</name></person>";
byte[] bytes = content.getBytes(StandardCharsets.UTF_8);
@@ -74,7 +74,7 @@ public class AsyncControllerJavaConfigTests {
}
@Test
public void callableInterceptor() throws Exception {
void callableInterceptor() throws Exception {
testClient.get().uri("/callable")
.accept(MediaType.APPLICATION_JSON)
.exchange()
@@ -66,7 +66,7 @@ public class WebAppResourceTests {
// Resources served via <mvc:resources/>
@Test
public void resourceRequest() {
void resourceRequest() {
testClient.get().uri("/resources/Spring.js")
.exchange()
.expectStatus().isOk()
@@ -77,7 +77,7 @@ public class WebAppResourceTests {
// Forwarded to the "default" servlet via <mvc:default-servlet-handler/>
@Test
public void resourcesViaDefaultServlet() throws Exception {
void resourcesViaDefaultServlet() throws Exception {
EntityExchangeResult<Void> result = testClient.get().uri("/unknown/resource")
.exchange()
.expectStatus().isOk()
@@ -67,7 +67,7 @@ public class XmlConfigTests {
@Test
public void person() {
void person() {
testClient.get().uri("/person/5")
.accept(MediaType.APPLICATION_JSON)
.exchange()
@@ -61,7 +61,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
public class FilterTests {
@Test
public void whenFiltersCompleteMvcProcessesRequest() throws Exception {
void whenFiltersCompleteMvcProcessesRequest() throws Exception {
WebTestClient client = MockMvcWebTestClient.bindToController(new PersonController())
.filters(new ContinueFilter())
.build();
@@ -81,7 +81,7 @@ public class FilterTests {
}
@Test
public void filtersProcessRequest() {
void filtersProcessRequest() {
WebTestClient client = MockMvcWebTestClient.bindToController(new PersonController())
.filters(new ContinueFilter(), new RedirectFilter())
.build();
@@ -93,7 +93,7 @@ public class FilterTests {
}
@Test
public void filterMappedBySuffix() {
void filterMappedBySuffix() {
WebTestClient client = MockMvcWebTestClient.bindToController(new PersonController())
.filter(new RedirectFilter(), "*.html")
.build();
@@ -105,7 +105,7 @@ public class FilterTests {
}
@Test
public void filterWithExactMapping() {
void filterWithExactMapping() {
WebTestClient client = MockMvcWebTestClient.bindToController(new PersonController())
.filter(new RedirectFilter(), "/p", "/persons")
.build();
@@ -117,7 +117,7 @@ public class FilterTests {
}
@Test
public void filterSkipped() throws Exception {
void filterSkipped() throws Exception {
WebTestClient client = MockMvcWebTestClient.bindToController(new PersonController())
.filter(new RedirectFilter(), "/p", "/person")
.build();
@@ -138,7 +138,7 @@ public class FilterTests {
}
@Test
public void filterWrapsRequestResponse() throws Exception {
void filterWrapsRequestResponse() throws Exception {
WebTestClient client = MockMvcWebTestClient.bindToController(new PersonController())
.filter(new WrappingRequestResponseFilter())
.build();
@@ -152,7 +152,7 @@ public class FilterTests {
}
@Test
public void filterWrapsRequestResponseAndPerformsAsyncDispatch() {
void filterWrapsRequestResponseAndPerformsAsyncDispatch() {
WebTestClient client = MockMvcWebTestClient.bindToController(new PersonController())
.filters(new WrappingRequestResponseFilter(), new ShallowEtagHeaderFilter())
.build();
@@ -56,7 +56,7 @@ public class FrameworkExtensionTests {
@Test
public void fooHeader() {
void fooHeader() {
this.client.mutateWith(headers().foo("a=b"))
.get().uri("/")
.exchange()
@@ -64,7 +64,7 @@ public class FrameworkExtensionTests {
}
@Test
public void barHeader() {
void barHeader() {
this.client.mutateWith(headers().bar("a=b"))
.get().uri("/")
.exchange()
@@ -58,7 +58,7 @@ public class MultipartControllerTests {
@Test
public void multipartRequestWithSingleFile() {
void multipartRequestWithSingleFile() {
byte[] fileContent = "bar".getBytes(StandardCharsets.UTF_8);
Map<String, String> json = Collections.singletonMap("name", "yeeeah");
@@ -82,14 +82,14 @@ public class MultipartControllerTests {
}
@Test
public void multipartRequestWithSingleFileNotPresent() {
void multipartRequestWithSingleFileNotPresent() {
testClient.post().uri("/multipartfile")
.exchange()
.expectStatus().isFound();
}
@Test
public void multipartRequestWithFileArray() {
void multipartRequestWithFileArray() {
byte[] fileContent = "bar".getBytes(StandardCharsets.UTF_8);
Map<String, String> json = Collections.singletonMap("name", "yeeeah");
@@ -106,14 +106,14 @@ public class MultipartControllerTests {
}
@Test
public void multipartRequestWithFileArrayNoMultipart() {
void multipartRequestWithFileArrayNoMultipart() {
testClient.post().uri("/multipartfilearray")
.exchange()
.expectStatus().isFound();
}
@Test
public void multipartRequestWithOptionalFile() {
void multipartRequestWithOptionalFile() {
byte[] fileContent = "bar".getBytes(StandardCharsets.UTF_8);
Map<String, String> json = Collections.singletonMap("name", "yeeeah");
@@ -129,7 +129,7 @@ public class MultipartControllerTests {
}
@Test
public void multipartRequestWithOptionalFileNotPresent() {
void multipartRequestWithOptionalFileNotPresent() {
Map<String, String> json = Collections.singletonMap("name", "yeeeah");
MultipartBodyBuilder bodyBuilder = new MultipartBodyBuilder();
@@ -143,7 +143,7 @@ public class MultipartControllerTests {
}
@Test
public void multipartRequestWithOptionalFileArray() {
void multipartRequestWithOptionalFileArray() {
byte[] fileContent = "bar".getBytes(StandardCharsets.UTF_8);
Map<String, String> json = Collections.singletonMap("name", "yeeeah");
@@ -160,7 +160,7 @@ public class MultipartControllerTests {
}
@Test
public void multipartRequestWithOptionalFileArrayNotPresent() {
void multipartRequestWithOptionalFileArrayNotPresent() {
Map<String, String> json = Collections.singletonMap("name", "yeeeah");
MultipartBodyBuilder bodyBuilder = new MultipartBodyBuilder();
@@ -174,7 +174,7 @@ public class MultipartControllerTests {
}
@Test
public void multipartRequestWithOptionalFileList() {
void multipartRequestWithOptionalFileList() {
byte[] fileContent = "bar".getBytes(StandardCharsets.UTF_8);
Map<String, String> json = Collections.singletonMap("name", "yeeeah");
@@ -191,7 +191,7 @@ public class MultipartControllerTests {
}
@Test
public void multipartRequestWithOptionalFileListNotPresent() {
void multipartRequestWithOptionalFileListNotPresent() {
Map<String, String> json = Collections.singletonMap("name", "yeeeah");
MultipartBodyBuilder bodyBuilder = new MultipartBodyBuilder();
@@ -205,7 +205,7 @@ public class MultipartControllerTests {
}
@Test
public void multipartRequestWithServletParts() {
void multipartRequestWithServletParts() {
byte[] fileContent = "bar".getBytes(StandardCharsets.UTF_8);
Map<String, String> json = Collections.singletonMap("name", "yeeeah");
@@ -221,7 +221,7 @@ public class MultipartControllerTests {
}
@Test
public void multipartRequestWrapped() {
void multipartRequestWrapped() {
Map<String, String> json = Collections.singletonMap("name", "yeeeah");
MultipartBodyBuilder bodyBuilder = new MultipartBodyBuilder();
@@ -39,7 +39,7 @@ import static org.springframework.http.MediaType.TEXT_EVENT_STREAM;
public class ReactiveReturnTypeTests {
@Test
public void sseWithFlux() {
void sseWithFlux() {
WebTestClient testClient =
MockMvcWebTestClient.bindToController(new ReactiveController()).build();
@@ -50,7 +50,7 @@ public class RedirectTests {
@Test
public void save() throws Exception {
void save() throws Exception {
EntityExchangeResult<Void> exchangeResult =
testClient.post().uri("/persons?name=Andy")
.exchange()
@@ -67,7 +67,7 @@ public class RedirectTests {
}
@Test
public void saveSpecial() throws Exception {
void saveSpecial() throws Exception {
EntityExchangeResult<Void> result =
testClient.post().uri("/people?name=Andy")
.exchange()
@@ -84,7 +84,7 @@ public class RedirectTests {
}
@Test
public void saveWithErrors() throws Exception {
void saveWithErrors() throws Exception {
EntityExchangeResult<Void> result =
testClient.post().uri("/persons").exchange().expectStatus().isOk().expectBody().isEmpty();
@@ -96,7 +96,7 @@ public class RedirectTests {
}
@Test
public void saveSpecialWithErrors() throws Exception {
void saveSpecialWithErrors() throws Exception {
EntityExchangeResult<Void> result =
testClient.post().uri("/people").exchange().expectStatus().isOk().expectBody().isEmpty();
@@ -108,7 +108,7 @@ public class RedirectTests {
}
@Test
public void getPerson() throws Exception {
void getPerson() throws Exception {
EntityExchangeResult<Void> result =
MockMvcWebTestClient.bindToController(new PersonController())
.defaultRequest(get("/").flashAttr("message", "success!"))
@@ -36,7 +36,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
public class RequestParameterTests {
@Test
public void queryParameter() {
void queryParameter() {
WebTestClient client = MockMvcWebTestClient.bindToController(new PersonController()).build();
@@ -41,7 +41,7 @@ import static org.springframework.web.servlet.function.ServerResponse.ok;
*
* @author Arjen Poutsma
*/
public class RouterFunctionTests {
class RouterFunctionTests {
@Test
void json() {
@@ -52,7 +52,7 @@ public class RouterFunctionTests {
}
@Test
public void queryParameter() {
void queryParameter() {
execute("/search?name=George", body -> body.jsonPath("$.name").isEqualTo("George"));
}
@@ -135,4 +135,5 @@ public class RouterFunctionTests {
this.age = age;
}
}
}
@@ -42,7 +42,7 @@ public class SseTests {
@Test
public void sse() {
void sse() {
FluxExchangeResult<Person> exchangeResult = this.testClient.get()
.uri("/persons")
.exchange()
@@ -47,7 +47,7 @@ public class PrintingResultHandlerSmokeTests {
// Comment out class-level @Disabled to see the output.
@Test
public void printViaConsumer() {
void printViaConsumer() {
testClient.post().uri("/")
.contentType(MediaType.TEXT_PLAIN)
.bodyValue("Hello Request".getBytes(StandardCharsets.UTF_8))
@@ -58,7 +58,7 @@ public class PrintingResultHandlerSmokeTests {
}
@Test
public void returnResultAndPrint() {
void returnResultAndPrint() {
EntityExchangeResult<String> result = testClient.post().uri("/")
.contentType(MediaType.TEXT_PLAIN)
.bodyValue("Hello Request".getBytes(StandardCharsets.UTF_8))
@@ -80,4 +80,5 @@ public class PrintingResultHandlerSmokeTests {
return "Hello Response";
}
}
}
@@ -64,55 +64,55 @@ public class CookieAssertionTests {
@Test
public void testExists() {
void exists() {
client.get().uri("/").exchange().expectCookie().exists(COOKIE_NAME);
}
@Test
public void testNotExists() {
void notExists() {
client.get().uri("/").exchange().expectCookie().doesNotExist("unknownCookie");
}
@Test
public void testEqualTo() {
void hamcrestEqualTo() {
client.get().uri("/").exchange().expectCookie().valueEquals(COOKIE_NAME, "en-US");
client.get().uri("/").exchange().expectCookie()
.value(COOKIE_NAME, v -> MatcherAssert.assertThat(v, equalTo("en-US")));
}
@Test
public void testMatcher() {
void matcher() {
client.get().uri("/").exchange().expectCookie()
.value(COOKIE_NAME, v -> MatcherAssert.assertThat(v, startsWith("en-US")));
}
@Test
public void testMaxAge() {
void maxAge() {
client.get().uri("/").exchange().expectCookie().maxAge(COOKIE_NAME, Duration.ofSeconds(-1));
}
@Test
public void testDomain() {
void domain() {
client.get().uri("/").exchange().expectCookie().domain(COOKIE_NAME, "domain");
}
@Test
public void testPath() {
void path() {
client.get().uri("/").exchange().expectCookie().path(COOKIE_NAME, "/");
}
@Test
public void testSecured() {
void secured() {
client.get().uri("/").exchange().expectCookie().secure(COOKIE_NAME, false);
}
@Test
public void testHttpOnly() {
void httpOnly() {
client.get().uri("/").exchange().expectCookie().httpOnly(COOKIE_NAME, true);
}
@Test
public void testSameSite() {
void sameSite() {
client.get().uri("/").exchange().expectCookie().sameSite(COOKIE_NAME, "Strict");
}
@@ -52,12 +52,12 @@ public class HandlerAssertionTests {
@Test
public void handlerType() throws Exception {
void handlerType() throws Exception {
performRequest().andExpect(handler().handlerType(SimpleController.class));
}
@Test
public void methodCallOnNonMock() {
void methodCallOnNonMock() {
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() -> performRequest().andExpect(handler().methodCall("bogus")))
.withMessageContaining("The supplied object [bogus] is not an instance of")
@@ -66,24 +66,24 @@ public class HandlerAssertionTests {
}
@Test
public void methodCall() throws Exception {
void methodCall() throws Exception {
performRequest().andExpect(handler().methodCall(on(SimpleController.class).handle()));
}
@Test
public void methodName() throws Exception {
void methodName() throws Exception {
performRequest().andExpect(handler().methodName("handle"));
}
@Test
public void methodNameMatchers() throws Exception {
void methodNameMatchers() throws Exception {
performRequest()
.andExpect(handler().methodName(equalTo("handle")))
.andExpect(handler().methodName(is(not("save"))));
}
@Test
public void method() throws Exception {
void method() throws Exception {
Method method = SimpleController.class.getMethod("handle");
performRequest().andExpect(handler().method(method));
}
@@ -58,7 +58,7 @@ public class JsonPathAssertionTests {
@Test
public void exists() {
void exists() {
String composerByName = "$.composers[?(@.name == '%s')]";
String performerByName = "$.performers[?(@.name == '%s')]";
@@ -78,7 +78,7 @@ public class JsonPathAssertionTests {
}
@Test
public void doesNotExist() {
void doesNotExist() {
client.get().uri("/music/people")
.exchange()
.expectBody()
@@ -88,7 +88,7 @@ public class JsonPathAssertionTests {
}
@Test
public void equality() {
void equality() {
client.get().uri("/music/people")
.exchange()
.expectBody()
@@ -106,7 +106,7 @@ public class JsonPathAssertionTests {
}
@Test
public void hamcrestMatcher() {
void hamcrestMatcher() {
client.get().uri("/music/people")
.exchange()
.expectBody()
@@ -117,7 +117,7 @@ public class JsonPathAssertionTests {
}
@Test
public void hamcrestMatcherWithParameterizedJsonPath() {
void hamcrestMatcherWithParameterizedJsonPath() {
client.get().uri("/music/people")
.exchange()
.expectBody()
@@ -40,7 +40,7 @@ public class UrlAssertionTests {
@Test
public void testRedirect() {
void redirect() {
testClient.get().uri("/persons")
.exchange()
.expectStatus().isFound()
@@ -48,7 +48,7 @@ public class UrlAssertionTests {
}
@Test
public void testRedirectPattern() throws Exception {
void redirectPattern() throws Exception {
EntityExchangeResult<Void> result =
testClient.get().uri("/persons").exchange().expectBody().isEmpty();
@@ -57,7 +57,7 @@ public class UrlAssertionTests {
}
@Test
public void testForward() {
void forward() {
testClient.get().uri("/")
.exchange()
.expectStatus().isOk()
@@ -65,7 +65,7 @@ public class UrlAssertionTests {
}
@Test
public void testForwardPattern() throws Exception {
void forwardPattern() throws Exception {
EntityExchangeResult<Void> result =
testClient.get().uri("/").exchange().expectBody().isEmpty();
@@ -44,14 +44,14 @@ public class ViewNameAssertionTests {
@Test
public void testEqualTo() throws Exception {
void hamcrestEqualTo() throws Exception {
MockMvcWebTestClient.resultActionsFor(performRequest())
.andExpect(view().name("mySpecialView"))
.andExpect(view().name(equalTo("mySpecialView")));
}
@Test
public void testHamcrestMatcher() throws Exception {
void hamcrestMatcher() throws Exception {
MockMvcWebTestClient.resultActionsFor(performRequest())
.andExpect(view().name(containsString("Special")));
}
@@ -66,14 +66,14 @@ public class XmlContentAssertionTests {
@Test
public void testXmlEqualTo() {
void xmlEqualTo() {
testClient.get().uri("/music/people")
.exchange()
.expectBody().xml(PEOPLE_XML);
}
@Test
public void testNodeHamcrestMatcher() {
void nodeHamcrestMatcher() {
testClient.get().uri("/music/people")
.exchange()
.expectBody().xpath("/people/composers/composer[1]").exists();
@@ -68,7 +68,7 @@ public class XpathAssertionTests {
@Test
public void testExists() {
void exists() {
String composer = "/ns:people/composers/composer[%s]";
String performer = "/ns:people/performers/performer[%s]";
@@ -85,7 +85,7 @@ public class XpathAssertionTests {
}
@Test
public void testDoesNotExist() {
void doesNotExist() {
String composer = "/ns:people/composers/composer[%s]";
String performer = "/ns:people/performers/performer[%s]";
@@ -99,7 +99,7 @@ public class XpathAssertionTests {
}
@Test
public void testString() {
void string() {
String composerName = "/ns:people/composers/composer[%s]/name";
String performerName = "/ns:people/performers/performer[%s]/name";
@@ -119,7 +119,7 @@ public class XpathAssertionTests {
}
@Test
public void testNumber() {
void number() {
String expression = "/ns:people/composers/composer[%s]/someDouble";
testClient.get().uri("/music/people")
@@ -134,7 +134,7 @@ public class XpathAssertionTests {
}
@Test
public void testBoolean() {
void booleanCase() {
String expression = "/ns:people/performers/performer[%s]/someBoolean";
testClient.get().uri("/music/people")
@@ -145,7 +145,7 @@ public class XpathAssertionTests {
}
@Test
public void testNodeCount() {
void nodeCount() {
testClient.get().uri("/music/people")
.exchange()
.expectBody()
@@ -156,7 +156,7 @@ public class XpathAssertionTests {
}
@Test
public void testFeedWithLinefeedChars() {
void feedWithLinefeedChars() {
MockMvcWebTestClient.bindToController(new BlogFeedController()).build()
.get().uri("/blog.atom")
.accept(MediaType.APPLICATION_ATOM_XML)
@@ -82,7 +82,7 @@ public class AsyncControllerJavaConfigTests {
// SPR-13615
@Test
public void callableInterceptor() throws Exception {
void callableInterceptor() throws Exception {
MvcResult mvcResult = this.mockMvc.perform(get("/callable").accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(request().asyncStarted())
@@ -91,7 +91,7 @@ public class JavaConfigTests {
}
@Test
public void person() throws Exception {
void person() throws Exception {
this.mockMvc.perform(get("/person/5").accept(MediaType.APPLICATION_JSON))
.andDo(print())
.andExpectAll(
@@ -103,7 +103,7 @@ public class JavaConfigTests {
}
@Test
public void andExpectAllWithOneFailure() {
void andExpectAllWithOneFailure() {
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() -> this.mockMvc.perform(get("/person/5").accept(MediaType.APPLICATION_JSON))
.andExpectAll(
@@ -115,7 +115,7 @@ public class JavaConfigTests {
}
@Test
public void andExpectAllWithMultipleFailures() {
void andExpectAllWithMultipleFailures() {
assertThatExceptionOfType(AssertionError.class).isThrownBy(() ->
this.mockMvc.perform(get("/person/5").accept(MediaType.APPLICATION_JSON))
.andExpectAll(
@@ -65,7 +65,7 @@ public class WebAppResourceTests {
// Resources served via <mvc:resources/>
@Test
public void resourceRequest() throws Exception {
void resourceRequest() throws Exception {
this.mockMvc.perform(get("/resources/Spring.js"))
.andExpect(content().contentType("text/javascript"))
.andExpect(content().string(containsString("Spring={};")));
@@ -74,7 +74,7 @@ public class WebAppResourceTests {
// Forwarded to the "default" servlet via <mvc:default-servlet-handler/>
@Test
public void resourcesViaDefaultServlet() throws Exception {
void resourcesViaDefaultServlet() throws Exception {
this.mockMvc.perform(get("/unknown/resource"))
.andExpect(handler().handlerType(DefaultServletHttpRequestHandler.class))
.andExpect(forwardedUrl("default"));
@@ -69,7 +69,7 @@ public class XmlConfigTests {
}
@Test
public void person() throws Exception {
void person() throws Exception {
this.mockMvc.perform(get("/person/5").accept(MediaType.APPLICATION_JSON))
.andDo(print())
.andExpect(status().isOk())
@@ -82,12 +82,12 @@ public class CustomRequestAttributesRequestContextHolderTests {
}
@Test
public void singletonController() throws Exception {
void singletonController() throws Exception {
this.mockMvc.perform(get("/singletonController").requestAttr(FROM_MVC_TEST_MOCK, FROM_MVC_TEST_MOCK));
}
@AfterEach
public void verifyCustomRequestAttributesAreRestored() {
void verifyCustomRequestAttributesAreRestored() {
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
assertThat(requestAttributes).isInstanceOf(ServletRequestAttributes.class);
HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest();
@@ -36,7 +36,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
public class FormContentTests {
@Test // SPR-15753
public void formContentIsNotDuplicated() throws Exception {
void formContentIsNotDuplicated() throws Exception {
MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new Spr15753Controller())
.addFilter(new FormContentFilter())
@@ -113,30 +113,30 @@ public class RequestContextHolderTests {
}
@Test
public void singletonController() throws Exception {
void singletonController() throws Exception {
this.mockMvc.perform(get("/singletonController").requestAttr(FROM_MVC_TEST_MOCK, FROM_MVC_TEST_MOCK));
}
@Test
public void requestScopedController() throws Exception {
void requestScopedController() throws Exception {
assertThat(AopUtils.isCglibProxy(this.requestScopedController)).as("request-scoped controller must be a CGLIB proxy").isTrue();
this.mockMvc.perform(get("/requestScopedController").requestAttr(FROM_MVC_TEST_MOCK, FROM_MVC_TEST_MOCK));
}
@Test
public void requestScopedService() throws Exception {
void requestScopedService() throws Exception {
assertThat(AopUtils.isCglibProxy(this.requestScopedService)).as("request-scoped service must be a CGLIB proxy").isTrue();
this.mockMvc.perform(get("/requestScopedService").requestAttr(FROM_MVC_TEST_MOCK, FROM_MVC_TEST_MOCK));
}
@Test
public void sessionScopedService() throws Exception {
void sessionScopedService() throws Exception {
assertThat(AopUtils.isCglibProxy(this.sessionScopedService)).as("session-scoped service must be a CGLIB proxy").isTrue();
this.mockMvc.perform(get("/sessionScopedService").requestAttr(FROM_MVC_TEST_MOCK, FROM_MVC_TEST_MOCK));
}
@AfterEach
public void verifyRestoredRequestAttributes() {
void verifyRestoredRequestAttributes() {
assertRequestAttributes(false);
}
@@ -44,7 +44,7 @@ import static org.springframework.test.web.servlet.setup.MockMvcBuilders.standal
public class ApiVersionTests {
@Test
public void queryParameter() throws Exception {
void queryParameter() throws Exception {
String header = "API-Version";
@@ -68,7 +68,7 @@ import static org.springframework.test.web.servlet.setup.MockMvcBuilders.standal
public class FilterTests {
@Test
public void whenFiltersCompleteMvcProcessesRequest() throws Exception {
void whenFiltersCompleteMvcProcessesRequest() throws Exception {
standaloneSetup(new PersonController())
.addFilters(new ContinueFilter()).build()
.perform(post("/persons").param("name", "Andy"))
@@ -81,7 +81,7 @@ public class FilterTests {
}
@Test
public void filtersProcessRequest() throws Exception {
void filtersProcessRequest() throws Exception {
standaloneSetup(new PersonController())
.addFilters(new ContinueFilter(), new RedirectFilter()).build()
.perform(post("/persons").param("name", "Andy"))
@@ -89,7 +89,7 @@ public class FilterTests {
}
@Test
public void filterMappedBySuffix() throws Exception {
void filterMappedBySuffix() throws Exception {
standaloneSetup(new PersonController())
.addFilter(new RedirectFilter(), "*.html").build()
.perform(post("/persons.html").param("name", "Andy"))
@@ -97,7 +97,7 @@ public class FilterTests {
}
@Test
public void filterWithExactMapping() throws Exception {
void filterWithExactMapping() throws Exception {
standaloneSetup(new PersonController())
.addFilter(new RedirectFilter(), "/p", "/persons").build()
.perform(post("/persons").param("name", "Andy"))
@@ -105,7 +105,7 @@ public class FilterTests {
}
@Test
public void filterSkipped() throws Exception {
void filterSkipped() throws Exception {
standaloneSetup(new PersonController())
.addFilter(new RedirectFilter(), "/p", "/person").build()
.perform(post("/persons").param("name", "Andy"))
@@ -118,7 +118,7 @@ public class FilterTests {
}
@Test
public void filterWrapsRequestResponse() throws Exception {
void filterWrapsRequestResponse() throws Exception {
standaloneSetup(new PersonController())
.addFilters(new WrappingRequestResponseFilter()).build()
.perform(post("/user"))
@@ -126,7 +126,7 @@ public class FilterTests {
}
@Test // SPR-16067, SPR-16695
public void filterWrapsRequestResponseAndPerformsAsyncDispatch() throws Exception {
void filterWrapsRequestResponseAndPerformsAsyncDispatch() throws Exception {
MockMvc mockMvc = standaloneSetup(new PersonController())
.addFilters(new WrappingRequestResponseFilter(), new ShallowEtagHeaderFilter())
.build();
@@ -56,12 +56,12 @@ public class FrameworkExtensionTests {
@Test
public void fooHeader() throws Exception {
void fooHeader() throws Exception {
this.mockMvc.perform(get("/").with(headers().foo("a=b"))).andExpect(content().string("Foo"));
}
@Test
public void barHeader() throws Exception {
void barHeader() throws Exception {
this.mockMvc.perform(get("/").with(headers().bar("a=b"))).andExpect(content().string("Bar"));
}
@@ -43,7 +43,7 @@ public class ReactiveReturnTypeTests {
@Test // SPR-16869
public void sseWithFlux() throws Exception {
void sseWithFlux() throws Exception {
MockMvc mockMvc = MockMvcBuilders.standaloneSetup(ReactiveController.class).build();
@@ -57,7 +57,7 @@ public class RedirectTests {
@Test
public void save() throws Exception {
void save() throws Exception {
this.mockMvc.perform(post("/persons").param("name", "Andy"))
.andExpect(status().isFound())
.andExpect(redirectedUrl("/persons/Joe"))
@@ -68,7 +68,7 @@ public class RedirectTests {
}
@Test
public void saveSpecial() throws Exception {
void saveSpecial() throws Exception {
this.mockMvc.perform(post("/people").param("name", "Andy"))
.andExpect(status().isFound())
.andExpect(redirectedUrl("/persons/Joe"))
@@ -79,7 +79,7 @@ public class RedirectTests {
}
@Test
public void saveWithErrors() throws Exception {
void saveWithErrors() throws Exception {
this.mockMvc.perform(post("/persons"))
.andExpect(status().isOk())
.andExpect(forwardedUrl("persons/add"))
@@ -89,7 +89,7 @@ public class RedirectTests {
}
@Test
public void saveSpecialWithErrors() throws Exception {
void saveSpecialWithErrors() throws Exception {
this.mockMvc.perform(post("/people"))
.andExpect(status().isOk())
.andExpect(forwardedUrl("persons/add"))
@@ -99,7 +99,7 @@ public class RedirectTests {
}
@Test
public void getPerson() throws Exception {
void getPerson() throws Exception {
this.mockMvc.perform(get("/persons/Joe").flashAttr("message", "success!"))
.andExpect(status().isOk())
.andExpect(forwardedUrl("persons/index"))
@@ -39,7 +39,7 @@ import static org.springframework.test.web.servlet.setup.MockMvcBuilders.standal
public class RequestParameterTests {
@Test
public void queryParameter() throws Exception {
void queryParameter() throws Exception {
standaloneSetup(new PersonController()).build()
.perform(get("/search?name=George").accept(MediaType.APPLICATION_JSON))
@@ -18,7 +18,6 @@ package org.springframework.test.web.servlet.samples.standalone;
import java.util.concurrent.CompletableFuture;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Mono;
@@ -48,13 +47,8 @@ import static org.springframework.web.servlet.function.ServerResponse.ok;
*/
public class RouterFunctionTests {
private MockMvc mockMvc;
private MockMvc mockMvc = routerFunctions(testRoute()).defaultResponseCharacterEncoding(UTF_8).build();
@BeforeEach
void setUp() {
RouterFunction<?> testRoute = testRoute();
this.mockMvc = routerFunctions(testRoute).defaultResponseCharacterEncoding(UTF_8).build();
}
@Test
void json() throws Exception {
@@ -75,7 +69,7 @@ public class RouterFunctionTests {
}
@Test
public void queryParameter() throws Exception {
void queryParameter() throws Exception {
this.mockMvc
.perform(get("/search?name=George").accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
@@ -164,4 +158,5 @@ public class RouterFunctionTests {
this.age = age;
}
}
}

Some files were not shown because too many files have changed in this diff Show More