ObjectUtils { public static Object toExternalObject( Object value) { return toObject( String.valueOf( value)); } private  ObjectUtils(); static Object toObject( String value); static Object toExternalObject( Object value);  }
@Test public void toExternalObject_whenNull() { String value = null; Object object = ObjectUtils.toExternalObject( value); assertThat( "Null", object, is( (Object) null)); value = "null"; object = ObjectUtils.toExternalObject( value); assertThat( "Null", object, is( (Object) null)); }
@Test public void toExternalObject_whenString() { String value = "This is just a plain old string"; Object object = ObjectUtils.toExternalObject( value); assertThat( "String", object, is( value)); }
@Test public void toExternalObject_whenInteger() { Integer value = Integer.MAX_VALUE; Object object = ObjectUtils.toExternalObject( value); assertThat( "Integer", object, is( value)); object = ObjectUtils.toExternalObject( String.valueOf( value)); assertThat( "Integer", object, is( value)); }
@Test public void toExternalObject_whenLong() { Long value = Long.MIN_VALUE; Object object = ObjectUtils.toExternalObject( value); assertThat( "Long", object, is( value)); object = ObjectUtils.toExternalObject( String.valueOf( value)); assertThat( "Long", object, is( value)); value = 0L; object = ObjectUtils.toExternalObject( value); assertThat( "Long", object, is( value.intValue())); }
@Test public void toExternalObject_whenDecimal() { BigDecimal value = new BigDecimal( "-42.00"); Object object = ObjectUtils.toExternalObject( value); assertThat( "Decimal", object, is( value)); object = ObjectUtils.toExternalObject( String.valueOf( value)); assertThat( "Decimal", object, is( value)); value = new BigDecimal( Long.MAX_VALUE); object = ObjectUtils.toExternalObject( value); assertThat( "Decimal", object, is( value.longValueExact())); value = new BigDecimal( Integer.MAX_VALUE); object = ObjectUtils.toExternalObject( value); assertThat( "Decimal", object, is( value.intValueExact())); }
@Test public void toExternalObject_whenBoolean() { Boolean value = true; Object object = ObjectUtils.toExternalObject( value); assertThat( "Boolean", object, is( value)); value = false; object = ObjectUtils.toExternalObject( String.valueOf( value).toUpperCase()); assertThat( "Boolean", object, is( value)); }