I am throwing Exception into my unit test but after throwing it I still want to continue testing
doThrow(new Exception()).when(myMock).myMethod(); myMock.myMethod(); System.out.println("Here"); // this is never called // Do verify and asserts
Can this be done?
You can just catch the exception:
doThrow(new MyException()).when(myMock).myMethod(); try { myMock.myMethod(); fail("MyException should have been thrown!"); } catch (MyException expected) { // Do something } System.out.println("Here"); // Verify the mock, assert, etc.