DatePickerCellEditor extends AbstractCellEditor implements
        TableCellEditor, TreeCellEditor { protected Date getValueAsDate(Object value) { if (isEmpty(value)) return null; if (value instanceof Date) { return (Date) value; } if (value instanceof Long) { return new Date((Long) value); } if (value instanceof String) { try { return dateFormat.parse((String) value); } catch (ParseException e) { handleParseException(e); } } if (value instanceof DefaultMutableTreeNode) { return getValueAsDate(((DefaultMutableTreeNode) value).getUserObject()); } if (value instanceof AbstractMutableTreeTableNode) { return getValueAsDate(((AbstractMutableTreeTableNode) value).getUserObject()); } return null; } DatePickerCellEditor();  DatePickerCellEditor(DateFormat dateFormat); @Override Date getCellEditorValue(); @Override boolean isCellEditable(EventObject anEvent); @Override boolean stopCellEditing(); void setClickCountToStart(int count); int getClickCountToStart(); @Override Component getTableCellEditorComponent(JTable table, Object value,
            boolean isSelected, int row, int column); @Override Component getTreeCellEditorComponent(JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row); DateFormat[] getFormats(); void setFormats(DateFormat... formats);  }
@Test public void testDateEditorValueAsDate() throws ParseException { DatePickerCellEditor editor = new DatePickerCellEditor(); Date input = new Date(); assertEquals("the input date must be unchanged", input, editor.getValueAsDate(input)); assertEquals("input as long must be same", input, editor.getValueAsDate(input.getTime())); String nonsenseString = "invalid"; assertNull("invalid string maps to null", editor.getValueAsDate(nonsenseString)); assertNull("empty String maps to null", editor.getValueAsDate("")); DefaultMutableTreeNode node = new DefaultMutableTreeNode(input); assertEquals("date must be user-object", input, editor.getValueAsDate(node)); DefaultMutableTreeTableNode tableNode = new DefaultMutableTreeTableNode(input); assertEquals("date must be user-object", input, editor.getValueAsDate(tableNode)); }