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.assertFalse; |
25 |
|
|
26 |
|
import java.awt.Component; |
27 |
|
import java.awt.Graphics2D; |
28 |
|
import java.awt.geom.AffineTransform; |
29 |
|
|
30 |
|
import javax.swing.JScrollBar; |
31 |
|
|
32 |
|
import org.testng.annotations.BeforeClass; |
33 |
|
import org.testng.annotations.Test; |
34 |
|
|
|
|
| 94.6% |
Uncovered Elements: 2 (37) |
Complexity: 8 |
Complexity Density: 0.29 |
|
35 |
|
public class JvSwingUtilsTest |
36 |
|
{ |
37 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
38 |
1 |
@BeforeClass(alwaysRun = true)... |
39 |
|
public void setUpJvOptionPane() |
40 |
|
{ |
41 |
1 |
JvOptionPane.setInteractiveMode(false); |
42 |
1 |
JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); |
43 |
|
} |
44 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
45 |
1 |
@Test(groups = { "Functional" })... |
46 |
|
public void testGetScrollBarProportion() |
47 |
|
{ |
48 |
|
|
49 |
|
|
50 |
|
|
51 |
1 |
JScrollBar sb = new JScrollBar(0, 125, 50, 0, 450); |
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
1 |
assertEquals(0.25f, JvSwingUtils.getScrollBarProportion(sb), 0.001f); |
58 |
|
} |
59 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
60 |
1 |
@Test(groups = { "Functional" })... |
61 |
|
public void testGetScrollValueForProportion() |
62 |
|
{ |
63 |
|
|
64 |
|
|
65 |
|
|
66 |
1 |
JScrollBar sb = new JScrollBar(0, 125, 50, 0, 450); |
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
|
72 |
1 |
assertEquals(125, JvSwingUtils.getScrollValueForProportion(sb, 0.25f)); |
73 |
|
} |
74 |
|
|
75 |
|
|
76 |
|
|
77 |
|
|
78 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
79 |
1 |
@Test(groups = { "Functional" })... |
80 |
|
public void testWrapTooltip_shortText() |
81 |
|
{ |
82 |
1 |
String tip = "hello world"; |
83 |
1 |
assertEquals(tip, JvSwingUtils.wrapTooltip(false, tip)); |
84 |
1 |
assertEquals("<html>" + tip + "</html>", |
85 |
|
JvSwingUtils.wrapTooltip(true, tip)); |
86 |
|
|
87 |
1 |
tip = "012345678901234567890123456789012345678901234567890123456789"; |
88 |
1 |
assertEquals(tip, JvSwingUtils.wrapTooltip(false, tip)); |
89 |
1 |
assertEquals("<html>" + tip + "</html>", |
90 |
|
JvSwingUtils.wrapTooltip(true, tip)); |
91 |
|
|
92 |
1 |
tip = "0123456789012345678901234567890123456789012345678901234567890"; |
93 |
1 |
assertFalse(tip.equals(JvSwingUtils.wrapTooltip(false, tip))); |
94 |
1 |
assertFalse(("<html>" + tip + "</html>") |
95 |
|
.equals(JvSwingUtils.wrapTooltip(true, tip))); |
96 |
|
} |
97 |
|
|
98 |
|
|
99 |
|
|
100 |
|
|
101 |
|
|
102 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
103 |
1 |
@Test(groups = { "Functional" })... |
104 |
|
public void testWrapTooltip_multilineShortText() |
105 |
|
{ |
106 |
1 |
String tip = "Now is the winter of our discontent<br>Made glorious summer by this sun of York"; |
107 |
1 |
assertEquals(tip, JvSwingUtils.wrapTooltip(false, tip)); |
108 |
1 |
assertEquals("<html>" + tip + "</html>", |
109 |
|
JvSwingUtils.wrapTooltip(true, tip)); |
110 |
|
} |
111 |
|
|
112 |
|
|
113 |
|
|
114 |
|
|
115 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
116 |
1 |
@Test(groups = { "Functional" })... |
117 |
|
public void testWrapTooltip_longText() |
118 |
|
{ |
119 |
1 |
String tip = "Now is the winter of our discontent made glorious summer by this sun of York"; |
120 |
1 |
String expected = "<style> div.ttip {width:350px;white-space:pre-wrap;padding:2px;overflow-wrap:break-word;}</style>" |
121 |
|
+ "<div class=\"ttip\">" + tip + " </div>"; |
122 |
1 |
assertEquals("<html>" + expected + "</html>", |
123 |
|
JvSwingUtils.wrapTooltip(true, tip)); |
124 |
1 |
assertEquals(expected, JvSwingUtils.wrapTooltip(false, tip)); |
125 |
|
} |
126 |
|
|
|
|
| 75% |
Uncovered Elements: 2 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
127 |
4 |
public static double getScaling(Component c)... |
128 |
|
{ |
129 |
4 |
Graphics2D g = (Graphics2D) c.getGraphics(); |
130 |
4 |
if (g == null) |
131 |
|
{ |
132 |
0 |
return 0.0; |
133 |
|
} |
134 |
4 |
AffineTransform t = g.getTransform(); |
135 |
4 |
double scaling = t.getScaleX(); |
136 |
4 |
return scaling; |
137 |
|
} |
138 |
|
|
139 |
|
} |