01: package org.uispec4j;
02:
03: import org.uispec4j.assertion.Assertion;
04: import org.uispec4j.utils.Utils;
05:
06: import javax.swing.JSpinner;
07: import javax.swing.SpinnerListModel;
08: import javax.swing.SpinnerModel;
09: import java.util.List;
10:
11: /**
12: * Wrapper for JSpinner components implementing a SpinnerListModel.
13: */
14: public class ListSpinner extends Spinner {
15: private SpinnerListModel model;
16:
17: public ListSpinner(JSpinner jSpinner) {
18: super (jSpinner);
19: SpinnerModel model = jSpinner.getModel();
20: if (!model.getClass().isAssignableFrom(SpinnerListModel.class)) {
21: throw new ItemNotFoundException(
22: "Expected JSpinner using a SpinnerListModel");
23: }
24: this .model = (SpinnerListModel) model;
25: }
26:
27: /**
28: * Checks the list spinner contents
29: */
30: public Assertion contentEquals(final Object[] expectedContents) {
31: return new Assertion() {
32: public void check() throws Exception {
33: List list = model.getList();
34: Utils.assertEquals(expectedContents, list
35: .toArray(new Object[list.size()]));
36: }
37: };
38: }
39: }
|