Add Guava example
This commit is contained in:
parent
d26bdb7621
commit
6f38d0b12e
|
@ -1,5 +1,6 @@
|
||||||
package com.baeldung;
|
package com.baeldung;
|
||||||
|
|
||||||
|
import com.google.common.primitives.Ints;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
@ -43,6 +44,15 @@ public class StringToIntTest {
|
||||||
assertThat(result).isEqualTo(42);
|
assertThat(result).isEqualTo(42);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenString_shouldConvertToInt5() throws Exception {
|
||||||
|
String givenString = "42";
|
||||||
|
|
||||||
|
Integer result = Ints.tryParse(givenString);
|
||||||
|
|
||||||
|
assertThat(result).isEqualTo(42);
|
||||||
|
}
|
||||||
|
|
||||||
@Test(expected = NumberFormatException.class)
|
@Test(expected = NumberFormatException.class)
|
||||||
public void givenInvalidInput_shouldThrow() throws Exception {
|
public void givenInvalidInput_shouldThrow() throws Exception {
|
||||||
String givenString = "nan";
|
String givenString = "nan";
|
||||||
|
|
Loading…
Reference in New Issue