Amend the test method names to include a when, remove unused throws and change equals test to assert Integer
This commit is contained in:
parent
539fe75116
commit
4f7cb84630
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue