Merge pull request #9414 from mona-mohamadinia/BAEL-4158
BAEL-4158: Improvement String to Int Article
This commit is contained in:
commit
0f355d1f0b
|
@ -17,6 +17,15 @@ public class StringToIntOrIntegerUnitTest {
|
||||||
assertThat(result).isEqualTo(42);
|
assertThat(result).isEqualTo(42);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenBinaryString_whenParsingInt_shouldConvertToInt() {
|
||||||
|
String givenString = "101010";
|
||||||
|
|
||||||
|
int result = Integer.parseInt(givenString, 2);
|
||||||
|
|
||||||
|
assertThat(result).isEqualTo(42);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenString_whenCallingIntegerValueOf_shouldConvertToInt() {
|
public void givenString_whenCallingIntegerValueOf_shouldConvertToInt() {
|
||||||
String givenString = "42";
|
String givenString = "42";
|
||||||
|
@ -27,6 +36,15 @@ public class StringToIntOrIntegerUnitTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
public void givenBinaryString_whenCallingIntegerValueOf_shouldConvertToInt() {
|
||||||
|
String givenString = "101010";
|
||||||
|
|
||||||
|
Integer result = Integer.valueOf(givenString, 2);
|
||||||
|
|
||||||
|
assertThat(result).isEqualTo(new Integer(42));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void givenString_whenCallingValueOf_shouldCacheSomeValues() {
|
public void givenString_whenCallingValueOf_shouldCacheSomeValues() {
|
||||||
for (int i = -128; i <= 127; i++) {
|
for (int i = -128; i <= 127; i++) {
|
||||||
String value = i + "";
|
String value = i + "";
|
||||||
|
|
Loading…
Reference in New Issue