33362
|
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 |
* @summary Testing IllegalStateException.
|
|
27 |
* @build KullaTesting TestingInputStream JShellStateClosedTest
|
|
28 |
* @run testng JShellStateClosedTest
|
|
29 |
*/
|
|
30 |
|
|
31 |
import java.util.function.Consumer;
|
|
32 |
|
|
33 |
import jdk.jshell.DeclarationSnippet;
|
|
34 |
import jdk.jshell.PersistentSnippet;
|
|
35 |
import jdk.jshell.Snippet;
|
|
36 |
import jdk.jshell.VarSnippet;
|
|
37 |
import org.testng.annotations.Test;
|
|
38 |
|
|
39 |
import static org.testng.Assert.fail;
|
|
40 |
|
|
41 |
@Test
|
|
42 |
public class JShellStateClosedTest extends KullaTesting {
|
|
43 |
|
|
44 |
private void testStateClosedException(Runnable action) {
|
|
45 |
getState().close();
|
|
46 |
try {
|
|
47 |
action.run();
|
|
48 |
fail("Exception expected");
|
|
49 |
} catch (IllegalStateException e) {
|
|
50 |
// Expected
|
|
51 |
}
|
|
52 |
}
|
|
53 |
|
|
54 |
public void testClasses() {
|
|
55 |
testStateClosedException(() -> getState().types());
|
|
56 |
}
|
|
57 |
|
|
58 |
public void testVariables() {
|
|
59 |
testStateClosedException(() -> getState().variables());
|
|
60 |
}
|
|
61 |
|
|
62 |
public void testMethods() {
|
|
63 |
testStateClosedException(() -> getState().methods());
|
|
64 |
}
|
|
65 |
|
|
66 |
public void testKeys() {
|
|
67 |
testStateClosedException(() -> getState().snippets());
|
|
68 |
}
|
|
69 |
|
|
70 |
public void testEval() {
|
|
71 |
testStateClosedException(() -> getState().eval("int a;"));
|
|
72 |
}
|
|
73 |
|
|
74 |
private void testStateClosedException(Consumer<Snippet> action) {
|
|
75 |
Snippet k = varKey(assertEval("int a;"));
|
|
76 |
getState().close();
|
|
77 |
try {
|
|
78 |
action.accept(k);
|
|
79 |
fail("IllegalStateException expected since closed");
|
|
80 |
} catch (IllegalStateException e) {
|
|
81 |
// Expected
|
|
82 |
}
|
|
83 |
}
|
|
84 |
|
|
85 |
private void testStateClosedWithoutException(Consumer<Snippet> action) {
|
|
86 |
Snippet k = varKey(assertEval("int a;"));
|
|
87 |
getState().close();
|
|
88 |
try {
|
|
89 |
action.accept(k);
|
|
90 |
} catch (IllegalStateException e) {
|
|
91 |
fail("Expected no IllegalStateException even though closed");
|
|
92 |
}
|
|
93 |
}
|
|
94 |
|
|
95 |
public void testStatus() {
|
|
96 |
testStateClosedWithoutException((key) -> getState().status(key));
|
|
97 |
}
|
|
98 |
|
|
99 |
public void testVarValue() {
|
|
100 |
testStateClosedException((key) -> getState().varValue((VarSnippet) key));
|
|
101 |
}
|
|
102 |
|
|
103 |
public void testDrop() {
|
|
104 |
testStateClosedException((key) -> getState().drop((PersistentSnippet) key));
|
|
105 |
}
|
|
106 |
|
|
107 |
public void testUnresolved() {
|
|
108 |
testStateClosedWithoutException((key) -> getState().unresolvedDependencies((DeclarationSnippet) key));
|
|
109 |
}
|
|
110 |
|
|
111 |
public void testDiagnostics() {
|
|
112 |
testStateClosedWithoutException((key) -> getState().diagnostics(key));
|
|
113 |
}
|
|
114 |
}
|