package com.github.havarunner;

import com.github.havarunner.exception.TestDidNotRiseExpectedException;
import org.junit.Test;
import org.junit.runner.notification.Failure;

import static com.github.havarunner.TestHelper.runAndRecordFailure;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertEquals;

public class ExpectedExceptionTest {

    @Test
    public void HavaRunner_supports_the_expected_exception_in_the_Test_annotation() {
        Failure failure = runAndRecordFailure(new HavaRunner(TestWithExpectedException.class));
        assertNull(failure);
    }

    @Test
    public void HavaRunner_fails_the_test_if_the_expected_exception_is_not_thrown() {
        Failure failure = runAndRecordFailure(new HavaRunner(TestWithUnexpectedException.class));
        assertEquals(failure.getException().getClass(), TestDidNotRiseExpectedException.class);
        assertEquals(
            "Test com.github.havarunner.ExpectedExceptionTest$TestWithUnexpectedException#this_is_a_test_that_passes_unexpectedly did not throw the expected exception java.lang.UnsupportedOperationException",
            failure.getMessage()
        );
    }

    static class TestWithExpectedException {

        @Test(expected = IllegalStateException.class)
        void this_should_rise_an_exception() {
            throw new IllegalStateException("This is an expected exception");
        }
    }

    static class TestWithUnexpectedException {

        @Test(expected = UnsupportedOperationException.class)
        void this_is_a_test_that_passes_unexpectedly() {

        }
    }
}

@@ -235,16 +235,62 @@
 ailure;%0A
+import static org.junit.Assert.assertNotNull;%0A
 import s
@@ -320,24 +320,24 @@
 assertNull;%0A
-
 import stati
@@ -1200,32 +1200,356 @@
       );%0A    %7D%0A%0A
+    @Test%0A    public void HavaRunner_fails_if_the_test_throws_an_exception_that_is_not_the_expected_exception() %7B%0A        Failure failure = runAndRecordFailure(new HavaRunner(ExpectingOtherExceptionButGotAnother.class));%0A        assertEquals(failure.getException().getClass(), TestDidNotRiseExpectedException.class);%0A    %7D%0A%0A
     static class
@@ -1938,24 +1938,24 @@
 ctedly() %7B%0A%0A
-
         %7D%0A  
@@ -1957,11 +1957,385 @@
  %7D%0A    %7D
+%0A%0A    static class ExpectingOtherExceptionButGotAnother %7B%0A%0A        @Test(expected = OtherExpection.class)%0A        public void shouldThrowOtherExpection() %7B%0A            throw new SomeException();%0A        %7D%0A%0A        private static class SomeException extends RuntimeException %7B%0A        %7D%0A%0A        private static class OtherExpection extends RuntimeException %7B%0A        %7D%0A%0A    %7D
 %0A%7D%0A

Add expected exception test