Junit4 

import static org.assertj.core.api.Assertions.assertThatThrownBy;
...
assertThatThrownBy(()->Integer.parseInt("One")).isInstanceOf(NumberFormatException.class);

 

Junit5

import org.junit.jupiter.api.Assertions;
...
Assertions.assertThrows(NumberFormatException.class, () -> {
      Integer.parseInt("One");
    });

+ Recent posts