I'm writing a small app and have encountered the following issue:
@Test
public void givenSkiExists_whenAddingNewSki_thenThrowEntityAlreadyPresentException () {
skiManager.addEntity(new Ski(new SkiType("name1", "description1"), "brand1", "model1", "bond1", 1f));
assertThrows(EntityAlreadyPresentException.class, () -> skiManager.addEntity(new Ski(new SkiType("name1", "description1"), "brand1", "model1", "bond1", 1f)));
}
the first skiManager.addEntity can throw multiple custom errors, but this test is not designed to check that, it assumes the first addEntity will work correctly, but I still need to handle the unhandled exceptions, and my question is:
Do I let it crash by just adding throws Exception to the unit test declaration or should I wrap it with try {...} catch (Exception e) {fail(e.message);}? is there any advantage to the second approach?
assertDoesNotThrow(). It seems to be included to take your situation into account.