|
| 1 | +/** |
| 2 | + * |
| 3 | + */ |
| 4 | +package org.json.junit.data; |
| 5 | + |
| 6 | +import java.io.Closeable; |
| 7 | +import java.io.IOException; |
| 8 | +import java.lang.reflect.InvocationTargetException; |
| 9 | + |
| 10 | +import org.json.JSONObject; |
| 11 | + |
| 12 | +/** |
| 13 | + * Object for testing the exception handling in {@link JSONObject#populateMap}. |
| 14 | + * |
| 15 | + * @author John Aylward |
| 16 | + */ |
| 17 | +public class ExceptionalBean { |
| 18 | + /** |
| 19 | + * @return a closeable. |
| 20 | + */ |
| 21 | + public Closeable getCloseable() { |
| 22 | + // anonymous inner class did not work... |
| 23 | + return new MyCloseable(); |
| 24 | + } |
| 25 | + |
| 26 | + /** |
| 27 | + * @return Nothing really. Just can't be void. |
| 28 | + * @throws IllegalAccessException |
| 29 | + * always thrown |
| 30 | + */ |
| 31 | + public int getIllegalAccessException() throws IllegalAccessException { |
| 32 | + throw new IllegalAccessException("Yup, it's illegal"); |
| 33 | + } |
| 34 | + |
| 35 | + /** |
| 36 | + * @return Nothing really. Just can't be void. |
| 37 | + * @throws IllegalArgumentException |
| 38 | + * always thrown |
| 39 | + */ |
| 40 | + public int getIllegalArgumentException() throws IllegalArgumentException { |
| 41 | + throw new IllegalArgumentException("Yup, it's illegal"); |
| 42 | + } |
| 43 | + |
| 44 | + /** |
| 45 | + * @return Nothing really. Just can't be void. |
| 46 | + * @throws InvocationTargetException |
| 47 | + * always thrown |
| 48 | + */ |
| 49 | + public int getInvocationTargetException() throws InvocationTargetException { |
| 50 | + throw new InvocationTargetException(new Exception("Yup, it's illegal")); |
| 51 | + } |
| 52 | + |
| 53 | + /** My closeable class. */ |
| 54 | + public static final class MyCloseable implements Closeable { |
| 55 | + |
| 56 | + /** |
| 57 | + * @return a string |
| 58 | + */ |
| 59 | + @SuppressWarnings("unused") |
| 60 | + public String getString() { |
| 61 | + return "Yup, it's closeable"; |
| 62 | + } |
| 63 | + |
| 64 | + @Override |
| 65 | + public void close() throws IOException { |
| 66 | + throw new IOException("Closing is too hard!"); |
| 67 | + } |
| 68 | + } |
| 69 | +} |
0 commit comments