Skip to content

Commit

Permalink
Consistent use of DefaultParameterNameResolver in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoeller committed Nov 23, 2022
1 parent 00da70e commit 0e33537
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 49 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2022 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.
Expand Down Expand Up @@ -27,7 +27,7 @@
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.config.ConstructorArgumentValues;
import org.springframework.beans.factory.config.DependencyDescriptor;
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
import org.springframework.core.DefaultParameterNameDiscoverer;
import org.springframework.core.MethodParameter;
import org.springframework.util.ClassUtils;

Expand Down Expand Up @@ -148,7 +148,7 @@ public void testAutowireCandidateWithConstructorDescriptor() throws Exception {
lbf.registerBeanDefinition(MARK, person2);
MethodParameter param = new MethodParameter(QualifiedTestBean.class.getDeclaredConstructor(Person.class), 0);
DependencyDescriptor qualifiedDescriptor = new DependencyDescriptor(param, false);
param.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());
param.initParameterNameDiscovery(new DefaultParameterNameDiscoverer());
assertThat(param.getParameterName()).isEqualTo("tpb");
assertThat(lbf.isAutowireCandidate(JUERGEN, null)).isTrue();
assertThat(lbf.isAutowireCandidate(JUERGEN, qualifiedDescriptor)).isTrue();
Expand All @@ -174,9 +174,9 @@ public void testAutowireCandidateWithMethodDescriptor() throws Exception {
new MethodParameter(QualifiedTestBean.class.getDeclaredMethod("autowireNonqualified", Person.class), 0);
DependencyDescriptor qualifiedDescriptor = new DependencyDescriptor(qualifiedParam, false);
DependencyDescriptor nonqualifiedDescriptor = new DependencyDescriptor(nonqualifiedParam, false);
qualifiedParam.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());
qualifiedParam.initParameterNameDiscovery(new DefaultParameterNameDiscoverer());
assertThat(qualifiedParam.getParameterName()).isEqualTo("tpb");
nonqualifiedParam.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());
nonqualifiedParam.initParameterNameDiscovery(new DefaultParameterNameDiscoverer());
assertThat(nonqualifiedParam.getParameterName()).isEqualTo("tpb");
assertThat(lbf.isAutowireCandidate(JUERGEN, null)).isTrue();
assertThat(lbf.isAutowireCandidate(JUERGEN, nonqualifiedDescriptor)).isTrue();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2022 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.
Expand Down Expand Up @@ -34,7 +34,7 @@
*/
class LocalVariableTableParameterNameDiscovererTests {

private final LocalVariableTableParameterNameDiscoverer discoverer = new LocalVariableTableParameterNameDiscoverer();
private final ParameterNameDiscoverer discoverer = new LocalVariableTableParameterNameDiscoverer();


@Test
Expand Down Expand Up @@ -162,45 +162,45 @@ void generifiedClass() throws Exception {

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

ctor = clazz.getDeclaredConstructor(Object.class, Object.class);
names = discoverer.getParameterNames(ctor);
assertThat(names.length).isEqualTo(2);
assertThat(names).hasSize(2);
assertThat(names[0]).isEqualTo("key");
assertThat(names[1]).isEqualTo("value");

Method m = clazz.getMethod("generifiedStaticMethod", Object.class);
names = discoverer.getParameterNames(m);
assertThat(names.length).isEqualTo(1);
assertThat(names).hasSize(1);
assertThat(names[0]).isEqualTo("param");

m = clazz.getMethod("generifiedMethod", Object.class, long.class, Object.class, Object.class);
names = discoverer.getParameterNames(m);
assertThat(names.length).isEqualTo(4);
assertThat(names).hasSize(4);
assertThat(names[0]).isEqualTo("param");
assertThat(names[1]).isEqualTo("x");
assertThat(names[2]).isEqualTo("key");
assertThat(names[3]).isEqualTo("value");

m = clazz.getMethod("voidStaticMethod", Object.class, long.class, int.class);
names = discoverer.getParameterNames(m);
assertThat(names.length).isEqualTo(3);
assertThat(names).hasSize(3);
assertThat(names[0]).isEqualTo("obj");
assertThat(names[1]).isEqualTo("x");
assertThat(names[2]).isEqualTo("i");

m = clazz.getMethod("nonVoidStaticMethod", Object.class, long.class, int.class);
names = discoverer.getParameterNames(m);
assertThat(names.length).isEqualTo(3);
assertThat(names).hasSize(3);
assertThat(names[0]).isEqualTo("obj");
assertThat(names[1]).isEqualTo("x");
assertThat(names[2]).isEqualTo("i");

m = clazz.getMethod("getDate");
names = discoverer.getParameterNames(m);
assertThat(names.length).isEqualTo(0);
assertThat(names).isEmpty();
}

@Disabled("Ignored because Ubuntu packages OpenJDK with debug symbols enabled. See SPR-8078.")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2022 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.
Expand All @@ -22,7 +22,6 @@

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledForJreRange;
import reactor.blockhound.BlockHound;
import reactor.core.scheduler.ReactorBlockHoundIntegration;
import reactor.core.scheduler.Schedulers;
Expand All @@ -32,22 +31,19 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.jupiter.api.condition.JRE.JAVA_14;

/**
* Tests to verify the spring-core BlockHound integration rules.
*
* @author Rossen Stoyanchev
* @since 5.2.4
*/
@DisabledForJreRange(min = JAVA_14)
public class SpringCoreBlockHoundIntegrationTests {


@BeforeAll
static void setUp() {
static void setup() {
BlockHound.builder()
.with(new ReactorBlockHoundIntegration()) // Reactor non-blocking thread predicate
.with(new ReactorBlockHoundIntegration()) // Reactor non-blocking thread predicate
.with(new ReactiveAdapterRegistry.SpringCoreBlockHoundIntegration())
.install();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2022 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.
Expand All @@ -26,7 +26,7 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
import org.springframework.core.DefaultParameterNameDiscoverer;
import org.springframework.core.MethodParameter;
import org.springframework.core.annotation.SynthesizingMethodParameter;
import org.springframework.messaging.Message;
Expand Down Expand Up @@ -81,7 +81,7 @@ public void setup() throws Exception {
this.paramAnnotatedRequired = new SynthesizingMethodParameter(payloadMethod, 2);
this.paramWithSpelExpression = new SynthesizingMethodParameter(payloadMethod, 3);
this.paramValidated = new SynthesizingMethodParameter(payloadMethod, 4);
this.paramValidated.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());
this.paramValidated.initParameterNameDiscovery(new DefaultParameterNameDiscoverer());
this.paramValidatedNotAnnotated = new SynthesizingMethodParameter(payloadMethod, 5);
this.paramNotAnnotated = new SynthesizingMethodParameter(payloadMethod, 6);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2022 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.
Expand Down Expand Up @@ -39,7 +39,7 @@
import org.springframework.cglib.proxy.Enhancer;
import org.springframework.cglib.proxy.Factory;
import org.springframework.cglib.proxy.MethodProxy;
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
import org.springframework.core.DefaultParameterNameDiscoverer;
import org.springframework.core.MethodIntrospector;
import org.springframework.core.MethodParameter;
import org.springframework.core.ParameterNameDiscoverer;
Expand Down Expand Up @@ -131,7 +131,7 @@ public class ResolvableMethod {

private static final SpringObjenesis objenesis = new SpringObjenesis();

private static final ParameterNameDiscoverer nameDiscoverer = new LocalVariableTableParameterNameDiscoverer();
private static final ParameterNameDiscoverer nameDiscoverer = new DefaultParameterNameDiscoverer();

// Matches ValueConstants.DEFAULT_NONE (spring-web and spring-messaging)
private static final String DEFAULT_VALUE_NONE = "\n\t\t\n\t\t\n\uE000\uE001\uE002\n\t\t\t\t\n";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import org.junit.jupiter.api.Test;

import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
import org.springframework.core.DefaultParameterNameDiscoverer;
import org.springframework.core.convert.ConversionService;
import org.springframework.format.support.DefaultFormattingConversionService;
import org.springframework.web.bind.WebDataBinder;
Expand Down Expand Up @@ -128,7 +128,7 @@ private WebDataBinderFactory createFactory(String methodName, Class<?>... parame
InvocableHandlerMethod handlerMethod = new InvocableHandlerMethod(handler, method);
handlerMethod.setHandlerMethodArgumentResolvers(this.argumentResolvers);
handlerMethod.setDataBinderFactory(new DefaultDataBinderFactory(null));
handlerMethod.setParameterNameDiscoverer(new LocalVariableTableParameterNameDiscoverer());
handlerMethod.setParameterNameDiscoverer(new DefaultParameterNameDiscoverer());

return new InitBinderDataBinderFactory(
Collections.singletonList(handlerMethod), this.bindingInitializer);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2022 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.
Expand All @@ -22,7 +22,7 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
import org.springframework.core.DefaultParameterNameDiscoverer;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
Expand Down Expand Up @@ -177,7 +177,7 @@ public void updateModelBindingResult() throws Exception {
assertThat(container.getModel().get(commandName)).isEqualTo(command);
String bindingResultKey = BindingResult.MODEL_KEY_PREFIX + commandName;
assertThat(container.getModel().get(bindingResultKey)).isSameAs(dataBinder.getBindingResult());
assertThat(container.getModel().size()).isEqualTo(2);
assertThat(container.getModel()).hasSize(2);
}

@Test
Expand Down Expand Up @@ -240,7 +240,7 @@ public void updateModelWhenRedirecting() throws Exception {
modelFactory.updateModel(this.webRequest, container);

assertThat(container.getModel().get(queryParamName)).isEqualTo(queryParam);
assertThat(container.getModel().size()).isEqualTo(1);
assertThat(container.getModel()).hasSize(1);
assertThat(this.attributeStore.retrieveAttribute(this.webRequest, attributeName)).isEqualTo(attribute);
}

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

return new ModelFactory(Collections.singletonList(modelMethod), null, this.attributeHandler);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2022 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.
Expand Down Expand Up @@ -39,7 +39,7 @@
import org.springframework.cglib.proxy.Enhancer;
import org.springframework.cglib.proxy.Factory;
import org.springframework.cglib.proxy.MethodProxy;
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
import org.springframework.core.DefaultParameterNameDiscoverer;
import org.springframework.core.MethodIntrospector;
import org.springframework.core.MethodParameter;
import org.springframework.core.ParameterNameDiscoverer;
Expand Down Expand Up @@ -130,7 +130,7 @@ public class ResolvableMethod {

private static final SpringObjenesis objenesis = new SpringObjenesis();

private static final ParameterNameDiscoverer nameDiscoverer = new LocalVariableTableParameterNameDiscoverer();
private static final ParameterNameDiscoverer nameDiscoverer = new DefaultParameterNameDiscoverer();

// Matches ValueConstants.DEFAULT_NONE (spring-web and spring-messaging)
private static final String DEFAULT_VALUE_NONE = "\n\t\t\n\t\t\n\uE000\uE001\uE002\n\t\t\t\t\n";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

import org.junit.jupiter.api.Test;

import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
import org.springframework.core.DefaultParameterNameDiscoverer;
import org.springframework.core.ReactiveAdapterRegistry;
import org.springframework.core.convert.ConversionService;
import org.springframework.format.support.DefaultFormattingConversionService;
Expand Down Expand Up @@ -131,7 +131,7 @@ private BindingContext createBindingContext(String methodName, Class<?>... param

SyncInvocableHandlerMethod handlerMethod = new SyncInvocableHandlerMethod(handler, method);
handlerMethod.setArgumentResolvers(new ArrayList<>(this.argumentResolvers));
handlerMethod.setParameterNameDiscoverer(new LocalVariableTableParameterNameDiscoverer());
handlerMethod.setParameterNameDiscoverer(new DefaultParameterNameDiscoverer());

return new InitBinderBindingContext(this.bindingInitializer, Collections.singletonList(handlerMethod));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
import org.springframework.core.DefaultParameterNameDiscoverer;
import org.springframework.core.MethodParameter;
import org.springframework.core.annotation.SynthesizingMethodParameter;
import org.springframework.http.HttpInputMessage;
Expand Down Expand Up @@ -138,28 +138,28 @@ public InputStream getInputStream() throws IOException {

Method method = ReflectionUtils.findMethod(getClass(), "handle", (Class<?>[]) null);
paramRequestPart = new SynthesizingMethodParameter(method, 0);
paramRequestPart.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());
paramRequestPart.initParameterNameDiscovery(new DefaultParameterNameDiscoverer());
paramNamedRequestPart = new SynthesizingMethodParameter(method, 1);
paramValidRequestPart = new SynthesizingMethodParameter(method, 2);
paramMultipartFile = new SynthesizingMethodParameter(method, 3);
paramMultipartFileList = new SynthesizingMethodParameter(method, 4);
paramMultipartFileArray = new SynthesizingMethodParameter(method, 5);
paramInt = new SynthesizingMethodParameter(method, 6);
paramMultipartFileNotAnnot = new SynthesizingMethodParameter(method, 7);
paramMultipartFileNotAnnot.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());
paramMultipartFileNotAnnot.initParameterNameDiscovery(new DefaultParameterNameDiscoverer());
paramPart = new SynthesizingMethodParameter(method, 8);
paramPart.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());
paramPart.initParameterNameDiscovery(new DefaultParameterNameDiscoverer());
paramPartList = new SynthesizingMethodParameter(method, 9);
paramPartArray = new SynthesizingMethodParameter(method, 10);
paramRequestParamAnnot = new SynthesizingMethodParameter(method, 11);
optionalMultipartFile = new SynthesizingMethodParameter(method, 12);
optionalMultipartFile.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());
optionalMultipartFile.initParameterNameDiscovery(new DefaultParameterNameDiscoverer());
optionalMultipartFileList = new SynthesizingMethodParameter(method, 13);
optionalMultipartFileList.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());
optionalMultipartFileList.initParameterNameDiscovery(new DefaultParameterNameDiscoverer());
optionalPart = new SynthesizingMethodParameter(method, 14);
optionalPart.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());
optionalPart.initParameterNameDiscovery(new DefaultParameterNameDiscoverer());
optionalPartList = new SynthesizingMethodParameter(method, 15);
optionalPartList.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());
optionalPartList.initParameterNameDiscovery(new DefaultParameterNameDiscoverer());
optionalRequestPart = new SynthesizingMethodParameter(method, 16);
}

Expand Down Expand Up @@ -204,7 +204,7 @@ public void resolveMultipartFileArray() throws Exception {
assertThat(actual).isNotNull();
assertThat(actual instanceof MultipartFile[]).isTrue();
MultipartFile[] parts = (MultipartFile[]) actual;
assertThat(parts.length).isEqualTo(2);
assertThat(parts).hasSize(2);
assertThat(multipartFile1).isEqualTo(parts[0]);
assertThat(multipartFile2).isEqualTo(parts[1]);
}
Expand Down Expand Up @@ -270,7 +270,7 @@ public void resolvePartArrayArgument() throws Exception {
Object result = resolver.resolveArgument(paramPartArray, null, webRequest, null);
assertThat(result instanceof Part[]).isTrue();
Part[] parts = (Part[]) result;
assertThat(parts.length).isEqualTo(2);
assertThat(parts).hasSize(2);
assertThat(part1).isEqualTo(parts[0]);
assertThat(part2).isEqualTo(parts[1]);
}
Expand Down

0 comments on commit 0e33537

Please sign in to comment.