JavaToValueConverter { public static Value convertBoxedJavaType(Object boxed) { if (boxed == null) { return null; } final Class<?> clazz = boxed.getClass(); if (clazz == String.class) { return new StringValue((String) boxed); } else if (clazz == Integer.class) { return new IntValue((Integer) boxed); } else if (clazz == Long.class) { return new LongValue((Long) boxed); } else if (clazz == Double.class) { return new DoubleValue((Double) boxed); } else if (clazz == Float.class) { return new FloatValue((Float) boxed); } else if (clazz == Boolean.class) { return new BooleanValue((Boolean) boxed); } else if (clazz == Byte.class) { return new ByteValue((Byte) boxed); } else if (clazz == Short.class) { return new ShortValue((Short) boxed); } else if (clazz == Character.class) { return new CharValue((Character) boxed); } else { throw new IllegalArgumentException("Object is no primitive Java type."); } }  static Value convertBoxedJavaType(Object boxed); static Object convertValueType(Value value);  }
@Test public void testJavaToValueConversion() { try { assertNull(JavaToValueConverter.convertBoxedJavaType(null)); assertEquals(new StringValue("123Test"), JavaToValueConverter.convertBoxedJavaType("123Test")); assertEquals(new ByteValue((byte) 44), JavaToValueConverter.convertBoxedJavaType((byte) 44)); assertEquals(new ShortValue((short) 10000), JavaToValueConverter.convertBoxedJavaType((short) 10000)); assertEquals(new IntValue(3567564), JavaToValueConverter.convertBoxedJavaType(3567564)); assertEquals(new LongValue(767692734), JavaToValueConverter.convertBoxedJavaType(767692734L)); assertEquals(new FloatValue(17.5f), JavaToValueConverter.convertBoxedJavaType(17.5f)); assertEquals(new DoubleValue(3.1415926), JavaToValueConverter.convertBoxedJavaType(3.1415926)); assertEquals(new BooleanValue(true), JavaToValueConverter.convertBoxedJavaType(true)); assertEquals(new CharValue('@'), JavaToValueConverter.convertBoxedJavaType('@')); try { JavaToValueConverter.convertBoxedJavaType(new ArrayList<Object>()); fail("Accepted invalid type."); } catch (IllegalArgumentException e) { } } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }