Skip to content

Commit 0e33537

Browse files
committed
Consistent use of DefaultParameterNameResolver in tests
1 parent 00da70e commit 0e33537

File tree

10 files changed

+45
-49
lines changed

10 files changed

+45
-49
lines changed

spring-beans/src/test/java/org/springframework/beans/factory/support/QualifierAnnotationAutowireBeanFactoryTests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2022 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.
@@ -27,7 +27,7 @@
2727
import org.springframework.beans.factory.annotation.Qualifier;
2828
import org.springframework.beans.factory.config.ConstructorArgumentValues;
2929
import org.springframework.beans.factory.config.DependencyDescriptor;
30-
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
30+
import org.springframework.core.DefaultParameterNameDiscoverer;
3131
import org.springframework.core.MethodParameter;
3232
import org.springframework.util.ClassUtils;
3333

@@ -148,7 +148,7 @@ public void testAutowireCandidateWithConstructorDescriptor() throws Exception {
148148
lbf.registerBeanDefinition(MARK, person2);
149149
MethodParameter param = new MethodParameter(QualifiedTestBean.class.getDeclaredConstructor(Person.class), 0);
150150
DependencyDescriptor qualifiedDescriptor = new DependencyDescriptor(param, false);
151-
param.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());
151+
param.initParameterNameDiscovery(new DefaultParameterNameDiscoverer());
152152
assertThat(param.getParameterName()).isEqualTo("tpb");
153153
assertThat(lbf.isAutowireCandidate(JUERGEN, null)).isTrue();
154154
assertThat(lbf.isAutowireCandidate(JUERGEN, qualifiedDescriptor)).isTrue();
@@ -174,9 +174,9 @@ public void testAutowireCandidateWithMethodDescriptor() throws Exception {
174174
new MethodParameter(QualifiedTestBean.class.getDeclaredMethod("autowireNonqualified", Person.class), 0);
175175
DependencyDescriptor qualifiedDescriptor = new DependencyDescriptor(qualifiedParam, false);
176176
DependencyDescriptor nonqualifiedDescriptor = new DependencyDescriptor(nonqualifiedParam, false);
177-
qualifiedParam.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());
177+
qualifiedParam.initParameterNameDiscovery(new DefaultParameterNameDiscoverer());
178178
assertThat(qualifiedParam.getParameterName()).isEqualTo("tpb");
179-
nonqualifiedParam.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());
179+
nonqualifiedParam.initParameterNameDiscovery(new DefaultParameterNameDiscoverer());
180180
assertThat(nonqualifiedParam.getParameterName()).isEqualTo("tpb");
181181
assertThat(lbf.isAutowireCandidate(JUERGEN, null)).isTrue();
182182
assertThat(lbf.isAutowireCandidate(JUERGEN, nonqualifiedDescriptor)).isTrue();

