diff --git a/core-java-8/src/test/java/com/baeldung/StringToIntTest.java b/core-java-8/src/test/java/com/baeldung/StringToIntOrIntegerTest.java similarity index 59% rename from core-java-8/src/test/java/com/baeldung/StringToIntTest.java rename to core-java-8/src/test/java/com/baeldung/StringToIntOrIntegerTest.java index 9f1c611e04..6c1493d89b 100644 --- a/core-java-8/src/test/java/com/baeldung/StringToIntTest.java +++ b/core-java-8/src/test/java/com/baeldung/StringToIntOrIntegerTest.java @@ -5,10 +5,10 @@ import org.junit.Test; import static org.assertj.core.api.Assertions.assertThat; -public class StringToIntTest { +public class StringToIntOrIntegerTest { @Test - public void givenString_shouldConvertToInt1() throws Exception { + public void givenString_whenParsingInt_shouldConvertToInt() { String givenString = "42"; int result = Integer.parseInt(givenString); @@ -18,25 +18,25 @@ public class StringToIntTest { @Test - public void givenString_shouldConvertToInt2() throws Exception { + public void givenString_whenCallingIntegerValueOf_shouldConvertToInt() { String givenString = "42"; Integer result = Integer.valueOf(givenString); - assertThat(result).isEqualTo(42); + assertThat(result).isEqualTo(new Integer(42)); } @Test - public void givenString_shouldConvertToInt3() throws Exception { + public void givenString_whenCallingIntegerConstructor_shouldConvertToInt() { String givenString = "42"; Integer result = new Integer(givenString); - assertThat(result).isEqualTo(42); + assertThat(result).isEqualTo(new Integer(42)); } @Test - public void givenString_shouldConvertToInt4() throws Exception { + public void givenString_whenCallingIntegerDecode_shouldConvertToInt() { String givenString = "42"; int result = Integer.decode(givenString); @@ -45,7 +45,7 @@ public class StringToIntTest { } @Test - public void givenString_shouldConvertToInt5() throws Exception { + public void givenString_whenTryParse_shouldConvertToInt() { String givenString = "42"; Integer result = Ints.tryParse(givenString); @@ -54,10 +54,9 @@ public class StringToIntTest { } @Test(expected = NumberFormatException.class) - public void givenInvalidInput_shouldThrow() throws Exception { + public void givenInvalidInput_whenParsingInt_shouldThrow() { String givenString = "nan"; - - int result = Integer.parseInt(givenString); + Integer.parseInt(givenString); } }