| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
|
| 21 |
|
package jalview.gui; |
| 22 |
|
|
| 23 |
|
import static org.testng.AssertJUnit.assertEquals; |
| 24 |
|
import static org.testng.AssertJUnit.assertTrue; |
| 25 |
|
|
| 26 |
|
import java.awt.Component; |
| 27 |
|
import java.awt.FlowLayout; |
| 28 |
|
import java.awt.GridLayout; |
| 29 |
|
|
| 30 |
|
import javax.swing.JLabel; |
| 31 |
|
import javax.swing.JPanel; |
| 32 |
|
import javax.swing.SwingUtilities; |
| 33 |
|
|
| 34 |
|
import org.testng.Assert; |
| 35 |
|
import org.testng.annotations.BeforeClass; |
| 36 |
|
import org.testng.annotations.Test; |
| 37 |
|
|
| |
|
| 92.9% |
Uncovered Elements: 3 (42) |
Complexity: 9 |
Complexity Density: 0.25 |
|
| 38 |
|
public class ProgressBarTest |
| 39 |
|
{ |
| 40 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 41 |
1 |
@BeforeClass(alwaysRun = true)... |
| 42 |
|
public void setUpJvOptionPane() |
| 43 |
|
{ |
| 44 |
1 |
JvOptionPane.setInteractiveMode(false); |
| 45 |
1 |
JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); |
| 46 |
|
} |
| 47 |
|
|
| 48 |
|
private JPanel statusPanel; |
| 49 |
|
|
| 50 |
|
private JLabel statusBar; |
| 51 |
|
|
| |
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
1PASS
|
|
| 52 |
1 |
@Test(groups = { "Functional" })... |
| 53 |
|
public void testConstructor_prematureInstantiation() |
| 54 |
|
{ |
| 55 |
1 |
try |
| 56 |
|
{ |
| 57 |
1 |
new ProgressBar(null, null); |
| 58 |
0 |
Assert.fail("Expected exception"); |
| 59 |
|
} catch (NullPointerException e) |
| 60 |
|
{ |
| 61 |
|
|
| 62 |
|
} |
| 63 |
|
} |
| 64 |
|
|
| |
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 2 |
Complexity Density: 0.4 |
1PASS
|
|
| 65 |
1 |
@Test(groups = { "Functional" })... |
| 66 |
|
public void testConstructor_wrongLayout() |
| 67 |
|
{ |
| 68 |
1 |
statusPanel = new JPanel(); |
| 69 |
1 |
statusPanel.setLayout(new FlowLayout()); |
| 70 |
1 |
try |
| 71 |
|
{ |
| 72 |
1 |
new ProgressBar(statusPanel, null); |
| 73 |
0 |
Assert.fail("expected exception"); |
| 74 |
|
} catch (IllegalArgumentException e) |
| 75 |
|
{ |
| 76 |
|
|
| 77 |
|
} |
| 78 |
|
} |
| 79 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 1 |
Complexity Density: 0.07 |
1PASS
|
|
| 80 |
1 |
@Test(groups = { "Functional" })... |
| 81 |
|
public void testSetProgressBar() |
| 82 |
|
{ |
| 83 |
1 |
statusPanel = new JPanel(); |
| 84 |
1 |
GridLayout layout = new GridLayout(1, 1); |
| 85 |
1 |
statusPanel.setLayout(layout); |
| 86 |
1 |
statusBar = new JLabel("nothing"); |
| 87 |
1 |
ProgressBar pb = new ProgressBar(statusPanel, statusBar); |
| 88 |
|
|
| 89 |
|
|
| 90 |
|
|
| 91 |
|
|
| 92 |
1 |
pb.setProgressBar("hello", 1L); |
| 93 |
1 |
verifyProgress(layout, new String[] { "hello" }); |
| 94 |
|
|
| 95 |
|
|
| 96 |
|
|
| 97 |
|
|
| 98 |
1 |
pb.setProgressBar("world", 2L); |
| 99 |
1 |
verifyProgress(layout, new String[] { "hello", "world" }); |
| 100 |
|
|
| 101 |
|
|
| 102 |
|
|
| 103 |
|
|
| 104 |
1 |
pb.setProgressBar(null, 1L); |
| 105 |
1 |
verifyProgress(layout, new String[] { "world" }); |
| 106 |
1 |
assertEquals("nothing", statusBar.getText()); |
| 107 |
|
|
| 108 |
|
|
| 109 |
|
|
| 110 |
|
|
| 111 |
1 |
pb.setProgressBar("goodbye", 2L); |
| 112 |
1 |
verifyProgress(layout, new String[] {}); |
| 113 |
1 |
assertEquals("goodbye", statusBar.getText()); |
| 114 |
|
} |
| 115 |
|
|
| 116 |
|
|
| 117 |
|
|
| 118 |
|
|
| 119 |
|
|
| 120 |
|
@param |
| 121 |
|
@param |
| 122 |
|
|
| |
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 123 |
4 |
private void verifyProgress(final GridLayout layout, final String[] msgs)... |
| 124 |
|
{ |
| 125 |
4 |
try |
| 126 |
|
{ |
| 127 |
4 |
SwingUtilities.invokeAndWait(new Runnable() |
| 128 |
|
{ |
| |
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
|
| 129 |
4 |
@Override... |
| 130 |
|
public void run() |
| 131 |
|
{ |
| 132 |
4 |
int msgCount = msgs.length; |
| 133 |
4 |
assertEquals(1 + msgCount, layout.getRows()); |
| 134 |
4 |
assertEquals(msgCount, statusPanel.getComponentCount()); |
| 135 |
4 |
int i = 0; |
| 136 |
4 |
for (Component c : statusPanel.getComponents()) |
| 137 |
|
{ |
| 138 |
4 |
assertTrue(c instanceof JPanel); |
| 139 |
4 |
assertTrue(((JPanel) c).getComponent(0) instanceof JLabel); |
| 140 |
4 |
assertEquals(msgs[i++], |
| 141 |
|
((JLabel) ((JPanel) c).getComponent(0)).getText()); |
| 142 |
|
} |
| 143 |
|
} |
| 144 |
|
}); |
| 145 |
|
} catch (Exception e) |
| 146 |
|
{ |
| 147 |
0 |
throw new AssertionError( |
| 148 |
|
"Unexpected exception waiting for progress bar validation", |
| 149 |
|
e); |
| 150 |
|
} |
| 151 |
|
} |
| 152 |
|
} |