2a7f1319756946e65106c982ab742a88805d2678
[jalview.git] / test / jalview / gui / JvSwingUtilsTest.java
1 package jalview.gui;
2
3 import static org.testng.AssertJUnit.assertEquals;
4 import static org.testng.AssertJUnit.assertFalse;
5
6 import javax.swing.JScrollBar;
7
8 import org.testng.annotations.Test;
9
10 public class JvSwingUtilsTest
11 {
12
13   @Test(groups = { "Functional" })
14   public void testGetScrollBarProportion()
15   {
16     /*
17      * orientation, value, extent (width), min, max
18      */
19     JScrollBar sb = new JScrollBar(0, 125, 50, 0, 450);
20
21     /*
22      * operating range is 25 - 425 (400 wide) so value 125 is 100/400ths of this
23      * range
24      */
25     assertEquals(0.25f, JvSwingUtils.getScrollBarProportion(sb), 0.001f);
26   }
27
28   @Test(groups = { "Functional" })
29   public void testGetScrollValueForProportion()
30   {
31     /*
32      * orientation, value, extent (width), min, max
33      */
34     JScrollBar sb = new JScrollBar(0, 125, 50, 0, 450);
35
36     /*
37      * operating range is 25 - 425 (400 wide) so value 125 is a quarter of this
38      * range
39      */
40     assertEquals(125, JvSwingUtils.getScrollValueForProportion(sb, 0.25f));
41   }
42
43   /**
44    * Test wrap tooltip where it is less than or equal to 60 characters long - no
45    * wrap should be applied
46    */
47   @Test(groups = { "Functional" })
48   public void testWrapTooltip_shortText()
49   {
50     String tip = "hello world";
51     assertEquals(tip, JvSwingUtils.wrapTooltip(false, tip));
52     assertEquals("<html>" + tip + "</html>",
53             JvSwingUtils.wrapTooltip(true, tip));
54
55     tip = "012345678901234567890123456789012345678901234567890123456789"; // 60
56     assertEquals(tip, JvSwingUtils.wrapTooltip(false, tip));
57     assertEquals("<html>" + tip + "</html>",
58             JvSwingUtils.wrapTooltip(true, tip));
59
60     tip = "0123456789012345678901234567890123456789012345678901234567890"; // 61
61     assertFalse(tip.equals(JvSwingUtils.wrapTooltip(false, tip)));
62     assertFalse(("<html>" + tip + "</html>").equals(JvSwingUtils
63             .wrapTooltip(true, tip)));
64   }
65
66   /**
67    * Test wrap tooltip where it is more than one line (separated by &lt;br&gt;
68    * tags) of less than or equal to 60 characters long - no wrap should be
69    * applied
70    */
71   @Test(groups = { "Functional" })
72   public void testWrapTooltip_multilineShortText()
73   {
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));
78   }
79
80   /**
81    * Test wrap tooltip where it is more than 60 characters long - word break and
82    * word wrap styling should be applied
83    */
84   @Test(groups = { "Functional" })
85   public void testWrapTooltip_longText()
86   {
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\">"
89             + tip + "</p>";
90     assertEquals("<html>" + expected + "</html>",
91             JvSwingUtils.wrapTooltip(true, tip));
92     assertEquals(expected, JvSwingUtils.wrapTooltip(false, tip));
93   }
94 }