-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathExceptionTest.java
More file actions
65 lines (53 loc) · 1.88 KB
/
Copy pathExceptionTest.java
File metadata and controls
65 lines (53 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package org.python.tests;
import junit.framework.TestCase;
import org.python.core.Py;
import org.python.util.PythonInterpreter;
public class ExceptionTest extends TestCase {
public static class Checked extends Exception {}
public interface Thrower {
void checked() throws Checked;
void checkedOrRuntime(boolean checked) throws Checked;
}
public void setUp() {
String raiser =
"from java.lang import Throwable\n" +
"from org.python.tests.ExceptionTest import Checked, Thrower\n" +
"class Raiser(Thrower):\n" +
" def checked(self):\n" +
" raise Checked()\n" +
" def checkedOrRuntime(self, checked):\n" +
" if checked:\n" +
" raise Checked()\n" +
" else:\n" +
" raise Throwable()\n" +
"r = Raiser()";
PythonInterpreter interp = new PythonInterpreter();
interp.exec(raiser);
t = Py.tojava(interp.get("r"), Thrower.class);
}
public void testRaisingCheckedException() {
try {
t.checked();
fail("Calling checked should raise Checked!");
} catch (Checked c) {
// All is as it should be.
}
try {
t.checkedOrRuntime(true);
fail("Calling checkedOrRuntime(true) should raise Checked!");
} catch (Checked c) {
// All is as it should be.
}
}
public void testRaisingRuntimeException() {
try {
t.checkedOrRuntime(false);
fail("Calling checkedOrRuntime(false) should raise Throwable!");
} catch (Checked c) {
fail("Calling checkedOrRuntime(false) should raise Throwable!");
} catch (Throwable t) {
// All is as it should be.
}
}
protected Thrower t;
}