review #2
This commit is contained in:
parent
dd98392dbe
commit
46c257f00f
@ -2,14 +2,16 @@ package com.baeldung.tostring;
|
||||
|
||||
public class StringCastUtils {
|
||||
public static String castToString(Object object) {
|
||||
if (object instanceof String)
|
||||
if (object instanceof String) {
|
||||
return (String) object;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getToString(Object object) {
|
||||
if (object != null)
|
||||
public static String getStringRepresentation(Object object) {
|
||||
if (object != null) {
|
||||
return object.toString();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,9 @@ package com.baeldung.tostring;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertSame;
|
||||
|
||||
public class ToStringUnitTest {
|
||||
@Test
|
||||
@ -96,7 +98,7 @@ public class ToStringUnitTest {
|
||||
|
||||
Object obj = input;
|
||||
|
||||
assertEquals("1234", StringCastUtils.getToString(obj));
|
||||
assertNotSame("1234", StringCastUtils.getToString(obj));
|
||||
assertEquals("1234", StringCastUtils.getStringRepresentation(obj));
|
||||
assertNotSame("1234", StringCastUtils.getStringRepresentation(obj));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user