Path: blob/master/test/jdk/java/lang/StackTraceElement/PublicConstructor.java
41149 views
/*1* Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 4712607 647923726* @summary Basic test for StackTraceElementPublic constructor27* @author Josh Bloch28*/2930import java.lang.module.ModuleDescriptor;3132public class PublicConstructor {33public static void main(String... args) {34testConstructor();35testConstructorWithModule();36}3738static void testConstructor() {39StackTraceElement ste = new StackTraceElement("com.acme.Widget",40"frobnicate",41"Widget.java", 42);42if (!(ste.getClassName().equals("com.acme.Widget") &&43ste.getFileName().equals("Widget.java") &&44ste.getMethodName().equals("frobnicate") &&45ste.getLineNumber() == 42))46throw new RuntimeException("1");4748if (ste.isNativeMethod())49throw new RuntimeException("2");5051assertEquals(ste.toString(),52"com.acme.Widget.frobnicate(Widget.java:42)");5354StackTraceElement ste1 = new StackTraceElement("com.acme.Widget",55"frobnicate",56"Widget.java",57-2);58if (!ste1.isNativeMethod())59throw new RuntimeException("3");6061assertEquals(ste1.toString(),62"com.acme.Widget.frobnicate(Native Method)");63}6465static void testConstructorWithModule() {66StackTraceElement ste = new StackTraceElement("app",67"jdk.module",68"9.0",69"com.acme.Widget",70"frobnicate",71"Widget.java",7242);73if (!(ste.getClassName().equals("com.acme.Widget") &&74ste.getModuleName().equals("jdk.module") &&75ste.getModuleVersion().equals("9.0") &&76ste.getClassLoaderName().equals("app") &&77ste.getFileName().equals("Widget.java") &&78ste.getMethodName().equals("frobnicate") &&79ste.getLineNumber() == 42))80throw new RuntimeException("3");8182if (ste.isNativeMethod())83throw new RuntimeException("4");8485assertEquals(ste.toString(),86"app/[email protected]/com.acme.Widget.frobnicate(Widget.java:42)");87}8889static void assertEquals(String s, String expected) {90if (!s.equals(expected)) {91throw new RuntimeException("Expected: " + expected + " but found: " + s);92}93}94}959697