0
@Rule
public final ExpectedException exception = ExpectedException.none();

@Test
public void doStuffThrowsParseException() {
    TestException foo = new TestException();

    exception.expect(ParseException.class);
    foo.doStuff("haha");
}

main

Date submissionT;
SimpleDateFormat tempDate = new SimpleDateFormat("EEE MMM d HH:mm:ss z yyyy");
public void doStuff(String time) {
    try {
        submissionT=tempDate.parse(time);
      }
      catch (Exception e) {     
        System.out.println(e.toString() + ", " + time);
      }
}

results in java.text.ParseException: Unparseable date: "haha", haha.

Although a ParseException is thrown the test fails. Why?

030
  • 10,842
  • 12
  • 78
  • 123
  • @Tunaki. This is not a duplicate. The code snippet resides from the link and it is not working – 030 Jan 28 '16 at 18:52
  • Have you read the [accepted answer](http://stackoverflow.com/a/156528/1743880)? Because your code doesn't have what this answer is saying you should have. – Tunaki Jan 28 '16 at 18:53
  • @Tunaki Yes sir, but that does not work either. – 030 Jan 28 '16 at 18:54
  • 1
    Well yes, you are catching the exception and doing nothing with it: `catch (Exception e)`. – Tunaki Jan 28 '16 at 18:57

0 Answers0