Browse Source

Avoid private bean classes in integration tests (for CGLIB on JDK 11)

Issue: SPR-16391
pull/1985/merge
Juergen Hoeller 8 years ago
parent
commit
93bb78ec23
  1. 4
      build.gradle
  2. 4
      spring-context/src/test/java/org/springframework/cache/config/EnableCachingIntegrationTests.java
  3. 31
      spring-test/src/test/java/org/springframework/test/web/servlet/samples/spr/RequestContextHolderTests.java
  4. 16
      spring-webflux/src/test/java/org/springframework/web/reactive/result/method/InvocableHandlerMethodTests.java
  5. 49
      spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ControllerMethodResolverTests.java
  6. 13
      spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/MvcUriComponentsBuilderTests.java

4
build.gradle

@ -101,13 +101,13 @@ configure(allprojects) { project ->
"-Xlint:-deprecation", "-Xlint:-unchecked"] "-Xlint:-deprecation", "-Xlint:-unchecked"]
compileJava { compileJava {
sourceCompatibility = 1.8 // can be switched to 10 for testing sourceCompatibility = 1.8 // can be switched to 11 for testing
targetCompatibility = 1.8 targetCompatibility = 1.8
options.encoding = "UTF-8" options.encoding = "UTF-8"
} }
compileTestJava { compileTestJava {
sourceCompatibility = 1.8 // can be switched to 10 for testing sourceCompatibility = 1.8 // can be switched to 11 for testing
targetCompatibility = 1.8 targetCompatibility = 1.8
options.encoding = "UTF-8" options.encoding = "UTF-8"
options.compilerArgs += "-parameters" options.compilerArgs += "-parameters"

4
spring-context/src/test/java/org/springframework/cache/config/EnableCachingIntegrationTests.java vendored

@ -157,7 +157,7 @@ public class EnableCachingIntegrationTests {
} }
private interface FooService { interface FooService {
Object getSimple(Object key); Object getSimple(Object key);
@ -166,7 +166,7 @@ public class EnableCachingIntegrationTests {
@CacheConfig(cacheNames = "testCache") @CacheConfig(cacheNames = "testCache")
private static class FooServiceImpl implements FooService { static class FooServiceImpl implements FooService {
private final AtomicLong counter = new AtomicLong(); private final AtomicLong counter = new AtomicLong();

31
spring-test/src/test/java/org/springframework/test/web/servlet/samples/spr/RequestContextHolderTests.java

@ -51,14 +51,11 @@ import org.springframework.web.filter.GenericFilterBean;
import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.nullValue; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.junit.Assert.assertThat; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
import static org.junit.Assert.assertTrue; import static org.springframework.test.web.servlet.setup.MockMvcBuilders.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static org.springframework.test.web.servlet.setup.MockMvcBuilders.webAppContextSetup;
/** /**
* Integration tests for the following use cases. * Integration tests for the following use cases.
@ -191,7 +188,7 @@ public class RequestContextHolderTests {
} }
@RestController @RestController
private static class SingletonController { static class SingletonController {
@RequestMapping("/singletonController") @RequestMapping("/singletonController")
public void handle() { public void handle() {
@ -200,7 +197,7 @@ public class RequestContextHolderTests {
} }
@RestController @RestController
private static class RequestScopedController { static class RequestScopedController {
@Autowired @Autowired
private ServletRequest request; private ServletRequest request;
@ -213,7 +210,7 @@ public class RequestContextHolderTests {
} }
} }
private static class RequestScopedService { static class RequestScopedService {
@Autowired @Autowired
private ServletRequest request; private ServletRequest request;
@ -224,7 +221,7 @@ public class RequestContextHolderTests {
} }
} }
private static class SessionScopedService { static class SessionScopedService {
@Autowired @Autowired
private ServletRequest request; private ServletRequest request;
@ -236,7 +233,7 @@ public class RequestContextHolderTests {
} }
@RestController @RestController
private static class ControllerWithRequestScopedService { static class ControllerWithRequestScopedService {
@Autowired @Autowired
private RequestScopedService service; private RequestScopedService service;
@ -250,7 +247,7 @@ public class RequestContextHolderTests {
} }
@RestController @RestController
private static class ControllerWithSessionScopedService { static class ControllerWithSessionScopedService {
@Autowired @Autowired
private SessionScopedService service; private SessionScopedService service;
@ -263,7 +260,7 @@ public class RequestContextHolderTests {
} }
} }
private static class FilterWithSessionScopedService extends GenericFilterBean { static class FilterWithSessionScopedService extends GenericFilterBean {
@Autowired @Autowired
private SessionScopedService service; private SessionScopedService service;
@ -278,7 +275,7 @@ public class RequestContextHolderTests {
} }
} }
private static class RequestFilter extends GenericFilterBean { static class RequestFilter extends GenericFilterBean {
@Override @Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
@ -287,7 +284,7 @@ public class RequestContextHolderTests {
} }
} }
private static class RequestAttributesFilter extends GenericFilterBean { static class RequestAttributesFilter extends GenericFilterBean {
@Override @Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {

16
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/InvocableHandlerMethodTests.java

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -40,13 +40,12 @@ import org.springframework.web.reactive.HandlerResult;
import org.springframework.web.server.ServerWebExchange; import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.UnsupportedMediaTypeStatusException; import org.springframework.web.server.UnsupportedMediaTypeStatusException;
import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import static org.mockito.Mockito.any; import static org.mockito.Mockito.any;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.*;
import static org.mockito.Mockito.when; import static org.springframework.mock.http.server.reactive.test.MockServerHttpRequest.*;
import static org.springframework.mock.http.server.reactive.test.MockServerHttpRequest.get; import static org.springframework.web.method.ResolvableMethod.*;
import static org.springframework.web.method.ResolvableMethod.on;
/** /**
* Unit tests for {@link InvocableHandlerMethod}. * Unit tests for {@link InvocableHandlerMethod}.
@ -251,7 +250,7 @@ public class InvocableHandlerMethodTests {
@SuppressWarnings("unused") @SuppressWarnings("unused")
private static class TestController { static class TestController {
public String noArgs() { public String noArgs() {
return "success"; return "success";
@ -271,8 +270,9 @@ public class InvocableHandlerMethodTests {
} }
} }
@SuppressWarnings("unused") @SuppressWarnings("unused")
private static class VoidController { static class VoidController {
@ResponseStatus(HttpStatus.BAD_REQUEST) @ResponseStatus(HttpStatus.BAD_REQUEST)
public void responseStatus() { public void responseStatus() {

49
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ControllerMethodResolverTests.java

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.web.reactive.result.method.annotation; package org.springframework.web.reactive.result.method.annotation;
import java.lang.reflect.Method; import java.lang.reflect.Method;
@ -46,11 +47,11 @@ import org.springframework.web.reactive.result.method.SyncInvocableHandlerMethod
import org.springframework.web.server.ResponseStatusException; import org.springframework.web.server.ResponseStatusException;
import org.springframework.web.server.ServerWebExchange; import org.springframework.web.server.ServerWebExchange;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.*;
import static org.junit.Assert.assertNotNull;
/** /**
* Unit tests for {@link ControllerMethodResolver}. * Unit tests for {@link ControllerMethodResolver}.
*
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
*/ */
public class ControllerMethodResolverTests { public class ControllerMethodResolverTests {
@ -61,8 +62,7 @@ public class ControllerMethodResolverTests {
@Before @Before
public void setUp() throws Exception { public void setup() {
ArgumentResolverConfigurer resolvers = new ArgumentResolverConfigurer(); ArgumentResolverConfigurer resolvers = new ArgumentResolverConfigurer();
resolvers.addCustomResolver(new CustomArgumentResolver()); resolvers.addCustomResolver(new CustomArgumentResolver());
resolvers.addCustomResolver(new CustomSyncArgumentResolver()); resolvers.addCustomResolver(new CustomSyncArgumentResolver());
@ -84,8 +84,7 @@ public class ControllerMethodResolverTests {
@Test @Test
public void requestMappingArgumentResolvers() throws Exception { public void requestMappingArgumentResolvers() {
InvocableHandlerMethod invocable = this.methodResolver.getRequestMappingMethod(this.handlerMethod); InvocableHandlerMethod invocable = this.methodResolver.getRequestMappingMethod(this.handlerMethod);
List<HandlerMethodArgumentResolver> resolvers = invocable.getResolvers(); List<HandlerMethodArgumentResolver> resolvers = invocable.getResolvers();
@ -122,10 +121,8 @@ public class ControllerMethodResolverTests {
} }
@Test @Test
public void modelAttributeArgumentResolvers() throws Exception { public void modelAttributeArgumentResolvers() {
List<InvocableHandlerMethod> methods = this.methodResolver.getModelAttributeMethods(this.handlerMethod);
List<InvocableHandlerMethod> methods =
this.methodResolver.getModelAttributeMethods(this.handlerMethod);
assertEquals("Expected one each from Controller + ControllerAdvice", 2, methods.size()); assertEquals("Expected one each from Controller + ControllerAdvice", 2, methods.size());
InvocableHandlerMethod invocable = methods.get(0); InvocableHandlerMethod invocable = methods.get(0);
@ -160,8 +157,7 @@ public class ControllerMethodResolverTests {
} }
@Test @Test
public void initBinderArgumentResolvers() throws Exception { public void initBinderArgumentResolvers() {
List<SyncInvocableHandlerMethod> methods = List<SyncInvocableHandlerMethod> methods =
this.methodResolver.getInitBinderMethods(this.handlerMethod); this.methodResolver.getInitBinderMethods(this.handlerMethod);
@ -191,11 +187,9 @@ public class ControllerMethodResolverTests {
} }
@Test @Test
public void exceptionHandlerArgumentResolvers() throws Exception { public void exceptionHandlerArgumentResolvers() {
InvocableHandlerMethod invocable = this.methodResolver.getExceptionHandlerMethod(
InvocableHandlerMethod invocable = new ResponseStatusException(HttpStatus.BAD_REQUEST, "reason"), this.handlerMethod);
this.methodResolver.getExceptionHandlerMethod(
new ResponseStatusException(HttpStatus.BAD_REQUEST, "reason"), this.handlerMethod);
assertNotNull("No match", invocable); assertNotNull("No match", invocable);
assertEquals(TestController.class, invocable.getBeanType()); assertEquals(TestController.class, invocable.getBeanType());
@ -227,11 +221,9 @@ public class ControllerMethodResolverTests {
} }
@Test @Test
public void exceptionHandlerFromControllerAdvice() throws Exception { public void exceptionHandlerFromControllerAdvice() {
InvocableHandlerMethod invocable = this.methodResolver.getExceptionHandlerMethod(
InvocableHandlerMethod invocable = new IllegalStateException("reason"), this.handlerMethod);
this.methodResolver.getExceptionHandlerMethod(
new IllegalStateException("reason"), this.handlerMethod);
assertNotNull(invocable); assertNotNull(invocable);
assertEquals(TestControllerAdvice.class, invocable.getBeanType()); assertEquals(TestControllerAdvice.class, invocable.getBeanType());
@ -246,7 +238,7 @@ public class ControllerMethodResolverTests {
@Controller @Controller
private static class TestController { static class TestController {
@InitBinder @InitBinder
void initDataBinder() {} void initDataBinder() {}
@ -262,8 +254,9 @@ public class ControllerMethodResolverTests {
} }
@ControllerAdvice @ControllerAdvice
private static class TestControllerAdvice { static class TestControllerAdvice {
@InitBinder @InitBinder
void initDataBinder() {} void initDataBinder() {}
@ -276,7 +269,8 @@ public class ControllerMethodResolverTests {
} }
private static class CustomArgumentResolver implements HandlerMethodArgumentResolver {
static class CustomArgumentResolver implements HandlerMethodArgumentResolver {
@Override @Override
public boolean supportsParameter(MethodParameter p) { public boolean supportsParameter(MethodParameter p) {
@ -289,7 +283,8 @@ public class ControllerMethodResolverTests {
} }
} }
private static class CustomSyncArgumentResolver extends CustomArgumentResolver
static class CustomSyncArgumentResolver extends CustomArgumentResolver
implements SyncHandlerMethodArgumentResolver { implements SyncHandlerMethodArgumentResolver {
@Override @Override

13
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/MvcUriComponentsBuilderTests.java

@ -66,14 +66,13 @@ import static org.junit.Assert.*;
import static org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder.*; import static org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder.*;
/** /**
* Unit tests for {@link org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder}. * Unit tests for {@link MvcUriComponentsBuilder}.
* *
* @author Oliver Gierke * @author Oliver Gierke
* @author Dietrich Schulten * @author Dietrich Schulten
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
* @author Sam Brannen * @author Sam Brannen
*/ */
@SuppressWarnings("unused")
public class MvcUriComponentsBuilderTests { public class MvcUriComponentsBuilderTests {
private final MockHttpServletRequest request = new MockHttpServletRequest(); private final MockHttpServletRequest request = new MockHttpServletRequest();
@ -467,12 +466,12 @@ public class MvcUriComponentsBuilderTests {
} }
private class PersonControllerImpl implements PersonController { static class PersonControllerImpl implements PersonController {
} }
@RequestMapping("/people/{id}/addresses") @RequestMapping("/people/{id}/addresses")
private static class PersonsAddressesController { static class PersonsAddressesController {
@RequestMapping("/{country}") @RequestMapping("/{country}")
HttpEntity<Void> getAddressesForCountry(@PathVariable String country) { HttpEntity<Void> getAddressesForCountry(@PathVariable String country) {
@ -539,7 +538,7 @@ public class MvcUriComponentsBuilderTests {
@RequestMapping("/user/{userId}/contacts") @RequestMapping("/user/{userId}/contacts")
private static class UserContactController { static class UserContactController {
@RequestMapping("/create") @RequestMapping("/create")
public String showCreate(@PathVariable Integer userId) { public String showCreate(@PathVariable Integer userId) {
@ -554,7 +553,7 @@ public class MvcUriComponentsBuilderTests {
} }
private static class PersonCrudController extends AbstractCrudController<Person, Long> { static class PersonCrudController extends AbstractCrudController<Person, Long> {
@RequestMapping(path = "/{id}", method = RequestMethod.GET) @RequestMapping(path = "/{id}", method = RequestMethod.GET)
public Person get(@PathVariable Long id) { public Person get(@PathVariable Long id) {
@ -564,7 +563,7 @@ public class MvcUriComponentsBuilderTests {
@Controller @Controller
private static class MetaAnnotationController { static class MetaAnnotationController {
@RequestMapping @RequestMapping
public void handle() { public void handle() {

Loading…
Cancel
Save