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.Test;
36 public class ProgressBarTest
39 private JPanel statusPanel;
41 private JLabel statusBar;
43 @Test(groups = { "Functional" })
44 public void testConstructor_prematureInstantiation()
48 new ProgressBar(null, null);
49 Assert.fail("Expected exception");
50 } catch (NullPointerException e)
56 @Test(groups = { "Functional" })
57 public void testConstructor_wrongLayout()
59 statusPanel = new JPanel();
60 statusPanel.setLayout(new FlowLayout());
63 new ProgressBar(statusPanel, null);
64 Assert.fail("expected exception");
65 } catch (IllegalArgumentException e)
71 @Test(groups = { "Functional" })
72 public void testSetProgressBar()
74 statusPanel = new JPanel();
75 GridLayout layout = new GridLayout(1, 1);
76 statusPanel.setLayout(layout);
77 statusBar = new JLabel("nothing");
78 ProgressBar pb = new ProgressBar(statusPanel, statusBar);
83 pb.setProgressBar("hello", 1L);
84 verifyProgress(layout, new String[] { "hello" });
89 pb.setProgressBar("world", 2L);
90 verifyProgress(layout, new String[] { "hello", "world" });
93 * Remove 'hello' with no status bar update
95 pb.setProgressBar(null, 1L);
96 verifyProgress(layout, new String[] { "world" });
97 assertEquals("nothing", statusBar.getText());
100 * Remove 'world' with status bar update
102 pb.setProgressBar("goodbye", 2L);
103 verifyProgress(layout, new String[] {});
104 assertEquals("goodbye", statusBar.getText());
108 * Verify the right number of progress bars containing the expected messages
114 private void verifyProgress(GridLayout layout, String[] msgs)
116 int msgCount = msgs.length;
117 assertEquals(1 + msgCount, layout.getRows());
118 assertEquals(msgCount, statusPanel.getComponentCount());
120 for (Component c : statusPanel.getComponents())
122 assertTrue(c instanceof JPanel);
123 assertTrue(((JPanel) c).getComponent(0) instanceof JLabel);
124 assertEquals(msgs[i++],
125 ((JLabel) ((JPanel) c).getComponent(0)).getText());