3 import static org.testng.AssertJUnit.assertEquals;
4 import static org.testng.AssertJUnit.assertFalse;
6 import javax.swing.JScrollBar;
8 import org.testng.annotations.Test;
10 public class JvSwingUtilsTest
13 @Test(groups ={ "Functional" })
14 public void testGetScrollBarProportion()
17 * orientation, value, extent (width), min, max
19 JScrollBar sb = new JScrollBar(0, 125, 50, 0, 450);
22 * operating range is 25 - 425 (400 wide) so value 125 is 100/400ths of this
25 assertEquals(0.25f, JvSwingUtils.getScrollBarProportion(sb), 0.001f);
28 @Test(groups = { "Functional" })
29 public void testGetScrollValueForProportion()
32 * orientation, value, extent (width), min, max
34 JScrollBar sb = new JScrollBar(0, 125, 50, 0, 450);
37 * operating range is 25 - 425 (400 wide) so value 125 is a quarter of this
40 assertEquals(125, JvSwingUtils.getScrollValueForProportion(sb, 0.25f));
44 * Test wrap tooltip where it is less than or equal to 60 characters long - no
45 * wrap should be applied
47 @Test(groups = { "Functional" })
48 public void testWrapTooltip_shortText()
50 String tip = "hello world";
51 assertEquals(tip, JvSwingUtils.wrapTooltip(false, tip));
52 assertEquals("<html>" + tip + "</html>",
53 JvSwingUtils.wrapTooltip(true, tip));
55 tip = "012345678901234567890123456789012345678901234567890123456789"; // 60
56 assertEquals(tip, JvSwingUtils.wrapTooltip(false, tip));
57 assertEquals("<html>" + tip + "</html>",
58 JvSwingUtils.wrapTooltip(true, tip));
60 tip = "0123456789012345678901234567890123456789012345678901234567890"; // 61
61 assertFalse(tip.equals(JvSwingUtils.wrapTooltip(false, tip)));
62 assertFalse(("<html>" + tip + "</html>").equals(JvSwingUtils
63 .wrapTooltip(true, tip)));
67 * Test wrap tooltip where it is more than one line (separated by <br>
68 * tags) of less than or equal to 60 characters long - no wrap should be
71 @Test(groups = { "Functional" })
72 public void testWrapTooltip_multilineShortText()
74 String tip = "Now is the winter of our discontent<br>Made glorious summer by this sun of York";
75 assertEquals(tip, JvSwingUtils.wrapTooltip(false, tip));
76 assertEquals("<html>" + tip + "</html>",
77 JvSwingUtils.wrapTooltip(true, tip));
81 * Test wrap tooltip where it is more than 60 characters long - word break and
82 * word wrap styling should be applied
84 @Test(groups = { "Functional" })
85 public void testWrapTooltip_longText()
87 String tip = "Now is the winter of our discontent made glorious summer by this sun of York";
88 String expected = "<style> p.ttip {width: 350; text-align: justify; word-wrap: break-word;}</style><p class=\"ttip\">"
90 assertEquals("<html>" + expected + "</html>",
91 JvSwingUtils.wrapTooltip(true, tip));
92 assertEquals(expected, JvSwingUtils.wrapTooltip(false, tip));