diff --git a/src/test/java/org/apache/commons/lang3/ObjectUtilsTest.java b/src/test/java/org/apache/commons/lang3/ObjectUtilsTest.java index d42b93a34..445e5e2e7 100644 --- a/src/test/java/org/apache/commons/lang3/ObjectUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/ObjectUtilsTest.java @@ -192,11 +192,27 @@ public class ObjectUtilsTest { } @Test - public void testIdentityToStringStringBuilder() { + public void testIdentityToStringObjectNull() { assertNull(ObjectUtils.identityToString(null)); + } + + @Test + public void testIdentityToStringInteger() { + final Integer i = Integer.valueOf(90); + final String expected = "java.lang.Integer@" + Integer.toHexString(System.identityHashCode(i)); + + assertEquals(expected, ObjectUtils.identityToString(i)); + } + + @Test + public void testIdentityToStringString() { assertEquals( - "java.lang.String@" + Integer.toHexString(System.identityHashCode(FOO)), - ObjectUtils.identityToString(FOO)); + "java.lang.String@" + Integer.toHexString(System.identityHashCode(FOO)), + ObjectUtils.identityToString(FOO)); + } + + @Test + public void testIdentityToStringStringBuilder() { final Integer i = Integer.valueOf(90); final String expected = "java.lang.Integer@" + Integer.toHexString(System.identityHashCode(i)); @@ -205,15 +221,21 @@ public class ObjectUtilsTest { final StringBuilder builder = new StringBuilder(); ObjectUtils.identityToString(builder, i); assertEquals(expected, builder.toString()); + } + @Test + public void testIdentityToStringStringBuilderNullValue() { try { - ObjectUtils.identityToString((StringBuilder)null, "tmp"); + ObjectUtils.identityToString(new StringBuilder(), null); fail("NullPointerException expected"); } catch(final NullPointerException npe) { } + } + @Test + public void testIdentityToStringStringBuilderNullStringBuilder() { try { - ObjectUtils.identityToString(new StringBuilder(), null); + ObjectUtils.identityToString((StringBuilder)null, "tmp"); fail("NullPointerException expected"); } catch(final NullPointerException npe) { }