55
66import static org .assertj .core .api .Assertions .assertThat ;
77
8- public class StringToIntTest {
8+ public class StringToIntOrIntegerTest {
99
1010 @ Test
11- public void givenString_shouldConvertToInt1 () throws Exception {
11+ public void givenString_whenParsingInt_shouldConvertToInt () {
1212 String givenString = "42" ;
1313
1414 int result = Integer .parseInt (givenString );
@@ -18,25 +18,25 @@ public void givenString_shouldConvertToInt1() throws Exception {
1818
1919
2020 @ Test
21- public void givenString_shouldConvertToInt2 () throws Exception {
21+ public void givenString_whenCallingIntegerValueOf_shouldConvertToInt () {
2222 String givenString = "42" ;
2323
2424 Integer result = Integer .valueOf (givenString );
2525
26- assertThat (result ).isEqualTo (42 );
26+ assertThat (result ).isEqualTo (new Integer ( 42 ) );
2727 }
2828
2929 @ Test
30- public void givenString_shouldConvertToInt3 () throws Exception {
30+ public void givenString_whenCallingIntegerConstructor_shouldConvertToInt () {
3131 String givenString = "42" ;
3232
3333 Integer result = new Integer (givenString );
3434
35- assertThat (result ).isEqualTo (42 );
35+ assertThat (result ).isEqualTo (new Integer ( 42 ) );
3636 }
3737
3838 @ Test
39- public void givenString_shouldConvertToInt4 () throws Exception {
39+ public void givenString_whenCallingIntegerDecode_shouldConvertToInt () {
4040 String givenString = "42" ;
4141
4242 int result = Integer .decode (givenString );
@@ -45,7 +45,7 @@ public void givenString_shouldConvertToInt4() throws Exception {
4545 }
4646
4747 @ Test
48- public void givenString_shouldConvertToInt5 () throws Exception {
48+ public void givenString_whenTryParse_shouldConvertToInt () {
4949 String givenString = "42" ;
5050
5151 Integer result = Ints .tryParse (givenString );
@@ -54,10 +54,9 @@ public void givenString_shouldConvertToInt5() throws Exception {
5454 }
5555
5656 @ Test (expected = NumberFormatException .class )
57- public void givenInvalidInput_shouldThrow () throws Exception {
57+ public void givenInvalidInput_whenParsingInt_shouldThrow () {
5858 String givenString = "nan" ;
59-
60- int result = Integer .parseInt (givenString );
59+ Integer .parseInt (givenString );
6160 }
6261
6362}
0 commit comments