From 087a50b2e723d3ca2f8ce327129ad305d9519beb Mon Sep 17 00:00:00 2001 From: sdhiray7 Date: Wed, 17 Aug 2022 21:04:12 +0530 Subject: [PATCH] [BAEL-5661] Integer.toString(int i) vs String.valueOf(int i) (#12606) * 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 * Update package name --- .../java/com/baeldung/inttostring/IntToStringUnitTest.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/core-java-modules/core-java-string-conversions-2/src/test/java/com/baeldung/inttostring/IntToStringUnitTest.java b/core-java-modules/core-java-string-conversions-2/src/test/java/com/baeldung/inttostring/IntToStringUnitTest.java index b865d0933d..34a4097d05 100644 --- a/core-java-modules/core-java-string-conversions-2/src/test/java/com/baeldung/inttostring/IntToStringUnitTest.java +++ b/core-java-modules/core-java-string-conversions-2/src/test/java/com/baeldung/inttostring/IntToStringUnitTest.java @@ -1,4 +1,4 @@ -package com.baeldung.chararraytostring; +package com.baeldung.inttostring; import static org.junit.Assert.assertEquals; @@ -23,7 +23,8 @@ public class IntToStringUnitTest { @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()); + // NOTE: primitive int can never be null, we are checking this example to check in what case the exception is thrown by these methods. + System.out.println(String.valueOf(i)); // prints "null" as the call goes to String.valueOf(Object obj) method + System.out.println(i.toString()); // throws NPE } }