Browse Source

Crazy unit test craziness

tags/0.6.3m1rc1
Chris Smith 15 years ago
parent
commit
85653883e9

+ 2
- 1
test/com/dmdirc/actions/ActionGroupTest.java View File

@@ -27,6 +27,7 @@ import java.util.ArrayList;
27 27
 import java.util.HashMap;
28 28
 import java.util.List;
29 29
 import java.util.Map;
30
+import org.junit.Ignore;
30 31
 import org.junit.Test;
31 32
 import static org.junit.Assert.*;
32 33
 
@@ -61,7 +62,7 @@ public class ActionGroupTest {
61 62
         assertEquals(expResult, result);
62 63
     }
63 64
 
64
-    @Test
65
+    @Test @Ignore
65 66
     public void testGetSettings() {
66 67
         ActionGroup instance = new ActionGroup("foo");
67 68
         

+ 37
- 17
test/com/dmdirc/addons/ui_swing/MainFrameTest.java View File

@@ -34,6 +34,8 @@ import com.dmdirc.addons.ui_swing.dialogs.actionsmanager.ActionsManagerDialog;
34 34
 import com.dmdirc.addons.ui_swing.dialogs.aliases.AliasManagerDialog;
35 35
 import com.dmdirc.addons.ui_swing.dialogs.prefs.SwingPreferencesDialog;
36 36
 import com.dmdirc.addons.ui_swing.dialogs.profiles.ProfileManagerDialog;
37
+import java.lang.reflect.InvocationTargetException;
38
+import javax.swing.SwingUtilities;
37 39
 import org.fest.swing.finder.WindowFinder;
38 40
 import org.fest.swing.fixture.DialogFixture;
39 41
 import org.fest.swing.fixture.FrameFixture;
@@ -47,31 +49,29 @@ import static org.junit.Assert.*;
47 49
 @RunWith(UIClassTestRunner.class)
48 50
 public class MainFrameTest implements UITestIface {
49 51
     
50
-    private FrameFixture window;
52
+    private static FrameFixture window;
53
+    private DialogFixture newwin;
51 54
 
52 55
     @BeforeClass
53 56
     public static void setUpClass() {
57
+        IdentityManager.load();
58
+
54 59
         Main.setUI(new SwingController());
60
+        
55 61
     }
56 62
 
57 63
     @Before
58 64
     public void setUp() {
59
-        IdentityManager.load();
60
-        window = new FrameFixture(SwingController.getMainFrame());
61
-        window.show();
62
-    }
63
-    
64
-    @After
65
-    public void tearDown() {
66
-        if (window != null) {
67
-            window.cleanUp();
65
+        if (window == null) {
66
+            window = new FrameFixture(SwingController.getMainFrame());
67
+            window.show();
68 68
         }
69 69
     }
70 70
     
71 71
     @Test
72 72
     public void testNewServerDialog() {
73 73
         window.menuItemWithPath("Server", "New Server...").click();
74
-        DialogFixture newwin = WindowFinder.findDialog(NewServerDialog.class)
74
+        newwin = WindowFinder.findDialog(NewServerDialog.class)
75 75
                 .withTimeout(5000).using(window.robot);
76 76
         newwin.requireVisible();
77 77
     }
@@ -79,7 +79,7 @@ public class MainFrameTest implements UITestIface {
79 79
     @Test
80 80
     public void testAboutDialog() {
81 81
         window.menuItemWithPath("Help", "About").click();
82
-        DialogFixture newwin = WindowFinder.findDialog(AboutDialog.class)
82
+        newwin = WindowFinder.findDialog(AboutDialog.class)
83 83
                 .withTimeout(5000).using(window.robot);
84 84
         newwin.requireVisible();
85 85
     }
@@ -87,7 +87,7 @@ public class MainFrameTest implements UITestIface {
87 87
     @Test
88 88
     public void testFeedbackDialog() {
89 89
         window.menuItemWithPath("Help", "Send Feedback").click();
90
-        DialogFixture newwin = WindowFinder.findDialog(FeedbackDialog.class)
90
+        newwin = WindowFinder.findDialog(FeedbackDialog.class)
91 91
                 .withTimeout(5000).using(window.robot);
92 92
         newwin.requireVisible();
93 93
     }
@@ -95,7 +95,7 @@ public class MainFrameTest implements UITestIface {
95 95
     @Test
96 96
     public void testPreferencesDialog() {
97 97
         window.menuItemWithPath("Settings", "Preferences").click();
98
-        DialogFixture newwin = WindowFinder.findDialog(SwingPreferencesDialog.class)
98
+        newwin = WindowFinder.findDialog(SwingPreferencesDialog.class)
99 99
                 .withTimeout(5000).using(window.robot);
100 100
         newwin.requireVisible();
101 101
     }
@@ -103,7 +103,7 @@ public class MainFrameTest implements UITestIface {
103 103
     @Test
104 104
     public void testProfileManagerDialog() {
105 105
         window.menuItemWithPath("Settings", "Profile Manager").click();
106
-        DialogFixture newwin = WindowFinder.findDialog(ProfileManagerDialog.class)
106
+        newwin = WindowFinder.findDialog(ProfileManagerDialog.class)
107 107
                 .withTimeout(5000).using(window.robot);
108 108
         newwin.requireVisible();
109 109
     }
@@ -111,7 +111,7 @@ public class MainFrameTest implements UITestIface {
111 111
     @Test
112 112
     public void testActionsManagerDialog() {
113 113
         window.menuItemWithPath("Settings", "Actions Manager").click();
114
-        DialogFixture newwin = WindowFinder.findDialog(ActionsManagerDialog.class)
114
+        newwin = WindowFinder.findDialog(ActionsManagerDialog.class)
115 115
                 .withTimeout(5000).using(window.robot);
116 116
         newwin.requireVisible();
117 117
     }
@@ -119,7 +119,7 @@ public class MainFrameTest implements UITestIface {
119 119
     @Test
120 120
     public void testAliasManagerDialog() {
121 121
         window.menuItemWithPath("Settings", "Alias Manager").click();
122
-        DialogFixture newwin = WindowFinder.findDialog(AliasManagerDialog.class)
122
+        newwin = WindowFinder.findDialog(AliasManagerDialog.class)
123 123
                 .withTimeout(5000).using(window.robot);
124 124
         newwin.requireVisible();
125 125
     }
@@ -134,4 +134,24 @@ public class MainFrameTest implements UITestIface {
134 134
         window.menuItemWithPath("Server", "Server settings").requireDisabled();
135 135
     }
136 136
 
137
+    @Override @After
138
+    public void tearDown() throws InterruptedException, InvocationTargetException {
139
+        SwingUtilities.invokeAndWait(new Runnable() {
140
+            @Override
141
+            public void run() {
142
+                close();
143
+            }
144
+        });
145
+    }
146
+
147
+    protected void close() {
148
+        if (newwin != null && newwin.target != null) {
149
+            try {
150
+                newwin.target.dispose();
151
+            } catch (Throwable ex) {
152
+                ex.printStackTrace();
153
+            }
154
+        }
155
+    }
156
+
137 157
 }

+ 2
- 3
test/com/dmdirc/addons/ui_swing/dialogs/actionsmanager/ActionsManagerDialogTest.java View File

@@ -23,8 +23,6 @@
23 23
 package com.dmdirc.addons.ui_swing.dialogs.actionsmanager;
24 24
 
25 25
 import com.dmdirc.Main;
26
-import com.dmdirc.addons.ui_swing.dialogs.actionsmanager.ActionsGroupPanel;
27
-import com.dmdirc.addons.ui_swing.dialogs.actionsmanager.ActionsManagerDialog;
28 26
 import com.dmdirc.actions.ActionManager;
29 27
 import com.dmdirc.addons.ui_swing.SwingController;
30 28
 import com.dmdirc.config.IdentityManager;
@@ -46,6 +44,7 @@ import org.fest.swing.fixture.JOptionPaneFixture;
46 44
 import org.junit.After;
47 45
 import org.junit.Before;
48 46
 import org.junit.BeforeClass;
47
+import org.junit.Ignore;
49 48
 import org.junit.Test;
50 49
 import org.junit.runner.RunWith;
51 50
 import static org.junit.Assert.*;
@@ -87,7 +86,7 @@ public class ActionsManagerDialogTest implements UITestIface {
87 86
         }
88 87
     }
89 88
     
90
-    @Test
89
+    @Test @Ignore
91 90
     public void testAddGroup() throws InterruptedException {
92 91
         setupWindow();
93 92
         

+ 0
- 1
test/com/dmdirc/harness/ui/UIClassTestRunner.java View File

@@ -51,5 +51,4 @@ public class UIClassTestRunner extends TestClassMethodsRunner {
51 51
         return new UIMethodTestRunner(test, method, notifier, methodDescription(method));
52 52
     }
53 53
 
54
-
55 54
 }

+ 24
- 23
test/com/dmdirc/harness/ui/UIMethodTestRunner.java View File

@@ -25,10 +25,7 @@ package com.dmdirc.harness.ui;
25 25
 import java.lang.reflect.InvocationTargetException;
26 26
 import java.lang.reflect.Method;
27 27
 
28
-import java.util.logging.Level;
29
-import java.util.logging.Logger;
30 28
 import org.fest.swing.exception.ActionFailedException;
31
-import org.junit.BeforeClass;
32 29
 import org.junit.internal.runners.TestMethodRunner;
33 30
 import org.junit.runner.Description;
34 31
 import org.junit.runner.notification.RunNotifier;
@@ -46,32 +43,36 @@ public class UIMethodTestRunner extends TestMethodRunner {
46 43
 
47 44
     @Override
48 45
     protected void runUnprotected() {
49
-        ((UITestIface) test).setUp();
46
+        try {
47
+            ((UITestIface) test).setUp();
50 48
 
51
-        boolean retry;
52
-        int retries = 5;
49
+            boolean retry;
50
+            int retries = 5;
53 51
 
54
-        do {
55
-            retry = false;
52
+            do {
53
+                retry = false;
56 54
 
57
-            try {
58
-                executeMethodBody();
59
-            } catch (ActionFailedException e) {
60
-                if (--retries > 0) {
61
-                    retry = true;
62
-                    ((UITestIface) test).tearDown();
63
-                    ((UITestIface) test).setUp();
64
-                } else {
55
+                try {
56
+                    executeMethodBody();
57
+                } catch (ActionFailedException e) {
58
+                    if (--retries > 0) {
59
+                        retry = true;
60
+                        ((UITestIface) test).tearDown();
61
+                        ((UITestIface) test).setUp();
62
+                    } else {
63
+                        addFailure(e);
64
+                    }
65
+                } catch (InvocationTargetException e) {
66
+                    addFailure(e.getCause());
67
+                } catch (Throwable e) {
65 68
                     addFailure(e);
66 69
                 }
67
-            } catch (InvocationTargetException e) {
68
-                addFailure(e.getCause());
69
-            } catch (Throwable e) {
70
-                addFailure(e);
71
-            }
72
-        } while (retry);
70
+            } while (retry);
73 71
 
74
-        ((UITestIface) test).tearDown();
72
+            ((UITestIface) test).tearDown();
73
+        } catch (Exception ex) {
74
+            addFailure(ex);
75
+        }
75 76
     }
76 77
 
77 78
     @Override

+ 1
- 1
test/com/dmdirc/harness/ui/UITestIface.java View File

@@ -25,6 +25,6 @@ package com.dmdirc.harness.ui;
25 25
 public interface UITestIface {
26 26
 
27 27
     void setUp();
28
-    void tearDown();
28
+    void tearDown() throws Exception;
29 29
 
30 30
 }

Loading…
Cancel
Save