提交 4b9e3a92 编写于 作者: S Sam Brannen

Introduce failing test for SPR-16652

This commit introduces tests for looking up annotations on parameters
in constructors for nested and inner classes via Spring's
MethodParameter abstraction.

The test for an inner class is currently disabled since it fails on
JDK 8. See JIRA issue for details.

Issue: SPR-16652
上级 d95bbb6b
/*
* 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 {
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册