Skip to content

Commit 93bb78e

Browse files
committed
Avoid private bean classes in integration tests (for CGLIB on JDK 11)
Issue: SPR-16391
1 parent b2bf5fe commit 93bb78e

File tree

6 files changed

+54
-63
lines changed

6 files changed

+54
-63
lines changed

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,13 @@ configure(allprojects) { project ->
101101
"-Xlint:-deprecation", "-Xlint:-unchecked"]
102102

103103
compileJava {
104-
sourceCompatibility = 1.8 // can be switched to 10 for testing
104+
sourceCompatibility = 1.8 // can be switched to 11 for testing
105105
targetCompatibility = 1.8
106106
options.encoding = "UTF-8"
107107
}
108108

109109
compileTestJava {
110-
sourceCompatibility = 1.8 // can be switched to 10 for testing
110+
sourceCompatibility = 1.8 // can be switched to 11 for testing
111111
targetCompatibility = 1.8
112112
options.encoding = "UTF-8"
113113
options.compilerArgs += "-parameters"

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public FooService fooService() {
157157
}
158158

159159

160-
private interface FooService {
160+
interface FooService {
161161

162162
Object getSimple(Object key);
163163

@@ -166,7 +166,7 @@ private interface FooService {
166166

167167

168168
@CacheConfig(cacheNames = "testCache")
169-
private static class FooServiceImpl implements FooService {
169+
static class FooServiceImpl implements FooService {
170170

171171
private final AtomicLong counter = new AtomicLong();
172172

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

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,11 @@
5151
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
5252
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
5353

54-
import static org.hamcrest.CoreMatchers.instanceOf;
55-
import static org.hamcrest.CoreMatchers.is;
56-
import static org.hamcrest.CoreMatchers.nullValue;
57-
import static org.junit.Assert.assertThat;
58-
import static org.junit.Assert.assertTrue;
59-
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
60-
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
61-
import static org.springframework.test.web.servlet.setup.MockMvcBuilders.webAppContextSetup;
54+
import static org.hamcrest.CoreMatchers.*;
55+
import static org.junit.Assert.*;
56+
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
57+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
58+
import static org.springframework.test.web.servlet.setup.MockMvcBuilders.*;
6259

6360
/**
6461
* Integration tests for the following use cases.
@@ -191,7 +188,7 @@ public FilterWithSessionScopedService filterWithSessionScopedService() {
191188
}
192189

193190
@RestController
194-
private static class SingletonController {
191+
static class SingletonController {
195192

196193
@RequestMapping("/singletonController")
197194
public void handle() {
@@ -200,7 +197,7 @@ public void handle() {
200197
}
201198

202199
@RestController
203-
private static class RequestScopedController {
200+
static class RequestScopedController {
204201

205202
@Autowired
206203
private ServletRequest request;
@@ -213,7 +210,7 @@ public void handle() {
213210
}
214211
}
215212

216-
private static class RequestScopedService {
213+
static class RequestScopedService {
217214

218215
@Autowired
219216
private ServletRequest request;
@@ -224,7 +221,7 @@ void process() {
224221
}
225222
}
226223

227-
private static class SessionScopedService {
224+
static class SessionScopedService {
228225

229226
@Autowired
230227
private ServletRequest request;
@@ -236,7 +233,7 @@ void process() {
236233
}
237234

238235
@RestController
239-
private static class ControllerWithRequestScopedService {
236+
static class ControllerWithRequestScopedService {
240237

241238
@Autowired
242239
private RequestScopedService service;
@@ -250,7 +247,7 @@ public void handle() {
250247
}
251248

252249
@RestController
253-
private static class ControllerWithSessionScopedService {
250+
static class ControllerWithSessionScopedService {
254251

255252
@Autowired
256253
private SessionScopedService service;
@@ -263,7 +260,7 @@ public void handle() {
263260
}
264261
}
265262

266-
private static class FilterWithSessionScopedService extends GenericFilterBean {
263+
static class FilterWithSessionScopedService extends GenericFilterBean {
267264

268265
@Autowired
269266
private SessionScopedService service;
@@ -278,7 +275,7 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha
278275
}
279276
}
280277

281-
private static class RequestFilter extends GenericFilterBean {
278+
static class RequestFilter extends GenericFilterBean {
282279

283280
@Override
284281
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
@@ -287,7 +284,7 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha
287284
}
288285
}
289286

290-
private static class RequestAttributesFilter extends GenericFilterBean {
287+
static class RequestAttributesFilter extends GenericFilterBean {
291288

292289
@Override
293290
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -40,13 +40,12 @@
4040
import org.springframework.web.server.ServerWebExchange;
4141
import org.springframework.web.server.UnsupportedMediaTypeStatusException;
4242

43-
import static org.hamcrest.Matchers.is;
43+
import static org.hamcrest.Matchers.*;
4444
import static org.junit.Assert.*;
4545
import static org.mockito.Mockito.any;
46-
import static org.mockito.Mockito.mock;
47-
import static org.mockito.Mockito.when;
48-
import static org.springframework.mock.http.server.reactive.test.MockServerHttpRequest.get;
49-
import static org.springframework.web.method.ResolvableMethod.on;
46+
import static org.mockito.Mockito.*;
47+
import static org.springframework.mock.http.server.reactive.test.MockServerHttpRequest.*;
48+
import static org.springframework.web.method.ResolvableMethod.*;
5049

5150
/**
5251
* Unit tests for {@link InvocableHandlerMethod}.
@@ -251,7 +250,7 @@ private void assertHandlerResultValue(Mono<HandlerResult> mono, String expected)
251250

252251

253252
@SuppressWarnings("unused")
254-
private static class TestController {
253+
static class TestController {
255254

256255
public String noArgs() {
257256
return "success";
@@ -271,8 +270,9 @@ public String responseStatus() {
271270
}
272271
}
273272

273+
274274
@SuppressWarnings("unused")
275-
private static class VoidController {
275+
static class VoidController {
276276

277277
@ResponseStatus(HttpStatus.BAD_REQUEST)
278278
public void responseStatus() {

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

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package org.springframework.web.reactive.result.method.annotation;
1718

1819
import java.lang.reflect.Method;
@@ -46,11 +47,11 @@
4647
import org.springframework.web.server.ResponseStatusException;
4748
import org.springframework.web.server.ServerWebExchange;
4849

49-
import static org.junit.Assert.assertEquals;
50-
import static org.junit.Assert.assertNotNull;
50+
import static org.junit.Assert.*;
5151

5252
/**
5353
* Unit tests for {@link ControllerMethodResolver}.
54+
*
5455
* @author Rossen Stoyanchev
5556
*/
5657
public class ControllerMethodResolverTests {
@@ -61,8 +62,7 @@ public class ControllerMethodResolverTests {
6162

6263

6364
@Before
64-
public void setUp() throws Exception {
65-
65+
public void setup() {
6666
ArgumentResolverConfigurer resolvers = new ArgumentResolverConfigurer();
6767
resolvers.addCustomResolver(new CustomArgumentResolver());
6868
resolvers.addCustomResolver(new CustomSyncArgumentResolver());
@@ -84,8 +84,7 @@ public void setUp() throws Exception {
8484

8585

8686
@Test
87-
public void requestMappingArgumentResolvers() throws Exception {
88-
87+
public void requestMappingArgumentResolvers() {
8988
InvocableHandlerMethod invocable = this.methodResolver.getRequestMappingMethod(this.handlerMethod);
9089
List<HandlerMethodArgumentResolver> resolvers = invocable.getResolvers();
9190

@@ -122,10 +121,8 @@ public void requestMappingArgumentResolvers() throws Exception {
122121
}
123122

124123
@Test
125-
public void modelAttributeArgumentResolvers() throws Exception {
126-
127-
List<InvocableHandlerMethod> methods =
128-
this.methodResolver.getModelAttributeMethods(this.handlerMethod);
124+
public void modelAttributeArgumentResolvers() {
125+
List<InvocableHandlerMethod> methods = this.methodResolver.getModelAttributeMethods(this.handlerMethod);
129126

130127
assertEquals("Expected one each from Controller + ControllerAdvice", 2, methods.size());
131128
InvocableHandlerMethod invocable = methods.get(0);
@@ -160,8 +157,7 @@ public void modelAttributeArgumentResolvers() throws Exception {
160157
}
161158

162159
@Test
163-
public void initBinderArgumentResolvers() throws Exception {
164-
160+
public void initBinderArgumentResolvers() {
165161
List<SyncInvocableHandlerMethod> methods =
166162
this.methodResolver.getInitBinderMethods(this.handlerMethod);
167163

@@ -191,11 +187,9 @@ public void initBinderArgumentResolvers() throws Exception {
191187
}
192188

193189
@Test
194-
public void exceptionHandlerArgumentResolvers() throws Exception {
195-
196-
InvocableHandlerMethod invocable =
197-
this.methodResolver.getExceptionHandlerMethod(
198-
new ResponseStatusException(HttpStatus.BAD_REQUEST, "reason"), this.handlerMethod);
190+
public void exceptionHandlerArgumentResolvers() {
191+
InvocableHandlerMethod invocable = this.methodResolver.getExceptionHandlerMethod(
192+
new ResponseStatusException(HttpStatus.BAD_REQUEST, "reason"), this.handlerMethod);
199193

200194
assertNotNull("No match", invocable);
201195
assertEquals(TestController.class, invocable.getBeanType());
@@ -227,11 +221,9 @@ public void exceptionHandlerArgumentResolvers() throws Exception {
227221
}
228222

229223
@Test
230-
public void exceptionHandlerFromControllerAdvice() throws Exception {
231-
232-
InvocableHandlerMethod invocable =
233-
this.methodResolver.getExceptionHandlerMethod(
234-
new IllegalStateException("reason"), this.handlerMethod);
224+
public void exceptionHandlerFromControllerAdvice() {
225+
InvocableHandlerMethod invocable = this.methodResolver.getExceptionHandlerMethod(
226+
new IllegalStateException("reason"), this.handlerMethod);
235227

236228
assertNotNull(invocable);
237229
assertEquals(TestControllerAdvice.class, invocable.getBeanType());
@@ -246,7 +238,7 @@ private static HandlerMethodArgumentResolver next(
246238

247239

248240
@Controller
249-
private static class TestController {
241+
static class TestController {
250242

251243
@InitBinder
252244
void initDataBinder() {}
@@ -262,8 +254,9 @@ void handleException(ResponseStatusException ex) {}
262254

263255
}
264256

257+
265258
@ControllerAdvice
266-
private static class TestControllerAdvice {
259+
static class TestControllerAdvice {
267260

268261
@InitBinder
269262
void initDataBinder() {}
@@ -276,7 +269,8 @@ void handleException(IllegalStateException ex) {}
276269

277270
}
278271

279-
private static class CustomArgumentResolver implements HandlerMethodArgumentResolver {
272+
273+
static class CustomArgumentResolver implements HandlerMethodArgumentResolver {
280274

281275
@Override
282276
public boolean supportsParameter(MethodParameter p) {
@@ -289,7 +283,8 @@ public Mono<Object> resolveArgument(MethodParameter p, BindingContext c, ServerW
289283
}
290284
}
291285

292-
private static class CustomSyncArgumentResolver extends CustomArgumentResolver
286+
287+
static class CustomSyncArgumentResolver extends CustomArgumentResolver
293288
implements SyncHandlerMethodArgumentResolver {
294289

295290
@Override

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,13 @@
6666
import static org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder.*;
6767

6868
/**
69-
* Unit tests for {@link org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder}.
69+
* Unit tests for {@link MvcUriComponentsBuilder}.
7070
*
7171
* @author Oliver Gierke
7272
* @author Dietrich Schulten
7373
* @author Rossen Stoyanchev
7474
* @author Sam Brannen
7575
*/
76-
@SuppressWarnings("unused")
7776
public class MvcUriComponentsBuilderTests {
7877

7978
private final MockHttpServletRequest request = new MockHttpServletRequest();
@@ -467,12 +466,12 @@ interface PersonController {
467466
}
468467

469468

470-
private class PersonControllerImpl implements PersonController {
469+
static class PersonControllerImpl implements PersonController {
471470
}
472471

473472

474473
@RequestMapping("/people/{id}/addresses")
475-
private static class PersonsAddressesController {
474+
static class PersonsAddressesController {
476475

477476
@RequestMapping("/{country}")
478477
HttpEntity<Void> getAddressesForCountry(@PathVariable String country) {
@@ -539,7 +538,7 @@ static class ExtendedController extends ControllerWithMethods {
539538

540539

541540
@RequestMapping("/user/{userId}/contacts")
542-
private static class UserContactController {
541+
static class UserContactController {
543542

544543
@RequestMapping("/create")
545544
public String showCreate(@PathVariable Integer userId) {
@@ -554,7 +553,7 @@ static abstract class AbstractCrudController<T, ID> {
554553
}
555554

556555

557-
private static class PersonCrudController extends AbstractCrudController<Person, Long> {
556+
static class PersonCrudController extends AbstractCrudController<Person, Long> {
558557

559558
@RequestMapping(path = "/{id}", method = RequestMethod.GET)
560559
public Person get(@PathVariable Long id) {
@@ -564,7 +563,7 @@ public Person get(@PathVariable Long id) {
564563

565564

566565
@Controller
567-
private static class MetaAnnotationController {
566+
static class MetaAnnotationController {
568567

569568
@RequestMapping
570569
public void handle() {

0 commit comments

Comments
 (0)