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 java.io.File; |
19 | |
20 | import javax.swing.JButton; |
21 | import javax.swing.JOptionPane; |
22 | import javax.swing.SwingUtilities; |
23 | |
24 | import junit.framework.TestCase; |
25 | import net.sf.jomic.tools.StandardConstants; |
26 | import net.sf.jomic.tools.TestTools; |
27 | import org.apache.commons.logging.Log; |
28 | import org.apache.commons.logging.LogFactory; |
29 | |
30 | /** |
31 | * TestCase for ConvertDialog. |
32 | * |
33 | * @author Thomas Aglassinger |
34 | */ |
35 | public class ConvertDialogTest extends TestCase implements StandardConstants |
36 | { |
37 | private ConvertDialog convertDialog; |
38 | private boolean dialogOpened; |
39 | private Log logger; |
40 | private TestTools testTools; |
41 | |
42 | protected void setUp() |
43 | throws Exception { |
44 | super.setUp(); |
45 | testTools = TestTools.instance(); |
46 | dialogOpened = false; |
47 | convertDialog = null; |
48 | logger = LogFactory.getLog(ConvertDialogTest.class); |
49 | } |
50 | |
51 | public void testConvertFrame() { |
52 | |
53 | SwingUtilities.invokeLater( |
54 | new Runnable() |
55 | { |
56 | public void run() { |
57 | convertDialog = new ConvertDialog(); |
58 | convertDialog.setModal(false); |
59 | convertDialog.pack(); |
60 | convertDialog.setVisible(true); |
61 | dialogOpened = true; |
62 | } |
63 | }); |
64 | while (!dialogOpened) { |
65 | try { |
66 | Thread.sleep(TICK); |
67 | } catch (InterruptedException interruption) { |
68 | logger.warn("ignoring interruption", interruption); |
69 | } |
70 | } |
71 | logger.debug("dialog opened"); |
72 | |
73 | JButton convertButton = convertDialog.getConvertButton(); |
74 | String targetDirName = testTools.getTestFileName(ConvertDialogTest.class, "testConvertFrame", null, null); |
75 | File targetDir = testTools.getTestOutputFile(targetDirName); |
76 | |
77 | assertFalse(convertButton.isEnabled()); |
78 | convertDialog.addComicToConvert(testTools.getTestComicFile()); |
79 | assertFalse(convertButton.isEnabled()); |
80 | convertDialog.setTargetDir(targetDir); |
81 | assertTrue(convertButton.isEnabled()); |
82 | |
83 | testTools.waitSomeTime(); |
84 | |
85 | if (convertButton.isEnabled()) { |
86 | convertButton.doClick(); |
87 | assertEquals(JOptionPane.OK_OPTION, convertDialog.getSelection()); |
88 | assertNotNull(convertDialog.getTargetDir()); |
89 | |
90 | File[] selectedFiles = convertDialog.getSelectedFiles(); |
91 | |
92 | assertNotNull(selectedFiles); |
93 | testTools.assertGreaterThan(selectedFiles.length, 0); |
94 | } |
95 | convertDialog.dispose(); |
96 | } |
97 | |
98 | protected void tearDown() |
99 | throws Exception { |
100 | super.tearDown(); |
101 | } |
102 | } |