test/lib/jdk/test/lib/Utils.java
changeset 58144 d003b3ef8b60
parent 55199 3a09397c147e
child 58679 9c3209ff7550
child 59053 ba6c248cae19
equal deleted inserted replaced
58143:b35771556cd0 58144:d003b3ef8b60
    23 
    23 
    24 package jdk.test.lib;
    24 package jdk.test.lib;
    25 
    25 
    26 import java.io.File;
    26 import java.io.File;
    27 import java.io.IOException;
    27 import java.io.IOException;
       
    28 import java.lang.annotation.Annotation;
    28 import java.net.InetAddress;
    29 import java.net.InetAddress;
    29 import java.net.InetSocketAddress;
    30 import java.net.InetSocketAddress;
    30 import java.net.MalformedURLException;
    31 import java.net.MalformedURLException;
    31 import java.net.ServerSocket;
    32 import java.net.ServerSocket;
    32 import java.net.URL;
    33 import java.net.URL;
   747     // It can handle both jtreg tests and a testng tests wrapped inside jtreg tests.
   748     // It can handle both jtreg tests and a testng tests wrapped inside jtreg tests.
   748     // For jtreg tests the name of the test will be searched by stack-walking
   749     // For jtreg tests the name of the test will be searched by stack-walking
   749     // until the method main() is found; the class containing that method is the
   750     // until the method main() is found; the class containing that method is the
   750     // main test class and will be returned as the name of the test.
   751     // main test class and will be returned as the name of the test.
   751     // Special handling is used for testng tests.
   752     // Special handling is used for testng tests.
       
   753     @SuppressWarnings("unchecked")
   752     public static String getTestName() {
   754     public static String getTestName() {
   753         String result = null;
   755         String result = null;
   754         // If we are using testng, then we should be able to load the "Test" annotation.
   756         // If we are using testng, then we should be able to load the "Test" annotation.
   755         Class testClassAnnotation;
   757         Class<? extends Annotation> testClassAnnotation;
   756 
   758 
   757         try {
   759         try {
   758             testClassAnnotation = Class.forName("org.testng.annotations.Test");
   760             testClassAnnotation = (Class<? extends Annotation>)Class.forName("org.testng.annotations.Test");
   759         } catch (ClassNotFoundException e) {
   761         } catch (ClassNotFoundException e) {
   760             testClassAnnotation = null;
   762             testClassAnnotation = null;
   761         }
   763         }
   762 
   764 
   763         StackTraceElement[] elms = (new Throwable()).getStackTrace();
   765         StackTraceElement[] elms = (new Throwable()).getStackTrace();
   774             // If this is a testng test, the test will have no "main" method. We can
   776             // If this is a testng test, the test will have no "main" method. We can
   775             // detect a testng test class by looking for the org.testng.annotations.Test
   777             // detect a testng test class by looking for the org.testng.annotations.Test
   776             // annotation. If present, then use the name of this class.
   778             // annotation. If present, then use the name of this class.
   777             if (testClassAnnotation != null) {
   779             if (testClassAnnotation != null) {
   778                 try {
   780                 try {
   779                     Class c = Class.forName(className);
   781                     Class<?> c = Class.forName(className);
   780                     if (c.isAnnotationPresent(testClassAnnotation)) {
   782                     if (c.isAnnotationPresent(testClassAnnotation)) {
   781                         result = className;
   783                         result = className;
   782                         break;
   784                         break;
   783                     }
   785                     }
   784                 } catch (ClassNotFoundException e) {
   786                 } catch (ClassNotFoundException e) {