Add Guava example
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.baeldung;
|
||||
|
||||
import com.google.common.primitives.Ints;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -43,6 +44,15 @@ public class StringToIntTest {
|
||||
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)
|
||||
public void givenInvalidInput_shouldThrow() throws Exception {
|
||||
String givenString = "nan";
|
||||
|
||||
Reference in New Issue
Block a user