Testowanie wyjątków
import static org.junit.jupiter.api.Assertions.assertThrows;
import org.junit.jupiter.api.Test;
class ExceptionsDemo {
@Test
public void shouldThrowExceptionWhenHostIsNull() {
assertThrows(IllegalArgumentException.class, () -> {
ConfigFactory.getForDatabase(null, 3000);
});
}
@Test
public void shouldThrowExceptionWhenHostIsEmpty() {
Throwable exception = assertThrows(IllegalArgumentException.class, () -> {
ConfigFactory.getForDatabase("", 3000);
});
assertEquals("Host cannot be empty!", exception.getMessage());
}
}