01: package org.uispec4j;
02:
03: import junit.framework.AssertionFailedError;
04: import org.uispec4j.utils.AssertionFailureNotDetectedError;
05: import org.uispec4j.xml.XmlAssert;
06:
07: import javax.swing.JSpinner;
08: import javax.swing.SpinnerModel;
09:
10: public abstract class SpinnerTestCase extends UIComponentTestCase {
11: protected JSpinner jSpinner;
12: protected Spinner spinner;
13:
14: protected abstract SpinnerModel createSpinnerModel()
15: throws Exception;
16:
17: protected abstract Spinner createSpinner(JSpinner jSpinner);
18:
19: protected void setUp() throws Exception {
20: init();
21: }
22:
23: public final void testGetComponentTypeName() throws Exception {
24: assertEquals("spinner", spinner.getDescriptionTypeName());
25: }
26:
27: public final void testGetDescription() throws Exception {
28: XmlAssert.assertEquivalent("<spinner name='marcel'>"
29: + " <button/>" + " <button/>" + " <textBox/>"
30: + "</spinner>", spinner.getDescription());
31: }
32:
33: protected final UIComponent createComponent() {
34: return spinner;
35: }
36:
37: protected final void checkPreviousValueFails(
38: String wrongPreviousValue) {
39: try {
40: assertTrue(spinner.previousValueEquals(wrongPreviousValue));
41: throw new AssertionFailureNotDetectedError();
42: } catch (AssertionFailedError e) {
43: assertEquals("No previous value from the start", e
44: .getMessage());
45: }
46: }
47:
48: protected final void checkNextValueFails(String wrongNextValue) {
49: try {
50: assertTrue(spinner.nextValueEquals(wrongNextValue));
51: throw new AssertionFailureNotDetectedError();
52: } catch (AssertionFailedError e) {
53: assertEquals("No previous value from the end", e
54: .getMessage());
55: }
56: }
57:
58: protected final void init() throws Exception {
59: jSpinner = new JSpinner(createSpinnerModel());
60: jSpinner.setName("marcel");
61: spinner = createSpinner(jSpinner);
62: }
63:
64: public void testFactory() throws Exception {
65: checkFactory(jSpinner, Spinner.class);
66: }
67: }
|