1 /*
2  * Copyright (c) 2015, 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  */
23 
24 /*
25  * @test
26  * @bug 8020968
27  * @summary Basic test for Stream<StackFrame> state
28  * @run main StackStreamState
29  */
30 
31 package test.java.lang.StackWalker;
32 
33 import java.lang.StackWalker.StackFrame;
34 import java.util.stream.Stream;
35 import org.testng.annotations.Test;
36 
37 public class StackStreamState {
main(String... args)38     public static void main(String... args) {
39         StackStreamState test = new StackStreamState();
40         test.testStatic();
41         test.testInstance();
42         test.testLocal();
43     }
44 
45     private static Stream<StackFrame> staticStream;
46     private Stream<StackFrame> instanceStream;
47     private final StackWalker walker = StackWalker.getInstance();
48 
49     // Android-changed: Add @Test annotation.
50     // void testStatic() {
51     @Test
testStatic()52     public void testStatic() {
53         walker.walk(s -> {
54             staticStream = s;
55             return null;
56         });
57         checkStreamState(staticStream);
58     }
59 
60     // Android-changed: Add @Test annotation.
61     // void testInstance() {
62     @Test
testInstance()63     public void testInstance() {
64         walker.walk(s -> {
65             instanceStream = s;
66             return null;
67         });
68         checkStreamState(instanceStream);
69     }
70     // Android-changed: Add @Test annotation.
71     // void testLocal() {
72     @Test
testLocal()73     public void testLocal() {
74         Stream<StackFrame> stream = walker.walk(s -> {
75             return s;
76         });
77         checkStreamState(stream);
78     }
checkStreamState(Stream<StackFrame> stream)79     void checkStreamState(Stream<StackFrame> stream) {
80         try {
81             stream.count();
82             throw new RuntimeException("IllegalStateException not thrown");
83         } catch (IllegalStateException e) {
84             System.out.println("Got expected IllegalStateException: " + e.getMessage());
85             e.printStackTrace(System.out);
86         }
87     }
88 }
89