01: package org.uispec4j;
02:
03: import org.uispec4j.utils.DateUtils;
04:
05: import javax.swing.JSpinner;
06: import javax.swing.SpinnerDateModel;
07: import javax.swing.SpinnerModel;
08: import java.util.Calendar;
09: import java.util.Date;
10:
11: public class DateSpinnerTest extends SpinnerTestCase {
12: private DateSpinner dateSpinner;
13:
14: protected void setUp() throws Exception {
15: super .setUp();
16: dateSpinner = (DateSpinner) spinner;
17: }
18:
19: protected SpinnerModel createSpinnerModel() throws Exception {
20: Date startDate = DateUtils.getDate("1964.11.23 19:55");
21: Date currentDate = DateUtils.getDate("1974.11.23 19:55");
22: Date endDate = DateUtils.getDate("1984.11.23 19:55");
23: return new SpinnerDateModel(currentDate, startDate, endDate,
24: Calendar.MONTH);
25: }
26:
27: protected Spinner createSpinner(JSpinner jSpinner) {
28: return new DateSpinner(jSpinner);
29: }
30:
31: public void testStartAndEndDate() throws Exception {
32: assertTrue(dateSpinner.startDateEquals("1964.11.23 19:55"));
33: assertTrue(dateSpinner.endDateEquals("1984.11.23 19:55"));
34:
35: assertFalse(dateSpinner.startDateEquals("1964.11.23 19:56"));
36: assertFalse(dateSpinner.endDateEquals("1964.11.23 19:56"));
37: }
38:
39: public void testCalendarFielsEquals() throws Exception {
40: assertTrue(dateSpinner.calendarFieldsEquals(Calendar.MONTH));
41: assertFalse(dateSpinner.calendarFieldsEquals(Calendar.YEAR));
42: }
43:
44: public void testUsingDateSpinnerWithOtherModelThanSpinnerDateModelThrowsAnException()
45: throws Exception {
46: try {
47: new DateSpinner(new JSpinner());
48: fail();
49: } catch (ItemNotFoundException e) {
50: assertEquals("Expected JSpinner using a SpinnerDateModel",
51: e.getMessage());
52: }
53: }
54: }
|