spring-core/src/test/java/org/springframework/core/LocalVariableTableParameterNameDiscovererTests.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2022 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.
@@ -34,7 +34,7 @@
3434
*/
3535
class LocalVariableTableParameterNameDiscovererTests {
3636

37-
private final LocalVariableTableParameterNameDiscoverer discoverer = new LocalVariableTableParameterNameDiscoverer();
37+
private final ParameterNameDiscoverer discoverer = new LocalVariableTableParameterNameDiscoverer();
3838

3939

4040
@Test
@@ -162,45 +162,45 @@ void generifiedClass() throws Exception {
162162

163163
Constructor<?> ctor = clazz.getDeclaredConstructor(Object.class);
164164
String[] names = discoverer.getParameterNames(ctor);
165-
assertThat(names.length).isEqualTo(1);
165+
assertThat(names).hasSize(1);
166166
assertThat(names[0]).isEqualTo("key");
167167

168168
ctor = clazz.getDeclaredConstructor(Object.class, Object.class);
169169
names = discoverer.getParameterNames(ctor);
170-
assertThat(names.length).isEqualTo(2);
170+
assertThat(names).hasSize(2);
171171
assertThat(names[0]).isEqualTo("key");
172172
assertThat(names[1]).isEqualTo("value");
173173

174174
Method m = clazz.getMethod("generifiedStaticMethod", Object.class);
175175
names = discoverer.getParameterNames(m);
176-
assertThat(names.length).isEqualTo(1);
176+
assertThat(names).hasSize(1);
177177
assertThat(names[0]).isEqualTo("param");
178178

179179
m = clazz.getMethod("generifiedMethod", Object.class, long.class, Object.class, Object.class);
180180
names = discoverer.getParameterNames(m);
181-
assertThat(names.length).isEqualTo(4);
181+
assertThat(names).hasSize(4);
182182
assertThat(names[0]).isEqualTo("param");
183183
assertThat(names[1]).isEqualTo("x");
184184
assertThat(names[2]).isEqualTo("key");
185185
assertThat(names[3]).isEqualTo("value");
186186

187187
m = clazz.getMethod("voidStaticMethod", Object.class, long.class, int.class);
188188
names = discoverer.getParameterNames(m);
189-
assertThat(names.length).isEqualTo(3);
189+
assertThat(names).hasSize(3);
190190
assertThat(names[0]).isEqualTo("obj");
191191
assertThat(names[1]).isEqualTo("x");
192192
assertThat(names[2]).isEqualTo("i");
193193

194194
m = clazz.getMethod("nonVoidStaticMethod", Object.class, long.class, int.class);
195195
names = discoverer.getParameterNames(m);
196-
assertThat(names.length).isEqualTo(3);
196+
assertThat(names).hasSize(3);
197197
assertThat(names[0]).isEqualTo("obj");
198198
assertThat(names[1]).isEqualTo("x");
199199
assertThat(names[2]).isEqualTo("i");
200200

201201
m = clazz.getMethod("getDate");
202202
names = discoverer.getParameterNames(m);
203-
assertThat(names.length).isEqualTo(0);
203+
assertThat(names).isEmpty();
204204
}
205205

206206
@Disabled("Ignored because Ubuntu packages OpenJDK with debug symbols enabled. See SPR-8078.")

spring-core/src/test/java/org/springframework/core/SpringCoreBlockHoundIntegrationTests.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2022 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.
@@ -22,7 +22,6 @@
2222

2323
import org.junit.jupiter.api.BeforeAll;
2424
import org.junit.jupiter.api.Test;
25-
import org.junit.jupiter.api.condition.DisabledForJreRange;
2625
import reactor.blockhound.BlockHound;
2726
import reactor.core.scheduler.ReactorBlockHoundIntegration;
2827
import reactor.core.scheduler.Schedulers;
@@ -32,22 +31,19 @@
3231

3332
import static org.assertj.core.api.Assertions.assertThat;
3433
import static org.assertj.core.api.Assertions.assertThatThrownBy;
35-
import static org.junit.jupiter.api.condition.JRE.JAVA_14;
3634

3735
/**
3836
* Tests to verify the spring-core BlockHound integration rules.
3937
*
4038
* @author Rossen Stoyanchev
4139
* @since 5.2.4
4240
*/
43-
@DisabledForJreRange(min = JAVA_14)
4441
public class SpringCoreBlockHoundIntegrationTests {
4542

46-
4743
@BeforeAll
48-
static void setUp() {
44+
static void setup() {
4945
BlockHound.builder()
50-
.with(new ReactorBlockHoundIntegration()) // Reactor non-blocking thread predicate
46+
.with(new ReactorBlockHoundIntegration()) // Reactor non-blocking thread predicate
5147
.with(new ReactiveAdapterRegistry.SpringCoreBlockHoundIntegration())
5248
.install();
5349
}

spring-messaging/src/test/java/org/springframework/messaging/handler/annotation/support/PayloadMethodArgumentResolverTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2022 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.
@@ -26,7 +26,7 @@
2626
import org.junit.jupiter.api.BeforeEach;
2727
import org.junit.jupiter.api.Test;
2828

29-
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
29+
import org.springframework.core.DefaultParameterNameDiscoverer;
3030
import org.springframework.core.MethodParameter;
3131
import org.springframework.core.annotation.SynthesizingMethodParameter;
3232
import org.springframework.messaging.Message;
@@ -81,7 +81,7 @@ public void setup() throws Exception {
8181
this.paramAnnotatedRequired = new SynthesizingMethodParameter(payloadMethod, 2);
8282
this.paramWithSpelExpression = new SynthesizingMethodParameter(payloadMethod, 3);
8383
this.paramValidated = new SynthesizingMethodParameter(payloadMethod, 4);
84-
this.paramValidated.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());
84+
this.paramValidated.initParameterNameDiscovery(new DefaultParameterNameDiscoverer());
8585
this.paramValidatedNotAnnotated = new SynthesizingMethodParameter(payloadMethod, 5);
8686
this.paramNotAnnotated = new SynthesizingMethodParameter(payloadMethod, 6);
8787
}

spring-messaging/src/test/java/org/springframework/messaging/handler/invocation/ResolvableMethod.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2022 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.
@@ -39,7 +39,7 @@
3939
import org.springframework.cglib.proxy.Enhancer;
4040
import org.springframework.cglib.proxy.Factory;
4141
import org.springframework.cglib.proxy.MethodProxy;
42-
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
42+
import org.springframework.core.DefaultParameterNameDiscoverer;
4343
import org.springframework.core.MethodIntrospector;
4444
import org.springframework.core.MethodParameter;
4545
import org.springframework.core.ParameterNameDiscoverer;
@@ -131,7 +131,7 @@ public class ResolvableMethod {
131131

132132
private static final SpringObjenesis objenesis = new SpringObjenesis();
133133

134-
private static final ParameterNameDiscoverer nameDiscoverer = new LocalVariableTableParameterNameDiscoverer();
134+
private static final ParameterNameDiscoverer nameDiscoverer = new DefaultParameterNameDiscoverer();
135135

136136
// Matches ValueConstants.DEFAULT_NONE (spring-web and spring-messaging)
137137
private static final String DEFAULT_VALUE_NONE = "\n\t\t\n\t\t\n\uE000\uE001\uE002\n\t\t\t\t\n";

spring-web/src/test/java/org/springframework/web/method/annotation/InitBinderDataBinderFactoryTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
import org.junit.jupiter.api.Test;
2323

24-
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
24+
import org.springframework.core.DefaultParameterNameDiscoverer;
2525
import org.springframework.core.convert.ConversionService;
2626
import org.springframework.format.support.DefaultFormattingConversionService;
2727
import org.springframework.web.bind.WebDataBinder;
@@ -128,7 +128,7 @@ private WebDataBinderFactory createFactory(String methodName, Class<?>... parame
128128
InvocableHandlerMethod handlerMethod = new InvocableHandlerMethod(handler, method);
129129
handlerMethod.setHandlerMethodArgumentResolvers(this.argumentResolvers);
130130
handlerMethod.setDataBinderFactory(new DefaultDataBinderFactory(null));
131-
handlerMethod.setParameterNameDiscoverer(new LocalVariableTableParameterNameDiscoverer());
131+
handlerMethod.setParameterNameDiscoverer(new DefaultParameterNameDiscoverer());
132132

133133
return new InitBinderDataBinderFactory(
134134
Collections.singletonList(handlerMethod), this.bindingInitializer);

spring-web/src/test/java/org/springframework/web/method/annotation/ModelFactoryTests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2022 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.
@@ -22,7 +22,7 @@
2222
import org.junit.jupiter.api.BeforeEach;
2323
import org.junit.jupiter.api.Test;
2424

25-
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
25+
import org.springframework.core.DefaultParameterNameDiscoverer;
2626
import org.springframework.ui.Model;
2727
import org.springframework.ui.ModelMap;
2828
import org.springframework.validation.BindingResult;
@@ -177,7 +177,7 @@ public void updateModelBindingResult() throws Exception {
177177
assertThat(container.getModel().get(commandName)).isEqualTo(command);
178178
String bindingResultKey = BindingResult.MODEL_KEY_PREFIX + commandName;
179179
assertThat(container.getModel().get(bindingResultKey)).isSameAs(dataBinder.getBindingResult());
180-
assertThat(container.getModel().size()).isEqualTo(2);
180+
assertThat(container.getModel()).hasSize(2);
181181
}
182182

183183
@Test
@@ -240,7 +240,7 @@ public void updateModelWhenRedirecting() throws Exception {
240240
modelFactory.updateModel(this.webRequest, container);
241241

242242
assertThat(container.getModel().get(queryParamName)).isEqualTo(queryParam);
243-
assertThat(container.getModel().size()).isEqualTo(1);
243+
assertThat(container.getModel()).hasSize(1);
244244
assertThat(this.attributeStore.retrieveAttribute(this.webRequest, attributeName)).isEqualTo(attribute);
245245
}
246246

@@ -252,7 +252,7 @@ private ModelFactory createModelFactory(String methodName, Class<?>... parameter
252252
InvocableHandlerMethod modelMethod = createHandlerMethod(methodName, parameterTypes);
253253
modelMethod.setHandlerMethodArgumentResolvers(resolvers);
254254
modelMethod.setDataBinderFactory(null);
255-
modelMethod.setParameterNameDiscoverer(new LocalVariableTableParameterNameDiscoverer());
255+
modelMethod.setParameterNameDiscoverer(new DefaultParameterNameDiscoverer());
256256

257257
return new ModelFactory(Collections.singletonList(modelMethod), null, this.attributeHandler);
258258
}

spring-web/src/testFixtures/java/org/springframework/web/testfixture/method/ResolvableMethod.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2022 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.
@@ -39,7 +39,7 @@
3939
import org.springframework.cglib.proxy.Enhancer;
4040
import org.springframework.cglib.proxy.Factory;
4141
import org.springframework.cglib.proxy.MethodProxy;
42-
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
42+
import org.springframework.core.DefaultParameterNameDiscoverer;
4343
import org.springframework.core.MethodIntrospector;
4444
import org.springframework.core.MethodParameter;
4545
import org.springframework.core.ParameterNameDiscoverer;
@@ -130,7 +130,7 @@ public class ResolvableMethod {
130130

131131
private static final SpringObjenesis objenesis = new SpringObjenesis();
132132

133-
private static final ParameterNameDiscoverer nameDiscoverer = new LocalVariableTableParameterNameDiscoverer();
133+
private static final ParameterNameDiscoverer nameDiscoverer = new DefaultParameterNameDiscoverer();
134134

135135
// Matches ValueConstants.DEFAULT_NONE (spring-web and spring-messaging)
136136
private static final String DEFAULT_VALUE_NONE = "\n\t\t\n\t\t\n\uE000\uE001\uE002\n\t\t\t\t\n";

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
import org.junit.jupiter.api.Test;
2525

26-
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
26+
import org.springframework.core.DefaultParameterNameDiscoverer;
2727
import org.springframework.core.ReactiveAdapterRegistry;
2828
import org.springframework.core.convert.ConversionService;
2929
import org.springframework.format.support.DefaultFormattingConversionService;
@@ -131,7 +131,7 @@ private BindingContext createBindingContext(String methodName, Class<?>... param
131131

132132
SyncInvocableHandlerMethod handlerMethod = new SyncInvocableHandlerMethod(handler, method);
133133
handlerMethod.setArgumentResolvers(new ArrayList<>(this.argumentResolvers));
134-
handlerMethod.setParameterNameDiscoverer(new LocalVariableTableParameterNameDiscoverer());
134+
handlerMethod.setParameterNameDiscoverer(new DefaultParameterNameDiscoverer());
135135

136136
return new InitBinderBindingContext(this.bindingInitializer, Collections.singletonList(handlerMethod));
137137
}

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
import org.junit.jupiter.api.BeforeEach;
3434
import org.junit.jupiter.api.Test;
3535

36-
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
36+
import org.springframework.core.DefaultParameterNameDiscoverer;
3737
import org.springframework.core.MethodParameter;
3838
import org.springframework.core.annotation.SynthesizingMethodParameter;
3939
import org.springframework.http.HttpInputMessage;
@@ -138,28 +138,28 @@ public InputStream getInputStream() throws IOException {
138138

139139
Method method = ReflectionUtils.findMethod(getClass(), "handle", (Class<?>[]) null);
140140
paramRequestPart = new SynthesizingMethodParameter(method, 0);
141-
paramRequestPart.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());
141+
paramRequestPart.initParameterNameDiscovery(new DefaultParameterNameDiscoverer());
142142
paramNamedRequestPart = new SynthesizingMethodParameter(method, 1);
143143
paramValidRequestPart = new SynthesizingMethodParameter(method, 2);
144144
paramMultipartFile = new SynthesizingMethodParameter(method, 3);
145145
paramMultipartFileList = new SynthesizingMethodParameter(method, 4);
146146
paramMultipartFileArray = new SynthesizingMethodParameter(method, 5);
147147
paramInt = new SynthesizingMethodParameter(method, 6);
148148
paramMultipartFileNotAnnot = new SynthesizingMethodParameter(method, 7);
149-
paramMultipartFileNotAnnot.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());
149+
paramMultipartFileNotAnnot.initParameterNameDiscovery(new DefaultParameterNameDiscoverer());
150150
paramPart = new SynthesizingMethodParameter(method, 8);
151-
paramPart.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());
151+
paramPart.initParameterNameDiscovery(new DefaultParameterNameDiscoverer());
152152
paramPartList = new SynthesizingMethodParameter(method, 9);
153153
paramPartArray = new SynthesizingMethodParameter(method, 10);
154154
paramRequestParamAnnot = new SynthesizingMethodParameter(method, 11);
155155
optionalMultipartFile = new SynthesizingMethodParameter(method, 12);
156-
optionalMultipartFile.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());
156+
optionalMultipartFile.initParameterNameDiscovery(new DefaultParameterNameDiscoverer());
157157
optionalMultipartFileList = new SynthesizingMethodParameter(method, 13);
158-
optionalMultipartFileList.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());
158+
optionalMultipartFileList.initParameterNameDiscovery(new DefaultParameterNameDiscoverer());
159159
optionalPart = new SynthesizingMethodParameter(method, 14);
160-
optionalPart.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());
160+
optionalPart.initParameterNameDiscovery(new DefaultParameterNameDiscoverer());
161161
optionalPartList = new SynthesizingMethodParameter(method, 15);
162-
optionalPartList.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());
162+
optionalPartList.initParameterNameDiscovery(new DefaultParameterNameDiscoverer());
163163
optionalRequestPart = new SynthesizingMethodParameter(method, 16);
164164
}
165165

@@ -204,7 +204,7 @@ public void resolveMultipartFileArray() throws Exception {
204204
assertThat(actual).isNotNull();
205205
assertThat(actual instanceof MultipartFile[]).isTrue();
206206
MultipartFile[] parts = (MultipartFile[]) actual;
207-
assertThat(parts.length).isEqualTo(2);
207+
assertThat(parts).hasSize(2);
208208
assertThat(multipartFile1).isEqualTo(parts[0]);
209209
assertThat(multipartFile2).isEqualTo(parts[1]);
210210
}
@@ -270,7 +270,7 @@ public void resolvePartArrayArgument() throws Exception {
270270
Object result = resolver.resolveArgument(paramPartArray, null, webRequest, null);
271271
assertThat(result instanceof Part[]).isTrue();
272272
Part[] parts = (Part[]) result;
273-
assertThat(parts.length).isEqualTo(2);
273+
assertThat(parts).hasSize(2);
274274
assertThat(part1).isEqualTo(parts[0]);
275275
assertThat(part2).isEqualTo(parts[1]);
276276
}

0 commit comments

Comments
 (0)