refactor: simplify ParseInteger (#4376)

This commit is contained in:
Piotr Idzik
2023-09-16 20:57:03 +02:00
committed by GitHub
parent 5bb54977fe
commit 58c21c5756
2 changed files with 38 additions and 12 deletions

View File

@ -8,6 +8,7 @@ import org.junit.jupiter.api.Test;
*/
public class ParseIntegerTest {
private static final String NULL_PARAMETER_MESSAGE = "Input parameter must not be null!";
private static final String EMPTY_PARAMETER_MESSAGE = "Input parameter must not be empty!";
private static final String INCORRECT_FORMAT_MESSAGE = "Input parameter of incorrect format";
@Test
@ -16,6 +17,12 @@ public class ParseIntegerTest {
Assertions.assertEquals(exception.getMessage(), NULL_PARAMETER_MESSAGE);
}
@Test
public void testEmptyInput() {
IllegalArgumentException exception = Assertions.assertThrows(IllegalArgumentException.class, () -> ParseInteger.parseInt(""));
Assertions.assertEquals(exception.getMessage(), EMPTY_PARAMETER_MESSAGE);
}
@Test
public void testInputOfIncorrectFormat() {
IllegalArgumentException exception = Assertions.assertThrows(NumberFormatException.class, () -> ParseInteger.parseInt("+0a123"));