1 | // Jomic - a viewer for comic book archives. |
2 | // Copyright (C) 2004-2011 Thomas Aglassinger |
3 | // |
4 | // This program is free software: you can redistribute it and/or modify |
5 | // it under the terms of the GNU General Public License as published by |
6 | // the Free Software Foundation, either version 3 of the License, or |
7 | // (at your option) any later version. |
8 | // |
9 | // This program is distributed in the hope that it will be useful, |
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | // GNU General Public License for more details. |
13 | // |
14 | // You should have received a copy of the GNU General Public License |
15 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | package net.sf.jomic.ui; |
17 | |
18 | import javax.swing.JFileChooser; |
19 | import javax.swing.SwingUtilities; |
20 | |
21 | import junit.extensions.abbot.ComponentTestFixture; |
22 | import net.sf.jomic.tools.TestTools; |
23 | |
24 | /** |
25 | * TestCase for OpenComicFileChooserAccessory. |
26 | * |
27 | * @author Thomas Aglassinger |
28 | */ |
29 | public class OpenComicFileChooserAccessoryTest extends ComponentTestFixture |
30 | { |
31 | private TestTools testTools; |
32 | |
33 | public void testAccessory() { |
34 | OpenComicFileChooserAccessory accessory = new OpenComicFileChooserAccessory(); |
35 | |
36 | showFrame(accessory); |
37 | testTools.waitSomeTime(); |
38 | } |
39 | |
40 | public void testFileChooser() { |
41 | final JFileChooser chooser = new JFileChooser(); |
42 | OpenComicFileChooserAccessory accessory = new OpenComicFileChooserAccessory(); |
43 | |
44 | chooser.setAccessory(accessory); |
45 | |
46 | Runnable chooserRunner = new ShowOpenDialogRunner(chooser); |
47 | |
48 | SwingUtilities.invokeLater(chooserRunner); |
49 | testTools.waitSomeTime(); |
50 | chooser.setVisible(false); |
51 | } |
52 | |
53 | protected void fixtureSetUp() |
54 | throws Exception { |
55 | try { |
56 | super.fixtureSetUp(); |
57 | } catch (Throwable error) { |
58 | throw new IllegalStateException("cannot setup fixture", error); |
59 | } |
60 | testTools = TestTools.instance(); |
61 | testTools.setupCache(); |
62 | } |
63 | |
64 | protected void fixtureTearDown() |
65 | throws Exception { |
66 | testTools = null; |
67 | try { |
68 | super.fixtureTearDown(); |
69 | } catch (Throwable error) { |
70 | throw new IllegalStateException("cannot tear down fixture", error); |
71 | } |
72 | |
73 | } |
74 | |
75 | /** |
76 | * Runnable to show a JFileChooser. |
77 | * |
78 | * @author Thomas Aglassinger |
79 | */ |
80 | private final class ShowOpenDialogRunner implements Runnable |
81 | { |
82 | private final JFileChooser chooser; |
83 | |
84 | private ShowOpenDialogRunner(JFileChooser newChooser) { |
85 | super(); |
86 | chooser = newChooser; |
87 | } |
88 | |
89 | public void run() { |
90 | chooser.showOpenDialog(null); |
91 | } |
92 | } |
93 | } |