2016-04-15 23:47:32 +03:00
|
|
|
package com.baeldung;
|
|
|
|
|
|
2016-11-14 09:45:01 +01:00
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
2016-04-15 23:47:32 +03:00
|
|
|
|
2016-11-14 09:45:01 +01:00
|
|
|
import org.junit.jupiter.api.Test;
|
2016-04-15 23:47:32 +03:00
|
|
|
|
2017-05-15 18:35:14 +02:00
|
|
|
public class ExceptionUnitTest {
|
2016-04-15 23:47:32 +03:00
|
|
|
|
2016-11-14 09:45:01 +01:00
|
|
|
@Test
|
|
|
|
|
void shouldThrowException() {
|
2017-05-07 23:11:55 +05:30
|
|
|
Throwable exception = assertThrows(UnsupportedOperationException.class, () -> {
|
2016-11-14 09:45:01 +01:00
|
|
|
throw new UnsupportedOperationException("Not supported");
|
|
|
|
|
});
|
|
|
|
|
assertEquals(exception.getMessage(), "Not supported");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void assertThrowsException() {
|
|
|
|
|
String str = null;
|
|
|
|
|
assertThrows(IllegalArgumentException.class, () -> {
|
|
|
|
|
Integer.valueOf(str);
|
|
|
|
|
});
|
|
|
|
|
}
|
2016-04-15 23:47:32 +03:00
|
|
|
}
|