01: package org.uispec4j;
02:
03: import junit.framework.Assert;
04: import org.uispec4j.assertion.Assertion;
05: import org.uispec4j.utils.DateUtils;
06:
07: import javax.swing.JSpinner;
08: import javax.swing.SpinnerDateModel;
09: import javax.swing.SpinnerModel;
10:
11: /**
12: * Wrapper for JSpinner components implementing a SpinnerDateModel.
13: */
14: public class DateSpinner extends Spinner {
15: private SpinnerDateModel model;
16:
17: public DateSpinner(JSpinner jSpinner) throws ItemNotFoundException {
18: super (jSpinner);
19: SpinnerModel model = jSpinner.getModel();
20: if (!model.getClass().isAssignableFrom(SpinnerDateModel.class)) {
21: throw new ItemNotFoundException(
22: "Expected JSpinner using a SpinnerDateModel");
23: }
24: this .model = (SpinnerDateModel) model;
25: }
26:
27: /**
28: * Checks that the date spinner displays starts with the given value
29: * @see DateUtils to format the date as String
30: */
31: public Assertion startDateEquals(final String expectedStartDate) {
32: return new Assertion() {
33: public void check() throws Exception {
34: Assert.assertEquals(DateUtils
35: .getDate(expectedStartDate), model.getStart());
36: }
37: };
38: }
39:
40: /**
41: * Checks that the date spinner displays ends with the given value
42: * @see DateUtils to format the date as String
43: */
44: public Assertion endDateEquals(final String expectedEndDate) {
45: return new Assertion() {
46: public void check() throws Exception {
47: Assert.assertEquals(DateUtils.getDate(expectedEndDate),
48: model.getEnd());
49: }
50: };
51: }
52:
53: /**
54: * Checks that the date spinner computes previous and next value with the given value.
55: * {@link java.util.Calendar} constants
56: */
57: public Assertion calendarFieldsEquals(
58: final int expectedCalendarFields) {
59: return new Assertion() {
60: public void check() throws Exception {
61: Assert.assertEquals(expectedCalendarFields, model
62: .getCalendarField());
63: }
64: };
65: }
66: }
|