01: /*
02: * Copyright 2006 Sun Microsystems, Inc., 4150 Network Circle,
03: * Santa Clara, California 95054, U.S.A. All rights reserved.
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation; either
08: * version 2.1 of the License, or (at your option) any later version.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library; if not, write to the Free Software
17: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18: */
19: package org.jdesktop.swingx;
20:
21: import junit.framework.TestCase;
22:
23: import java.util.Calendar;
24: import java.util.Date;
25:
26: /**
27: * Created by IntelliJ IDEA.
28: * User: joutwate
29: * Date: Jun 1, 2006
30: * Time: 6:58:10 PM
31: * To change this template use File | Settings | File Templates.
32: */
33: public class JXDatePickerTest extends TestCase {
34: private Calendar cal;
35:
36: public void setUp() {
37: cal = Calendar.getInstance();
38: }
39:
40: public void teardown() {
41: }
42:
43: public void testDefaultConstructor() {
44: JXDatePicker datePicker = new JXDatePicker();
45: cal.setTimeInMillis(System.currentTimeMillis());
46: Date today = cleanupDate(cal);
47: assertTrue(today.equals(datePicker.getDate()));
48: assertTrue(today.getTime() == datePicker.getDateInMillis());
49: }
50:
51: public void testConstructor() {
52: cal.setTimeInMillis(System.currentTimeMillis());
53: cal.add(Calendar.DAY_OF_MONTH, 5);
54: Date expectedDate = cleanupDate(cal);
55: JXDatePicker datePicker = new JXDatePicker(cal
56: .getTimeInMillis());
57: assertTrue(expectedDate.equals(datePicker.getDate()));
58: assertTrue(expectedDate.getTime() == datePicker
59: .getDateInMillis());
60: }
61:
62: public void testNullSelection() {
63: JXDatePicker datePicker = new JXDatePicker();
64: datePicker.setDate(null);
65: assertTrue(null == datePicker.getDate());
66: assertTrue(-1 == datePicker.getDateInMillis());
67: }
68:
69: public void testSetDate() {
70: cal.setTimeInMillis(System.currentTimeMillis());
71: cal.add(Calendar.DAY_OF_MONTH, 5);
72: Date expectedDate = cleanupDate(cal);
73: JXDatePicker datePicker = new JXDatePicker();
74: datePicker.setDate(cal.getTime());
75: assertTrue(expectedDate.equals(datePicker.getDate()));
76: assertTrue(expectedDate.equals(datePicker.getEditor()
77: .getValue()));
78:
79: datePicker.setDate(null);
80: assertTrue(null == datePicker.getDate());
81: assertTrue(null == datePicker.getEditor().getValue());
82: }
83:
84: private Date cleanupDate(Calendar cal) {
85: cal.set(Calendar.HOUR_OF_DAY, 0);
86: cal.set(Calendar.MINUTE, 0);
87: cal.set(Calendar.SECOND, 0);
88: cal.set(Calendar.MILLISECOND, 0);
89: return cal.getTime();
90: }
91: }
|