/
ExceptionalBean.java
66 lines (58 loc) · 1.7 KB
/
ExceptionalBean.java
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
66
/**
*
*/
package org.json.junit.data;
import java.io.Closeable;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
/**
* Object for testing the exception handling in {@link org.json.JSONObject#populateMap}.
*
* @author John Aylward
*/
public class ExceptionalBean {
/**
* @return a closeable.
*/
public Closeable getCloseable() {
// anonymous inner class did not work...
return new MyCloseable();
}
/**
* @return Nothing really. Just can't be void.
* @throws IllegalAccessException
* always thrown
*/
public int getIllegalAccessException() throws IllegalAccessException {
throw new IllegalAccessException("Yup, it's illegal");
}
/**
* @return Nothing really. Just can't be void.
* @throws IllegalArgumentException
* always thrown
*/
public int getIllegalArgumentException() throws IllegalArgumentException {
throw new IllegalArgumentException("Yup, it's illegal");
}
/**
* @return Nothing really. Just can't be void.
* @throws InvocationTargetException
* always thrown
*/
public int getInvocationTargetException() throws InvocationTargetException {
throw new InvocationTargetException(new Exception("Yup, it's illegal"));
}
/** My closeable class. */
public static final class MyCloseable implements Closeable {
/**
* @return a string
*/
public String getString() {
return "Yup, it's closeable";
}
@Override
public void close() throws IOException {
throw new IOException("Closing is too hard!");
}
}
}