diff --git a/spring-core/src/test/java/org/springframework/core/MethodParameterTests.java b/spring-core/src/test/java/org/springframework/core/MethodParameterTests.java index 6d5dc18f27..2a1815b526 100644 --- a/spring-core/src/test/java/org/springframework/core/MethodParameterTests.java +++ b/spring-core/src/test/java/org/springframework/core/MethodParameterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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. @@ -16,9 +16,15 @@ package org.springframework.core; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import java.lang.reflect.Constructor; import java.lang.reflect.Method; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; import static org.junit.Assert.*; @@ -26,6 +32,7 @@ import static org.junit.Assert.*; /** * @author Arjen Poutsma * @author Juergen Hoeller + * @author Sam Brannen */ public class MethodParameterTests { @@ -98,9 +105,48 @@ public class MethodParameterTests { new MethodParameter(method, 2); } + @Test + public void annotatedConstructorParameterInStaticNestedClass() throws Exception { + Constructor constructor = NestedClass.class.getDeclaredConstructor(String.class); + MethodParameter methodParameter = MethodParameter.forExecutable(constructor, 0); + assertEquals(String.class, methodParameter.getParameterType()); + assertNotNull("Failed to find @Param annotation", methodParameter.getParameterAnnotation(Param.class)); + assertNotNull(methodParameter.getParameterAnnotation(Param.class)); + } + + @Test + @Ignore("Disabled until SPR-16652 is resolved") + public void annotatedConstructorParameterInInnerClass() throws Exception { + Constructor constructor = InnerClass.class.getDeclaredConstructor(getClass(), String.class); + MethodParameter methodParameter = MethodParameter.forExecutable(constructor, 1); + assertEquals(String.class, methodParameter.getParameterType()); + assertNull(methodParameter.getParameterAnnotation(Override.class)); + // The following assertion currently fails if this test class is compiled using JDK 8. + assertNotNull("Failed to find @Param annotation", methodParameter.getParameterAnnotation(Param.class)); + } + public int method(String p1, long p2) { return 42; } + @SuppressWarnings("unused") + private static class NestedClass { + + NestedClass(@Param String s) { + } + } + + @SuppressWarnings("unused") + private class InnerClass { + + InnerClass(@Param String s) { + } + } + + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.PARAMETER) + private @interface Param { + } + }