diff --git a/spring-core/src/test/java/org/springframework/core/type/AbstractMethodMetadataTests.java b/spring-core/src/test/java/org/springframework/core/type/AbstractMethodMetadataTests.java index 799626afd1b..a7defe230a7 100644 --- a/spring-core/src/test/java/org/springframework/core/type/AbstractMethodMetadataTests.java +++ b/spring-core/src/test/java/org/springframework/core/type/AbstractMethodMetadataTests.java @@ -105,6 +105,12 @@ public abstract class AbstractMethodMetadataTests { assertThat(getTagged(WithMethod.class).getMethodName()).isEqualTo("test"); } + @Test + void toStringMethodShowsPrimitives() { + assertThat(getTagged(WithMethodParameters.class).toString()) + .isEqualTo("public java.lang.String org.springframework.core.type.AbstractMethodMetadataTests$WithMethodParameters.test(java.lang.String[],int)"); + } + @Test void getDeclaringClassReturnsDeclaringClass() { assertThat(getTagged(WithMethod.class).getDeclaringClassName()).isEqualTo(WithMethod.class.getName()); @@ -291,6 +297,15 @@ public abstract class AbstractMethodMetadataTests { } + public static class WithMethodParameters { + + @Tag + public String test(String[] names, int age) { + return ""; + } + + } + public static class WithVoidMethod { @Tag diff --git a/spring-core/src/test/java24/org/springframework/core/type/classreading/ClassFileMethodMetadataToStringTests.java b/spring-core/src/test/java24/org/springframework/core/type/classreading/ClassFileMethodMetadataToStringTests.java deleted file mode 100644 index 5bebcfa928a..00000000000 --- a/spring-core/src/test/java24/org/springframework/core/type/classreading/ClassFileMethodMetadataToStringTests.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2002-present 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. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.core.type.classreading; - -import org.junit.jupiter.api.Test; - -import org.springframework.core.io.DefaultResourceLoader; -import org.springframework.core.type.MethodMetadata; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Tests for parameter type rendering by the {@code java.lang.classfile} based - * {@link ClassFileMethodMetadata}'s {@code toString()}. - * - * @author junhyeong9812 - */ -class ClassFileMethodMetadataToStringTests { - - @Test - void toStringRendersParameterTypeNames() throws Exception { - ClassFileMetadataReaderFactory factory = new ClassFileMetadataReaderFactory(new DefaultResourceLoader()); - MetadataReader reader = factory.getMetadataReader(WithMethod.class.getName()); - MethodMetadata method = reader.getAnnotationMetadata().getDeclaredMethods().stream() - .filter(candidate -> candidate.getMethodName().equals("sample")) - .findFirst() - .orElseThrow(); - // primitive and array parameter types must keep their canonical names, - // not be prefixed with "." (".int", ".String[]") - assertThat(method.toString()).endsWith(".sample(int,java.lang.String[])"); - } - - - @SuppressWarnings("unused") - static class WithMethod { - - public void sample(int number, String[] values) { - } - } - -}