JAL-1645 Version-Rel Version 2.9 Year-Rel 2015 Licensing glob
[jalview.git] / test / jalview / gui / JvSwingUtilsTest.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9)
3  * Copyright (C) 2015 The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
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.
11  *  
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.
16  * 
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.
20  */
21 package jalview.gui;
22
23 import static org.testng.AssertJUnit.assertEquals;
24 import static org.testng.AssertJUnit.assertFalse;
25
26 import javax.swing.JScrollBar;
27
28 import org.testng.annotations.Test;
29
30 public class JvSwingUtilsTest
31 {
32
33   @Test(groups = { "Functional" })
34   public void testGetScrollBarProportion()
35   {
36     /*
37      * orientation, value, extent (width), min, max
38      */
39     JScrollBar sb = new JScrollBar(0, 125, 50, 0, 450);
40
41     /*
42      * operating range is 25 - 425 (400 wide) so value 125 is 100/400ths of this
43      * range
44      */
45     assertEquals(0.25f, JvSwingUtils.getScrollBarProportion(sb), 0.001f);
46   }
47
48   @Test(groups = { "Functional" })
49   public void testGetScrollValueForProportion()
50   {
51     /*
52      * orientation, value, extent (width), min, max
53      */
54     JScrollBar sb = new JScrollBar(0, 125, 50, 0, 450);
55
56     /*
57      * operating range is 25 - 425 (400 wide) so value 125 is a quarter of this
58      * range
59      */
60     assertEquals(125, JvSwingUtils.getScrollValueForProportion(sb, 0.25f));
61   }
62
63   /**
64    * Test wrap tooltip where it is less than or equal to 60 characters long - no
65    * wrap should be applied
66    */
67   @Test(groups = { "Functional" })
68   public void testWrapTooltip_shortText()
69   {
70     String tip = "hello world";
71     assertEquals(tip, JvSwingUtils.wrapTooltip(false, tip));
72     assertEquals("<html>" + tip + "</html>",
73             JvSwingUtils.wrapTooltip(true, tip));
74
75     tip = "012345678901234567890123456789012345678901234567890123456789"; // 60
76     assertEquals(tip, JvSwingUtils.wrapTooltip(false, tip));
77     assertEquals("<html>" + tip + "</html>",
78             JvSwingUtils.wrapTooltip(true, tip));
79
80     tip = "0123456789012345678901234567890123456789012345678901234567890"; // 61
81     assertFalse(tip.equals(JvSwingUtils.wrapTooltip(false, tip)));
82     assertFalse(("<html>" + tip + "</html>").equals(JvSwingUtils
83             .wrapTooltip(true, tip)));
84   }
85
86   /**
87    * Test wrap tooltip where it is more than one line (separated by &lt;br&gt;
88    * tags) of less than or equal to 60 characters long - no wrap should be
89    * applied
90    */
91   @Test(groups = { "Functional" })
92   public void testWrapTooltip_multilineShortText()
93   {
94     String tip = "Now is the winter of our discontent<br>Made glorious summer by this sun of York";
95     assertEquals(tip, JvSwingUtils.wrapTooltip(false, tip));
96     assertEquals("<html>" + tip + "</html>",
97             JvSwingUtils.wrapTooltip(true, tip));
98   }
99
100   /**
101    * Test wrap tooltip where it is more than 60 characters long - word break and
102    * word wrap styling should be applied
103    */
104   @Test(groups = { "Functional" })
105   public void testWrapTooltip_longText()
106   {
107     String tip = "Now is the winter of our discontent made glorious summer by this sun of York";
108     String expected = "<style> p.ttip {width: 350; text-align: justify; word-wrap: break-word;}</style><p class=\"ttip\">"
109             + tip + "</p>";
110     assertEquals("<html>" + expected + "</html>",
111             JvSwingUtils.wrapTooltip(true, tip));
112     assertEquals(expected, JvSwingUtils.wrapTooltip(false, tip));
113   }
114 }