1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.springframework.richclient.settings.support;
17
18 import javax.swing.JLabel;
19 import javax.swing.JSplitPane;
20
21 import org.springframework.richclient.settings.TransientSettings;
22
23 import junit.framework.TestCase;
24
25
26
27
28 public class SplitPaneMementoTests extends TestCase {
29 private JSplitPane splitPane;
30
31 private TransientSettings settings;
32
33 public void testConstructor() {
34 try {
35 new SplitPaneMemento(null);
36 fail("Should throw IllegalArgumentException");
37 } catch (IllegalArgumentException e) {
38
39 }
40
41 try {
42 splitPane.setName(null);
43 new SplitPaneMemento(splitPane, "");
44 fail("Should throw IllegalArgumentException: splitPane has no name");
45 } catch (Exception e) {
46
47 }
48
49 splitPane.setName("splitPane0");
50
51 SplitPaneMemento memento = new SplitPaneMemento(splitPane);
52 assertEquals(splitPane, memento.getSplitPane());
53 assertEquals("splitPane0", memento.getKey());
54
55 memento = new SplitPaneMemento(splitPane, "key");
56 assertEquals(splitPane, memento.getSplitPane());
57 assertEquals("key", memento.getKey());
58 }
59
60 public void testSaveState() {
61 SplitPaneMemento memento = new SplitPaneMemento(splitPane, "split");
62
63 splitPane.setDividerLocation(333);
64
65 memento.saveState(settings);
66
67 assertEquals(333, settings.getInt("split.dividerLocation"));
68 }
69
70 public void testRestoreState() {
71 SplitPaneMemento memento = new SplitPaneMemento(splitPane, "split");
72
73 splitPane.setDividerLocation(333);
74 assertEquals(333, splitPane.getDividerLocation());
75
76 settings.setInt("split.dividerLocation", 250);
77
78 memento.restoreState(settings);
79
80 assertEquals(250, splitPane.getDividerLocation());
81 }
82
83 protected void setUp() throws Exception {
84 splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
85 splitPane.setLeftComponent(new JLabel("Left"));
86 splitPane.setRightComponent(new JLabel("Right"));
87 splitPane.setSize(800, 600);
88
89 settings = new TransientSettings();
90 }
91 }