jdk/test/java/lang/reflect/Method/GenericStringTest.java
changeset 39825 6441823cea46
parent 39731 7a4bc90065bd
equal deleted inserted replaced
39824:629cd556bb2e 39825:6441823cea46
    21  * questions.
    21  * questions.
    22  */
    22  */
    23 
    23 
    24 /*
    24 /*
    25  * @test
    25  * @test
    26  * @bug 5033583 6316717 6470106 8004979 8161500
    26  * @bug 5033583 6316717 6470106 8004979 8161500 8162539
    27  * @summary Check toGenericString() and toString() methods
    27  * @summary Check toGenericString() and toString() methods
    28  * @author Joseph D. Darcy
    28  * @author Joseph D. Darcy
    29  */
    29  */
    30 
    30 
    31 import java.lang.reflect.*;
    31 import java.lang.reflect.*;
    42                 ExpectedGenericString egs = method.getAnnotation(ExpectedGenericString.class);
    42                 ExpectedGenericString egs = method.getAnnotation(ExpectedGenericString.class);
    43                 if (egs != null) {
    43                 if (egs != null) {
    44                     String actual = method.toGenericString();
    44                     String actual = method.toGenericString();
    45                     System.out.println(actual);
    45                     System.out.println(actual);
    46                     if (method.isBridge()) {
    46                     if (method.isBridge()) {
    47                         if (! egs.bridgeValue().equals(actual)) {
    47                         failures += checkForFailure(egs.bridgeValue(), actual);
    48                             failures++;
       
    49                             System.err.printf("ERROR: Expected ''%s''; got ''%s''.\n",
       
    50                                               egs.value(), actual);
       
    51                         }
       
    52                     } else {
    48                     } else {
    53                         if (! egs.value().equals(actual)) {
    49                         failures += checkForFailure(egs.value(), actual);
    54                             failures++;
       
    55                             System.err.printf("ERROR: Expected ''%s''; got ''%s''.\n",
       
    56                                               egs.value(), actual);
       
    57                         }
       
    58                     }
    50                     }
    59                 }
    51                 }
    60 
    52 
    61                 if (method.isAnnotationPresent(ExpectedString.class)) {
    53                 if (method.isAnnotationPresent(ExpectedString.class)) {
    62                     ExpectedString es = method.getAnnotation(ExpectedString.class);
    54                     ExpectedString es = method.getAnnotation(ExpectedString.class);
    63                     String actual = method.toString();
    55                     String actual = method.toString();
    64                     if (! es.value().equals(actual)) {
    56                     failures += checkForFailure(es.value(), actual);
    65                         failures++;
       
    66                         System.err.printf("ERROR: Expected ''%s''; got ''%s''.\n",
       
    67                                           es.value(), actual);
       
    68                     }
       
    69                 }
    57                 }
    70 
    58 
    71             }
    59             }
    72 
    60 
    73         // Bridge Test; no "volatile" methods
    61         // Bridge Test; no "volatile" methods
    85 
    73 
    86         if (failures > 0) {
    74         if (failures > 0) {
    87             System.err.println("Test failed.");
    75             System.err.println("Test failed.");
    88             throw new RuntimeException();
    76             throw new RuntimeException();
    89         }
    77         }
       
    78     }
       
    79 
       
    80     private static int checkForFailure(String expected, String actual) {
       
    81         if (!expected.equals(actual)) {
       
    82             System.err.printf("ERROR: Expected ''%s'';%ngot             ''%s''.\n",
       
    83                               expected, actual);
       
    84             return 1;
       
    85         } else
       
    86             return 0;
    90     }
    87     }
    91 }
    88 }
    92 
    89 
    93 class TestClass1 {
    90 class TestClass1 {
    94     @ExpectedGenericString(
    91     @ExpectedGenericString(
   113    "public <T> T TestClass2.method1(E,T)")
   110    "public <T> T TestClass2.method1(E,T)")
   114     public <T> T method1(E e, T t) {return null;}
   111     public <T> T method1(E e, T t) {return null;}
   115 
   112 
   116     @ExpectedGenericString(
   113     @ExpectedGenericString(
   117    "public void TestClass2.method2() throws F")
   114    "public void TestClass2.method2() throws F")
       
   115     @ExpectedString(
       
   116    "public void TestClass2.method2() throws java.lang.Exception")
   118     public void method2() throws F {return;}
   117     public void method2() throws F {return;}
   119 
   118 
   120     @ExpectedGenericString(
   119     @ExpectedGenericString(
   121    "public E[] TestClass2.method3()")
   120    "public E[] TestClass2.method3()")
   122     public E[] method3() {return null;}
   121     public E[] method3() {return null;}