[BAEL-5661] Integer.toString vs String.valueOf (#12591)

* Initial commit for Object copy in Java

* review comments commit for Object copy in Java

* Initial commit for parseInt vs valueOf java

* Review comments commit for parseInt vs valueOf java

* Modify readme

* review comments

* build failure

* build failure retry

* build failure retry remove parseInt(java.lang.String,int,int,int)

* build failure add comment

* change examples

* review comments

* review comments 2

* review comments 3

* Initial commit for get current stacktrace

* Remove old files

* Name updates

* Jenkins error

* changes to file name

* Review comments

* Create unit test file

* Remove unnecessary files
This commit is contained in:
sdhiray7 2022-08-14 23:53:47 +05:30 committed by GitHub
parent a800f72b99
commit 06ac43bc9e
1 changed files with 29 additions and 0 deletions

View File

@ -0,0 +1,29 @@
package com.baeldung.chararraytostring;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
public class IntToStringUnitTest {
@Test
public void whenValidIntIsPassed_thenShouldConvertToString() {
assertEquals("11", Integer.toString(11));
assertEquals("11", Integer.toString(+11));
assertEquals("-11", Integer.toString(-11));
}
@Test
public void whenValidIntIsPassed_thenShouldConvertToValidString() {
assertEquals("11", String.valueOf(11));
assertEquals("11", String.valueOf(+11));
assertEquals("-11", String.valueOf(-11));
}
@Test(expected = NullPointerException.class)
public void whenNullIntegerObjectIsPassed_thenShouldThrowException() {
Integer i = null;
System.out.println(String.valueOf(i)); // it prints "null"
System.out.println(i.toString());
}
}