Path: blob/master/test/jdk/java/lang/StackWalker/SanityTest.java
41149 views
/*1* Copyright (c) 2015, 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 814045026* @summary Sanity test for exception cases27* @run testng SanityTest28*/293031import java.util.Collections;32import java.util.Set;3334import org.testng.annotations.Test;3536public class SanityTest {37@Test38public static void testNPE() {39try {40StackWalker sw = StackWalker.getInstance((Set<StackWalker.Option>) null);41throw new RuntimeException("NPE expected");42} catch (NullPointerException e) {}4344try {45StackWalker sw = StackWalker.getInstance((StackWalker.Option) null);46throw new RuntimeException("NPE expected");47} catch (NullPointerException e) {}48}4950@Test51public static void testUOE() {52try {53StackWalker.getInstance().getCallerClass();54throw new RuntimeException("UOE expected");55} catch (UnsupportedOperationException expected) {}56}5758@Test59public static void testInvalidEstimateDepth() {60try {61StackWalker sw = StackWalker.getInstance(Collections.emptySet(), 0);62throw new RuntimeException("Illegal estimateDepth should throw IAE");63} catch (IllegalArgumentException e) {}64}6566@Test67public static void testNullFuncation() {68try {69StackWalker.getInstance().walk(null);70throw new RuntimeException("NPE expected");71} catch (NullPointerException e) {}72}7374@Test75public static void testNullConsumer() {76try {77StackWalker.getInstance().forEach(null);78throw new RuntimeException("NPE expected");79} catch (NullPointerException e) {}80}818283@Test84public static void testUOEFromGetDeclaringClass() {85try {86StackWalker sw = StackWalker.getInstance();87sw.forEach(StackWalker.StackFrame::getDeclaringClass);88throw new RuntimeException("UOE expected");89} catch (UnsupportedOperationException expected) {90}91}9293@Test94public static void testUOEFromGetMethodType() {95try {96StackWalker sw = StackWalker.getInstance();97sw.forEach(StackWalker.StackFrame::getMethodType);98throw new RuntimeException("UOE expected");99} catch (UnsupportedOperationException expected) {}100}101}102103104