package com.googlecode.jslint4java;

import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;

import java.io.IOException;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

public class OptionParserTest {

    /** For generating exceptions. */
    private static class Foo {
        // Invoked via reflection.
        @SuppressWarnings("unused")
        public static Foo valueOf(String s) throws IOException {
            throw new IOException("burble");
        }
    }

    private final OptionParser optionParser = new OptionParser();

    @Rule
    public ExpectedException thrown = ExpectedException.none();

    @Test
    public void testNoSuchMethod() throws Exception {
        thrown.expect(RuntimeException.class);
        // root cause: NoSuchMethodException
        thrown.expectMessage("System.valueOf");
        optionParser.parse(System.class, "foo");
    }

    @Test
    public void testParseBoolean() throws Exception {
        assertThat(optionParser.parse(Boolean.class, "true"), is(Boolean.TRUE));
    }

    @Test
    public void testParseInteger() throws Exception {
        assertThat(optionParser.parse(Integer.class, "2"), is(2));
    }

    @Test
    public void testParseIntegerFailure() throws Exception {
        thrown.expect(NumberFormatException.class);
        optionParser.parse(Integer.class, "foo");
    }

    @Test
    public void testRuntimeExceptionWrapping() throws Exception {
        thrown.expect(RuntimeException.class);
        // root cause: IOException
        thrown.expectMessage("IOException: burble");
        optionParser.parse(Foo.class, "foo");
    }
}

@@ -137,16 +137,50 @@
 ption;%0A%0A
+import org.hamcrest.CoreMatchers;%0A
 import o
@@ -194,16 +194,16 @@
 t.Rule;%0A
-
 import o
@@ -821,31 +821,70 @@
         
-// root cause: 
+thrown.expectCause(CoreMatchers.%3CThrowable%3EinstanceOf(
 NoSuchMe
@@ -888,32 +888,41 @@
 hMethodException
+.class));
 %0A        thrown.
@@ -1615,23 +1615,62 @@
     
-// root cause: 
+thrown.expectCause(CoreMatchers.%3CThrowable%3EinstanceOf(
 IOEx
@@ -1676,16 +1676,25 @@
 xception
+.class));
 %0A       

Make use of expectCause().