@@ -113,6 +113,11 @@ public final class Utils {
113
113
public static final String TEST_CLASSES = System .getProperty ("test.classes" , "." );
114
114
115
115
/**
116
+ * Returns the value of 'test.name' system property
117
+ */
118
+ public static final String TEST_NAME = System .getProperty ("test.name" , "." );
119
+
120
+ /**
116
121
* Defines property name for seed value.
117
122
*/
118
123
public static final String SEED_PROPERTY_NAME = "jdk.test.lib.random.seed" ;
@@ -824,87 +829,6 @@ public static String distro() {
824
829
}
825
830
}
826
831
827
- // This method is intended to be called from a jtreg test.
828
- // It will identify the name of the test by means of stack walking.
829
- // It can handle both jtreg tests and a testng tests wrapped inside jtreg tests.
830
- // For jtreg tests the name of the test will be searched by stack-walking
831
- // until the method main() is found; the class containing that method is the
832
- // main test class and will be returned as the name of the test.
833
- // Special handling is used for testng tests.
834
- @ SuppressWarnings ("unchecked" )
835
- public static String getTestName () {
836
- String result = null ;
837
- // If we are using testng, then we should be able to load the "Test" annotation.
838
- Class <? extends Annotation > testClassAnnotation , junitTestClassAnnotation ;
839
-
840
- try {
841
- testClassAnnotation = (Class <? extends Annotation >)Class .forName ("org.testng.annotations.Test" );
842
- } catch (ClassNotFoundException e ) {
843
- testClassAnnotation = null ;
844
- }
845
-
846
- // If we are using junit, then we should be able to load the "Test" annotation.
847
- try {
848
- junitTestClassAnnotation = (Class <? extends Annotation >)Class .forName ("org.junit.Test" );
849
- } catch (ClassNotFoundException e ) {
850
- junitTestClassAnnotation = null ;
851
- }
852
-
853
- StackTraceElement [] elms = (new Throwable ()).getStackTrace ();
854
- for (StackTraceElement n : elms ) {
855
- String className = n .getClassName ();
856
-
857
- // If this is a "main" method, then use its class name, but only
858
- // if we are not using testng or junit.
859
- if (testClassAnnotation == null && junitTestClassAnnotation == null &&
860
- "main" .equals (n .getMethodName ())) {
861
- result = className ;
862
- break ;
863
- }
864
-
865
- // If this is a testng test, the test will have no "main" method. We can
866
- // detect a testng test class by looking for the org.testng.annotations.Test
867
- // annotation. If present, then use the name of this class.
868
- if (testClassAnnotation != null ) {
869
- try {
870
- Class <?> c = Class .forName (className );
871
- if (c .isAnnotationPresent (testClassAnnotation )) {
872
- result = className ;
873
- break ;
874
- }
875
- } catch (ClassNotFoundException e ) {
876
- throw new RuntimeException ("Unexpected exception: " + e , e );
877
- }
878
- }
879
-
880
- // If this is a junit test, the test will have no "main" method. We can
881
- // detect a junit test class by going through all the methods and
882
- // check if the method has the org.junit.Test annotation. If present,
883
- // then use the name of this class.
884
- if (junitTestClassAnnotation != null ) {
885
- try {
886
- Class <?> c = Class .forName (className );
887
- Method [] methods = c .getMethods ();
888
- for (Method method : methods ) {
889
- if (method .getName ().equals (n .getMethodName ()) &&
890
- method .isAnnotationPresent (junitTestClassAnnotation )) {
891
- result = className ;
892
- break ;
893
- }
894
- }
895
- } catch (ClassNotFoundException e ) {
896
- throw new RuntimeException ("Unexpected exception: " + e , e );
897
- }
898
- }
899
- }
900
-
901
- if (result == null ) {
902
- throw new RuntimeException ("Couldn't find main test class in stack trace" );
903
- }
904
-
905
- return result ;
906
- }
907
-
908
832
/**
909
833
* Creates an empty file in "user.dir" if the property set.
910
834
* <p>
0 commit comments