< prev index next >
test/java/lang/reflect/Constructor/GenericStringTest.java
Print this page
@@ -21,11 +21,11 @@
* questions.
*/
/*
* @test
- * @bug 5033583 6316717 6470106 8161500
+ * @bug 5033583 6316717 6470106 8161500 8162539
* @summary Check toGenericString() and toString() methods
* @author Joseph D. Darcy
*/
import java.lang.reflect.*;
@@ -39,32 +39,32 @@
for(Class<?> clazz: List.of(TestClass1.class, TestClass2.class))
for(Constructor<?> ctor: clazz.getDeclaredConstructors()) {
ExpectedGenericString egs = ctor.getAnnotation(ExpectedGenericString.class);
String actual = ctor.toGenericString();
System.out.println(actual);
- if (! egs.value().equals(actual)) {
- failures++;
- System.err.printf("ERROR: Expected generic string ''%s''; got ''%s''.\n",
- egs.value(), actual);
- }
+ failures += checkForFailure(egs.value(), actual);
if (ctor.isAnnotationPresent(ExpectedString.class)) {
- ExpectedString es = ctor.getAnnotation(ExpectedString.class);
- String result = ctor.toString();
- if (! es.value().equals(result)) {
- failures++;
- System.err.printf("ERROR: Expected ''%s''; got ''%s''.\n",
- es.value(), result);
- }
+ failures += checkForFailure(ctor.getAnnotation(ExpectedString.class).value(),
+ ctor.toString());
}
}
if (failures > 0) {
System.err.println("Test failed.");
throw new RuntimeException();
}
}
+
+ private static int checkForFailure(String expected, String actual) {
+ if (!expected.equals(actual)) {
+ System.err.printf("ERROR: Expected ''%s'';%ngot ''%s''.\n",
+ expected, actual);
+ return 1;
+ } else
+ return 0;
+ }
}
class TestClass1 {
@ExpectedGenericString(
"TestClass1(int,double)")
@@ -74,17 +74,27 @@
"private TestClass1(int,int)")
private TestClass1(int x, int param2) {}
@ExpectedGenericString(
"private TestClass1(java.lang.Object) throws java.lang.RuntimeException")
+ @ExpectedString(
+ "private TestClass1(java.lang.Object) throws java.lang.RuntimeException")
private TestClass1(Object o) throws RuntimeException {}
@ExpectedGenericString(
"protected <S,T> TestClass1(S,T) throws java.lang.Exception")
+ @ExpectedString(
+ "protected TestClass1(java.lang.Object,java.lang.Object) throws java.lang.Exception")
protected <S, T> TestClass1(S s, T t) throws Exception{}
@ExpectedGenericString(
+ "<E> TestClass1() throws E")
+ @ExpectedString(
+ "TestClass1() throws java.lang.Exception")
+ <E extends Exception> TestClass1() throws E {}
+
+ @ExpectedGenericString(
"TestClass1(java.lang.Object...)")
@ExpectedString(
"TestClass1(java.lang.Object[])")
TestClass1(Object... o){}
}
< prev index next >