### Question:
JXDatePicker extends JComponent { public void setDate(Date date) { try { date = getUI().getSelectableDate(date); } catch (PropertyVetoException e) { return; } Date old = getDate(); this.date = date; firePropertyChange("date", old, getDate()); } JXDatePicker();  JXDatePicker(Date selected);  JXDatePicker(Locale locale);  JXDatePicker(Date selection, Locale locale); void setDate(Date date); Date getDate(); DatePickerUI getUI(); void setUI(DatePickerUI ui); @Override void updateUI(); @Override String getUIClassID(); void setFormats(String... formats); void setFormats(DateFormat... formats); DateFormat[] getFormats(); JXMonthView getMonthView(); void setMonthView(JXMonthView monthView); TimeZone getTimeZone(); void setTimeZone(TimeZone tz); Date getLinkDay(); void setLinkDay(Date linkDay, String linkFormatString); void setLinkDay(Date linkDay); JPanel getLinkPanel(); void setLinkPanel(JPanel linkPanel); JFormattedTextField getEditor(); void setEditor(JFormattedTextField editor); @Override void setComponentOrientation(ComponentOrientation orientation); boolean isEditValid(); void commitEdit(); void cancelEdit(); void setEditable(boolean value); boolean isEditable(); @Override Font getFont(); @Override void setFont(final Font font); void setLightWeightPopupEnabled(boolean aFlag); boolean isLightWeightPopupEnabled(); @Override int getBaseline(int width, int height); void addActionListener(ActionListener l); void removeActionListener(ActionListener l); @Override @SuppressWarnings("unchecked") T[] getListeners(Class<T> listenerType); void addPopupMenuListener(PopupMenuListener l); void removePopupMenuListener(PopupMenuListener l); PopupMenuListener[] getPopupMenuListeners(); static final String uiClassID; static final String EDITOR; static final String MONTH_VIEW; static final String LINK_PANEL; static final String COMMIT_KEY; static final String CANCEL_KEY; static final String HOME_NAVIGATE_KEY; static final String HOME_COMMIT_KEY; }### Answer:
@Test public void testSetDateDoesNotChangeOriginal() { JXDatePicker picker = new JXDatePicker(); Date date = calendar.getTime(); Date copy = new Date(date.getTime()); picker.setDate(date); assertEquals(copy, date); }
@Test public void testDateProperty() { JXDatePicker picker = new JXDatePicker(); Date date = XTestUtils.getStartOfToday(5); PropertyChangeReport report = new PropertyChangeReport(); picker.addPropertyChangeListener("date", report); picker.setDate(date); TestUtils.assertPropertyChangeEvent(report, "date", null, date); }
@Test public void testSynchAllOnDateModified() { JXDatePicker picker = new JXDatePicker(); Date date = XTestUtils.getStartOfToday(5); picker.setDate(date); assertSynchAll(picker, date); }
@Test public void testPrefSizeEmptyEditor() { JXDatePicker picker = new JXDatePicker(new Date()); Dimension withValue = picker.getPreferredSize(); picker.setDate(null); assertEquals("pref width must be same null value", withValue.width, picker.getPreferredSize().width); }
@Test public void testSetDate() { calendar.setTimeInMillis(System.currentTimeMillis()); calendar.add(Calendar.DAY_OF_MONTH, 5); Date expectedDate = cleanupDate(calendar); JXDatePicker datePicker = new JXDatePicker(); datePicker.setDate(calendar.getTime()); assertTrue(expectedDate.equals(datePicker.getDate())); assertTrue(expectedDate.equals(datePicker.getEditor().getValue())); datePicker.setDate(null); assertTrue(null == datePicker.getDate()); assertTrue(null == datePicker.getEditor().getValue()); }