2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import static org.testng.AssertJUnit.assertEquals;
24 import static org.testng.AssertJUnit.assertTrue;
26 import java.awt.Component;
27 import java.awt.FlowLayout;
28 import java.awt.GridLayout;
30 import javax.swing.JLabel;
31 import javax.swing.JPanel;
33 import org.testng.Assert;
34 import org.testng.annotations.BeforeClass;
35 import org.testng.annotations.Test;
37 public class ProgressBarTest
40 @BeforeClass(alwaysRun = true)
41 public void setUpJvOptionPane()
43 JvOptionPane.setInteractiveMode(false);
44 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
47 private JPanel statusPanel;
49 private JLabel statusBar;
51 @Test(groups = { "Functional" })
52 public void testConstructor_prematureInstantiation()
56 new ProgressBar(null, null);
57 Assert.fail("Expected exception");
58 } catch (NullPointerException e)
64 @Test(groups = { "Functional" })
65 public void testConstructor_wrongLayout()
67 statusPanel = new JPanel();
68 statusPanel.setLayout(new FlowLayout());
71 new ProgressBar(statusPanel, null);
72 Assert.fail("expected exception");
73 } catch (IllegalArgumentException e)
79 @Test(groups = { "Functional" })
80 public void testSetProgressBar()
82 statusPanel = new JPanel();
83 GridLayout layout = new GridLayout(1, 1);
84 statusPanel.setLayout(layout);
85 statusBar = new JLabel("nothing");
86 ProgressBar pb = new ProgressBar(statusPanel, statusBar);
91 pb.setProgressBar("hello", 1L);
92 verifyProgress(layout, new String[] { "hello" });
97 pb.setProgressBar("world", 2L);
98 verifyProgress(layout, new String[] { "hello", "world" });
101 * Remove 'hello' with no status bar update
103 pb.setProgressBar(null, 1L);
104 verifyProgress(layout, new String[] { "world" });
105 assertEquals("nothing", statusBar.getText());
108 * Remove 'world' with status bar update
110 pb.setProgressBar("goodbye", 2L);
111 verifyProgress(layout, new String[] {});
112 assertEquals("goodbye", statusBar.getText());
116 * Verify the right number of progress bars containing the expected messages
122 private void verifyProgress(GridLayout layout, String[] msgs)
124 int msgCount = msgs.length;
125 assertEquals(1 + msgCount, layout.getRows());
126 assertEquals(msgCount, statusPanel.getComponentCount());
128 for (Component c : statusPanel.getComponents())
130 assertTrue(c instanceof JPanel);
131 assertTrue(((JPanel) c).getComponent(0) instanceof JLabel);
132 assertEquals(msgs[i++],
133 ((JLabel) ((JPanel) c).getComponent(0)).getText());