Last active
March 3, 2019 20:15
-
-
Save wkorando/48759bde824d7664b3435de832455db2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TestHandleExceptionsJUnit5 { | |
@Test | |
public void testExceptionHandling() { | |
Exception e = assertThrows(SpecificException.class, () -> onlyThrowsExceptions()); | |
assertEquals("An exception was thrown!", e.getMessage()); | |
} | |
@Test | |
public void testExceptionHandlingFailWrongExceptionType() { | |
assertThrows(Exception.class, () -> doesntThrowExceptions(), "Wrong exception type thrown!"); | |
} | |
@Test | |
public void testExceptionHandlingFailNoExceptionThrown() { | |
assertThrows(SpecificException.class, () -> doesntThrowExceptions(), "An exception wasn't thrown!"); | |
} | |
public void onlyThrowsExceptions() throws SpecificException { | |
throw new SpecificException("An exception was thrown!"); | |
} | |
public void doesntThrowExceptions() { | |
//do nothing | |
} | |
public class SpecificException extends Exception{ | |
public SpecificException(String message) { | |
super(message); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment