2016-11-14 09:45:01 +01:00
|
|
|
package com.baeldung;
|
|
|
|
|
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
|
|
|
|
|
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
|
|
|
|
|
public class AssertionTest {
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testConvertToDoubleThrowException() {
|
|
|
|
|
String age = "eighteen";
|
2017-05-07 23:11:55 +05:30
|
|
|
assertThrows(NumberFormatException.class, () -> {
|
2016-11-14 09:45:01 +01:00
|
|
|
convertToInt(age);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
assertThrows(NumberFormatException.class, () -> {
|
|
|
|
|
convertToInt(age);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static Integer convertToInt(String str) {
|
|
|
|
|
if (str == null) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return Integer.valueOf(str);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|