FormatUtils { public static String formatPropertyValue(EntityModelFactory entityModelFactory, AttributeModel model, Object value, String separator) { return formatPropertyValue(null, entityModelFactory, model, value, VaadinUtils.getLocale(), separator); } private  FormatUtils(); static String extractAndFormat(Grid<T> grid, AttributeModel am, Object obj); static String formatEntity(EntityModel<?> entityModel, Object value); static String formatEntityCollection(EntityModelFactory entityModelFactory, AttributeModel attributeModel, Object collection,
            String separator); static String formatPropertyValue(EntityModelFactory entityModelFactory, AttributeModel model, Object value, String separator); @SuppressWarnings("unchecked") static String formatPropertyValue(Grid<T> grid, EntityModelFactory entityModelFactory, AttributeModel model, Object value,
            Locale locale, String separator);  }
@Test public void testFormatPropertyValue() { EntityModel<TestEntity> model = factory.getModel(TestEntity.class); assertEquals("Bob", FormatUtils.formatPropertyValue(null, factory, model.getAttributeModel("name"), "Bob", LOCALE, ", ")); assertEquals("true", FormatUtils.formatPropertyValue(null, factory, model.getAttributeModel("someBoolean"), true, LOCALE, ", ")); assertEquals("false", FormatUtils.formatPropertyValue(null, factory, model.getAttributeModel("someBoolean"), false, LOCALE, ", ")); assertEquals("On", FormatUtils.formatPropertyValue(null, factory, model.getAttributeModel("someBoolean2"), true, LOCALE, ", ")); assertEquals("Off", FormatUtils.formatPropertyValue(null, factory, model.getAttributeModel("someBoolean2"), false, LOCALE, ", ")); assertEquals("Value A", FormatUtils.formatPropertyValue(null, factory, model.getAttributeModel("someEnum"), TestEnum.A, LOCALE, ", ")); assertEquals("12,40", FormatUtils.formatPropertyValue(null, factory, model.getAttributeModel("discount"), BigDecimal.valueOf(12.4), LOCALE, ", ")); assertEquals("1.042,40", FormatUtils.formatPropertyValue(null, factory, model.getAttributeModel("discount"), BigDecimal.valueOf(1042.4), LOCALE, ", ")); assertEquals("1.042,40%", FormatUtils.formatPropertyValue(null, factory, model.getAttributeModel("rate"), BigDecimal.valueOf(1042.4), LOCALE, ", ")); assertEquals("1,000.40", FormatUtils.formatPropertyValue(null, factory, model.getAttributeModel("discount"), BigDecimal.valueOf(1000.4), Locale.US, ", ")); assertEquals("12/10/2015", FormatUtils.formatPropertyValue(null, factory, model.getAttributeModel("birthDate"), DateUtils.createLocalDate("12102015"), LOCALE, ", ")); assertEquals("2015-42", FormatUtils.formatPropertyValue(null, factory, model.getAttributeModel("birthWeek"), DateUtils.createLocalDate("12102015"), LOCALE, ", ")); assertEquals("1.234", FormatUtils.formatPropertyValue(null, factory, model.getAttributeModel("someInt"), 1234, LOCALE, ", ")); assertEquals("1.234", FormatUtils.formatPropertyValue(null, factory, model.getAttributeModel("age"), 1234L, LOCALE, ", ")); }
@Test public void testFormatMasterEntity() { EntityModel<Entity2> model = factory.getModel(Entity2.class); AttributeModel at = model.getAttributeModel("entity1"); assertNotNull(at); Entity1 e1 = new Entity1(); e1.setId(1); e1.setName("some name"); Entity2 e2 = new Entity2(); e2.setId(2); e2.setSize(2); e2.setEntity1(e1); String result = FormatUtils.formatPropertyValue(null, factory, model.getAttributeModel("entity1"), e1, LOCALE, ", "); assertEquals("some name", result); }