Assert instances (vs classes) in MockMvc/WebTestClient

Issue: SPR-16520
This commit is contained in:
Rossen Stoyanchev
2018-02-21 14:01:53 -05:00
parent 3bfa56dff2
commit bb8cddda23
4 changed files with 40 additions and 8 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -44,7 +44,7 @@ import static org.junit.Assert.assertNotNull;
public class DefaultControllerSpecTests {
@Test
public void controller() throws Exception {
public void controller() {
new DefaultControllerSpec(new MyController()).build()
.get().uri("/")
.exchange()
@@ -53,7 +53,7 @@ public class DefaultControllerSpecTests {
}
@Test
public void controllerAdvice() throws Exception {
public void controllerAdvice() {
new DefaultControllerSpec(new MyController())
.controllerAdvice(new MyControllerAdvice())
.build()
@@ -63,8 +63,18 @@ public class DefaultControllerSpecTests {
.expectBody(String.class).isEqualTo("Handled exception");
}
@Test(expected = IllegalArgumentException.class)
public void controllerIsAnObjectInstance() {
new DefaultControllerSpec(MyController.class);
}
@Test(expected = IllegalArgumentException.class)
public void controllerAdviceIsAnObjectInstance() {
new DefaultControllerSpec(new MyController()).controllerAdvice(MyControllerAdvice.class);
}
@Test
public void configurerConsumers() throws Exception {
public void configurerConsumers() {
TestConsumer<ArgumentResolverConfigurer> argumentResolverConsumer = new TestConsumer<>();
TestConsumer<RequestedContentTypeResolverBuilder> contenTypeResolverConsumer = new TestConsumer<>();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -125,6 +125,17 @@ public class StandaloneMockMvcBuilderTests {
assertNotNull(serializer);
}
@Test(expected = IllegalArgumentException.class)
public void controllerIsAnObjectInstance() {
new StandaloneMockMvcBuilder(PersonController.class);
}
@Test(expected = IllegalArgumentException.class)
public void controllerAdviceIsAnObjectInstance() {
new StandaloneMockMvcBuilder(new PersonController()).setControllerAdvice(PersonController.class);
}
@Controller
private static class PlaceholderController {