27 lines
672 B
Java
Raw Normal View History

2016-04-15 23:47:32 +03:00
package com.baeldung;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.expectThrows;
2016-04-15 23:47:32 +03:00
import org.junit.jupiter.api.Test;
2016-04-15 23:47:32 +03:00
public class ExceptionTest {
@Test
void shouldThrowException() {
Throwable exception = expectThrows(UnsupportedOperationException.class, () -> {
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
}