AttributeTypeConverter { public static Object convert(final Attribute attribute) { switch (attribute.getType()) { case BOOLEAN: return Boolean.valueOf(attribute.getValue()); case FLOAT: case DOUBLE: return Double.valueOf(attribute.getValue()); case INT: case LONG: return Long.valueOf(attribute.getValue()); case STRING: return attribute.getValue(); default: throw new JpaUnitException("Unsupported attribute type: " + attribute.getType()); } } private  AttributeTypeConverter(); static Object convert(final Attribute attribute);  }
@Test public void testConvertBoolean() { final DefaultAttribute<Boolean> attribute = new DefaultAttribute<>(true, AttributeType.BOOLEAN); final Object value = AttributeTypeConverter.convert(attribute); assertThat(value, instanceOf(Boolean.class)); assertThat(value, equalTo(Boolean.TRUE)); }
@Test public void testConvertFloat() { final DefaultAttribute<Float> attribute = new DefaultAttribute<>(10.0f, AttributeType.FLOAT); final Object value = AttributeTypeConverter.convert(attribute); assertThat(value, instanceOf(Double.class)); assertThat(value, equalTo(10.0)); }
@Test public void testConvertDouble() { final DefaultAttribute<Double> attribute = new DefaultAttribute<>(10.0, AttributeType.DOUBLE); final Object value = AttributeTypeConverter.convert(attribute); assertThat(value, instanceOf(Double.class)); assertThat(value, equalTo(10.0)); }
@Test public void testConvertInteger() { final DefaultAttribute<Integer> attribute = new DefaultAttribute<>(10, AttributeType.INT); final Object value = AttributeTypeConverter.convert(attribute); assertThat(value, instanceOf(Long.class)); assertThat(value, equalTo(10l)); }
@Test public void testConvertLong() { final DefaultAttribute<Long> attribute = new DefaultAttribute<>(10l, AttributeType.LONG); final Object value = AttributeTypeConverter.convert(attribute); assertThat(value, instanceOf(Long.class)); assertThat(value, equalTo(10l)); }
@Test public void testConvertString() { final DefaultAttribute<String> attribute = new DefaultAttribute<>("foo", AttributeType.STRING); final Object value = AttributeTypeConverter.convert(attribute); assertThat(value, instanceOf(String.class)); assertThat(value, equalTo("foo")); }