EditAttributeWidgetFactory { protected void initDatePickerByRuleAttribute(final DatePicker datePicker, final RuleAttribute ruleAttribute) { datePicker.addValueChangeHandler(event -> { final Date date = datePicker.getValue(); final String sDate = (date == null ? null : DATE_FORMATTER.format(datePicker.getValue())); ruleAttribute.setValue(sDate); }); datePicker.setFormat(DATE_FORMAT); datePicker.setValue(assertDateValue(ruleAttribute)); } EditAttributeWidgetFactory(final boolean isReadOnly); TextBox textBox(final RuleAttribute ruleAttribute, final String dataType); DatePicker datePicker(final RuleAttribute ruleAttribute, final boolean allowEmptyValues);  }
@Test public void testInitDatePickerByRuleAttribute() { final DatePicker datePicker = mock(DatePicker.class); final String attributeValue = "31-May-2018"; doReturn(attributeValue).when(ruleAttribute).getValue(); factory.initDatePickerByRuleAttribute(datePicker, ruleAttribute); verify(datePicker).setFormat(any()); verify(datePicker).setValue(notNull(Date.class)); }
@Test public void testDatePickerValueChangeHandler() { final DatePicker datePicker = mock(DatePicker.class); final Date datePickerValue = new Date(); doReturn(datePickerValue).when(datePicker).getValue(); factory.initDatePickerByRuleAttribute(datePicker, ruleAttribute); verify(datePicker).addValueChangeHandler(valueChangeHandlerArgumentCaptor.capture()); valueChangeHandlerArgumentCaptor.getValue().onValueChange(null); verify(ruleAttribute).setValue(anyString()); }
@Test public void testDatePickerValueChangeHandlerNullValue() { final DatePicker datePicker = mock(DatePicker.class); final Date datePickerValue = null; doReturn(datePickerValue).when(datePicker).getValue(); factory.initDatePickerByRuleAttribute(datePicker, ruleAttribute); verify(datePicker).addValueChangeHandler(valueChangeHandlerArgumentCaptor.capture()); valueChangeHandlerArgumentCaptor.getValue().onValueChange(null); verify(ruleAttribute).setValue(eq(null)); }