Add Guava example

This commit is contained in:
Grzegorz Piwowarek 2016-08-22 16:28:38 +02:00
parent d26bdb7621
commit 6f38d0b12e
1 changed files with 10 additions and 0 deletions

View File

@ -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";