DisplayHelper { public static Object getDisplayValueForField(FieldDto field, Object value) { return getDisplayValueForField(field, value, null); } private  DisplayHelper(); static Object getDisplayValueForField(FieldDto field, Object value); static Object getDisplayValueForField(FieldDto field, Object value, Integer maxLength); static final DateTimeFormatter DTF; }
@Test public void shouldReturnNullForRegularFields() { FieldDto field = FieldTestHelper.fieldDto("strField", String.class); assertNull(DisplayHelper.getDisplayValueForField(field, "value")); field = FieldTestHelper.fieldDto("intField", Integer.class); assertNull(DisplayHelper.getDisplayValueForField(field, 14)); field = FieldTestHelper.fieldDto("dtField", DateTime.class); assertNull(DisplayHelper.getDisplayValueForField(field, DateUtil.now())); }
@Test public void shouldDisplayCbSingleSelectNoUserSupplied() { FieldDto field = FieldTestHelper.comboboxFieldDto(1L, "cb", "cb", false, false, DisplayTestEnum.valuesMap()); assertEquals("Monday", DisplayHelper.getDisplayValueForField(field, DisplayTestEnum.MONDAY)); field = FieldTestHelper.comboboxFieldDto(1L, "cb", "cb", false, false, DisplayTestEnum.valuesMap()); assertNull(DisplayHelper.getDisplayValueForField(field, null)); field = FieldTestHelper.comboboxFieldDto(1L, "cb", "cb", false, false, null); assertEquals(DisplayTestEnum.MONDAY, DisplayHelper.getDisplayValueForField(field, DisplayTestEnum.MONDAY)); }
@Test public void shouldDisplayCbSingleSelectUserSupplied() { FieldDto field = FieldTestHelper.comboboxFieldDto(1L, "cb", "cb", false, true, null); assertEquals("Something", DisplayHelper.getDisplayValueForField(field, "Something")); field = FieldTestHelper.comboboxFieldDto(1L, "cb", "cb", false, true, null); assertEquals(null, DisplayHelper.getDisplayValueForField(field, null)); }
@Test public void shouldDisplayCbMultiSelectNoUserSupplied() { FieldDto field = FieldTestHelper.comboboxFieldDto(1L, "cb", "cb", true, false, null); assertEquals(asList(DisplayTestEnum.MONDAY, DisplayTestEnum.TUESDAY), DisplayHelper.getDisplayValueForField(field, asList(DisplayTestEnum.MONDAY, DisplayTestEnum.TUESDAY))); field = FieldTestHelper.comboboxFieldDto(1L, "cb", "cb", true, false, DisplayTestEnum.valuesMap()); assertEquals(asList("Monday", "Tuesday"), DisplayHelper.getDisplayValueForField(field, asList(DisplayTestEnum.MONDAY, DisplayTestEnum.TUESDAY))); field = FieldTestHelper.comboboxFieldDto(1L, "cb", "cb", true, false, DisplayTestEnum.valuesMap()); assertNull(DisplayHelper.getDisplayValueForField(field, null)); field = FieldTestHelper.comboboxFieldDto(1L, "cb", "cb", true, false, DisplayTestEnum.valuesMap()); assertEquals(emptyList(), DisplayHelper.getDisplayValueForField(field, emptyList())); }
@Test public void shouldDisplayCbMultiSelectUserSupplied() { FieldDto field = FieldTestHelper.comboboxFieldDto(1L, "cb", "cb", true, true, null); assertEquals(asList("one", "two"), DisplayHelper.getDisplayValueForField(field, asList("one", "two"))); field = FieldTestHelper.comboboxFieldDto(1L, "cb", "cb", true, true, null); assertNull(DisplayHelper.getDisplayValueForField(field, null)); field = FieldTestHelper.comboboxFieldDto(1L, "cb", "cb", true, true, null); assertEquals(emptyList(), DisplayHelper.getDisplayValueForField(field, emptyList())); }