Переглянути джерело

Style fixes and new unit test

Change-Id: Icfb27b2dcfa9cd9ca122881c912878862cef3c90
Reviewed-on: http://gerrit.dmdirc.com/830
Automatic-Compile: DMDirc Local Commits <dmdirc@googlemail.com>
Reviewed-by: Gregory Holmes <greg@dmdirc.com>
tags/0.6.3
Chris Smith 14 роки тому
джерело
коміт
654dd23e4a

BIN
lib/uispec4j-2.1.jar Переглянути файл


+ 5
- 5
src/com/dmdirc/addons/ui_swing/dialogs/actionsmanager/ActionGroupInformationPanel.java Переглянути файл

@@ -109,11 +109,7 @@ public final class ActionGroupInformationPanel extends JPanel {
109 109
     public void setActionGroup(final ActionGroup group) {
110 110
         this.group = group;
111 111
 
112
-        if (group == null || group.getDescription() == null) {
113
-            infoLabel.setText("");
114
-            author.setText("");
115
-            version.setText("");
116
-        } else {
112
+        if (shouldDisplay()) {
117 113
             infoLabel.setText(group.getDescription());
118 114
             author.setText(group.getAuthor());
119 115
             version.setText(Integer.toString(group.getVersion()));
@@ -122,6 +118,10 @@ public final class ActionGroupInformationPanel extends JPanel {
122 118
             version.setVisible(group.getVersion() != -1);
123 119
             authorLabel.setVisible(group.getAuthor() != null);
124 120
             versionLabel.setVisible(group.getVersion() != -1);
121
+        } else {
122
+            infoLabel.setText("");
123
+            author.setText("");
124
+            version.setText("");
125 125
         }
126 126
     }
127 127
 

+ 8
- 6
src/com/dmdirc/addons/ui_swing/dialogs/actionsmanager/ActionGroupSettingsPanel.java Переглянути файл

@@ -116,13 +116,15 @@ public final class ActionGroupSettingsPanel extends JPanel implements ActionList
116 116
             label.setToolTipText(setting.getTitle());
117 117
             final JComponent component =
118 118
                     PrefsComponentFactory.getComponent(setting);
119
+
119 120
             if (component instanceof DurationDisplay) {
120
-            ((DurationDisplay) component).setWindow(window);
121
-        } else if (component instanceof ColourChooser) {
122
-            ((ColourChooser) component).setWindow(window);
123
-        } else if (component instanceof OptionalColourChooser) {
124
-            ((OptionalColourChooser) component).setWindow(window);
125
-        }
121
+                ((DurationDisplay) component).setWindow(window);
122
+            } else if (component instanceof ColourChooser) {
123
+                ((ColourChooser) component).setWindow(window);
124
+            } else if (component instanceof OptionalColourChooser) {
125
+                ((OptionalColourChooser) component).setWindow(window);
126
+            }
127
+
126 128
             final JButton button = new SettingsRevertButton(setting);
127 129
             settingMap.put(button, setting);
128 130
             button.addActionListener(this);

+ 101
- 0
test/com/dmdirc/addons/ui_swing/dialogs/actionsmanager/ActionGroupInformationPanelTest.java Переглянути файл

@@ -0,0 +1,101 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.ui_swing.dialogs.actionsmanager;
24
+
25
+import com.dmdirc.actions.ActionGroup;
26
+import org.junit.Test;
27
+import org.uispec4j.Panel;
28
+import org.uispec4j.UISpecTestCase;
29
+import static org.junit.Assert.*;
30
+import static org.mockito.Mockito.*;
31
+
32
+public class ActionGroupInformationPanelTest extends UISpecTestCase {
33
+
34
+    @Test
35
+    public void testShouldDisplayNull() {
36
+        assertFalse(new ActionGroupInformationPanel(null).shouldDisplay());
37
+    }
38
+
39
+    @Test
40
+    public void testShouldDisplayNoDescription() {
41
+        assertFalse(new ActionGroupInformationPanel(mock(ActionGroup.class)).shouldDisplay());
42
+    }
43
+
44
+    @Test
45
+    public void testShouldDisplay() {
46
+        final ActionGroup group = mock(ActionGroup.class);
47
+        when(group.getDescription()).thenReturn("description");
48
+
49
+        assertTrue(new ActionGroupInformationPanel(group).shouldDisplay());
50
+    }
51
+
52
+    @Test
53
+    public void testAllLabels() {
54
+        final ActionGroup group = mock(ActionGroup.class);
55
+        when(group.getDescription()).thenReturn("description");
56
+        when(group.getVersion()).thenReturn(17);
57
+        when(group.getAuthor()).thenReturn("foo <bar@baz>");
58
+        
59
+        final Panel panel = new Panel(new ActionGroupInformationPanel(group));
60
+
61
+        assertEquals("<panel>"
62
+                + "<textBox text=\"description\"/>"
63
+                + "<textBox text=\"Author: \"/>"
64
+                + "<textBox text=\"foo &lt;bar@baz&gt;\"/>"
65
+                + "<textBox text=\"Version: \"/>"
66
+                + "<textBox text=\"17\"/>"
67
+                + "</panel>", panel.getDescription().replace("\n", ""));
68
+    }
69
+
70
+    @Test
71
+    public void testNoAuthor() {
72
+        final ActionGroup group = mock(ActionGroup.class);
73
+        when(group.getDescription()).thenReturn("description");
74
+        when(group.getVersion()).thenReturn(17);
75
+
76
+        final Panel panel = new Panel(new ActionGroupInformationPanel(group));
77
+
78
+        assertEquals("<panel>"
79
+                + "<textBox text=\"description\"/>"
80
+                + "<textBox text=\"Version: \"/>"
81
+                + "<textBox text=\"17\"/>"
82
+                + "</panel>", panel.getDescription().replace("\n", ""));
83
+    }
84
+
85
+    @Test
86
+    public void testNoVersion() {
87
+        final ActionGroup group = mock(ActionGroup.class);
88
+        when(group.getDescription()).thenReturn("description");
89
+        when(group.getVersion()).thenReturn(-1);
90
+        when(group.getAuthor()).thenReturn("foo <bar@baz>");
91
+
92
+        final Panel panel = new Panel(new ActionGroupInformationPanel(group));
93
+
94
+        assertEquals("<panel>"
95
+                + "<textBox text=\"description\"/>"
96
+                + "<textBox text=\"Author: \"/>"
97
+                + "<textBox text=\"foo &lt;bar@baz&gt;\"/>"
98
+                + "</panel>", panel.getDescription().replace("\n", ""));
99
+    }
100
+
101
+}

Завантаження…
Відмінити
Зберегти