1 /*
2 * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
663 NULL_VALUES.put(short.class, (short) 0);
664 NULL_VALUES.put(char.class, '\0');
665 NULL_VALUES.put(int.class, 0);
666 NULL_VALUES.put(long.class, 0L);
667 NULL_VALUES.put(float.class, 0.0f);
668 NULL_VALUES.put(double.class, 0.0d);
669 }
670
671 /**
672 * Returns mandatory property value
673 * @param propName is a name of property to request
674 * @return a String with requested property value
675 */
676 public static String getMandatoryProperty(String propName) {
677 Objects.requireNonNull(propName, "Requested null property");
678 String prop = System.getProperty(propName);
679 Objects.requireNonNull(prop,
680 String.format("A mandatory property '%s' isn't set", propName));
681 return prop;
682 }
683 }
684
|
1 /*
2 * Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
663 NULL_VALUES.put(short.class, (short) 0);
664 NULL_VALUES.put(char.class, '\0');
665 NULL_VALUES.put(int.class, 0);
666 NULL_VALUES.put(long.class, 0L);
667 NULL_VALUES.put(float.class, 0.0f);
668 NULL_VALUES.put(double.class, 0.0d);
669 }
670
671 /**
672 * Returns mandatory property value
673 * @param propName is a name of property to request
674 * @return a String with requested property value
675 */
676 public static String getMandatoryProperty(String propName) {
677 Objects.requireNonNull(propName, "Requested null property");
678 String prop = System.getProperty(propName);
679 Objects.requireNonNull(prop,
680 String.format("A mandatory property '%s' isn't set", propName));
681 return prop;
682 }
683
684 // This method is intended to be called from a jtreg test.
685 // It will identify the name of the test by means of stack walking.
686 // It can handle both jtreg tests and a testng tests wrapped inside jtreg tests.
687 // For jtreg tests the name of the test will be searched by stack-walking
688 // until the method main() is found; the class containing that method is the
689 // main test class and will be returned as the name of the test.
690 // Special handling is used for testng tests.
691 public static String getTestName() {
692 String result = null;
693 // If we are using testng, then we should be able to load the "Test" annotation.
694 Class testClassAnnotation;
695
696 try {
697 testClassAnnotation = Class.forName("org.testng.annotations.Test");
698 } catch (ClassNotFoundException e) {
699 testClassAnnotation = null;
700 }
701
702 StackTraceElement[] elms = (new Throwable()).getStackTrace();
703 for (StackTraceElement n: elms) {
704 String className = n.getClassName();
705
706 // If this is a "main" method, then use its class name, but only
707 // if we are not using testng.
708 if (testClassAnnotation == null && "main".equals(n.getMethodName())) {
709 result = className;
710 break;
711 }
712
713 // If this is a testng test, the test will have no "main" method. We can
714 // detect a testng test class by looking for the org.testng.annotations.Test
715 // annotation. If present, then use the name of this class.
716 if (testClassAnnotation != null) {
717 try {
718 Class c = Class.forName(className);
719 if (c.isAnnotationPresent(testClassAnnotation)) {
720 result = className;
721 break;
722 }
723 } catch (ClassNotFoundException e) {
724 throw new RuntimeException("Unexpected exception: " + e, e);
725 }
726 }
727 }
728
729 if (result == null) {
730 throw new RuntimeException("Couldn't find main test class in stack trace");
731 }
732
733 return result;
734 }
735
736 }
737
|