JavaToValueConverter { public static Object convertValueType(Value value) { if (value == null) { return null; } if (value instanceof StringValue) { return ((StringValue) value).getValue(); } else if (value instanceof IntValue) { return ((IntValue) value).getValue(); } else if (value instanceof LongValue) { return ((LongValue) value).getValue(); } else if (value instanceof DoubleValue) { return ((DoubleValue) value).getValue(); } else if (value instanceof FloatValue) { return ((FloatValue) value).getValue(); } else if (value instanceof BooleanValue) { return ((BooleanValue) value).getValue(); } else if (value instanceof ByteValue) { return ((ByteValue) value).getValue(); } else if (value instanceof ShortValue) { return ((ShortValue) value).getValue(); } else if (value instanceof CharValue) { return ((CharValue) value).getValue(); } else { throw new IllegalArgumentException("Object is no primitive Java type."); } }  static Value convertBoxedJavaType(Object boxed); static Object convertValueType(Value value);  }
@Test public void testValueToJavaConversion() { try { assertNull(JavaToValueConverter.convertValueType(null)); assertEquals("123Test", JavaToValueConverter.convertValueType(new StringValue("123Test"))); assertEquals((byte) 44, JavaToValueConverter.convertValueType(new ByteValue((byte) 44))); assertEquals((short) 10000, JavaToValueConverter.convertValueType(new ShortValue((short) 10000))); assertEquals(3567564, JavaToValueConverter.convertValueType(new IntValue(3567564))); assertEquals(767692734L, JavaToValueConverter.convertValueType(new LongValue(767692734))); assertEquals(17.5f, JavaToValueConverter.convertValueType(new FloatValue(17.5f))); assertEquals(3.1415926, JavaToValueConverter.convertValueType(new DoubleValue(3.1415926))); assertEquals(true, JavaToValueConverter.convertValueType(new BooleanValue(true))); assertEquals('@', JavaToValueConverter.convertValueType(new CharValue('@'))); try { JavaToValueConverter.convertValueType(new MyValue()); fail("Accepted invalid type."); } catch (IllegalArgumentException e) { } } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }