@Test public void shouldThrowError() throws Exception { thrown.expect(NoClassDefFoundError.class); thrown.expectMessage("WillGoAway"); SuperClassMissing.main(new String[0]); }
/** * Runs the test using the specified harness. * * @param harness the test harness (<code>null</code> not permitted). */ public void test(TestHarness harness) { NoClassDefFoundError error1 = new NoClassDefFoundError(); harness.check(error1 != null); harness.check(error1.toString(), "java.lang.NoClassDefFoundError"); NoClassDefFoundError error2 = new NoClassDefFoundError("nothing happens"); harness.check(error2 != null); harness.check(error2.toString(), "java.lang.NoClassDefFoundError: nothing happens"); }
/** * Runs the test using the specified harness. * * @param harness the test harness (<code>null</code> not permitted). */ public void test(TestHarness harness) { // flag that is set when exception is caught boolean caught = false; try { throw new NoClassDefFoundError("NoClassDefFoundError"); } catch (NoClassDefFoundError e) { // correct exception was caught caught = true; } harness.check(caught); }