2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
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.
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.
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.
23 import static org.testng.AssertJUnit.assertEquals;
24 import static org.testng.AssertJUnit.assertFalse;
26 import javax.swing.JScrollBar;
28 import org.testng.annotations.BeforeClass;
29 import org.testng.annotations.Test;
31 public class JvSwingUtilsTest
34 @BeforeClass(alwaysRun = true)
35 public void setUpJvOptionPane()
37 JvOptionPane.setInteractiveMode(false);
38 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
41 @Test(groups = { "Functional" })
42 public void testGetScrollBarProportion()
45 * orientation, value, extent (width), min, max
47 JScrollBar sb = new JScrollBar(0, 125, 50, 0, 450);
50 * operating range is 25 - 425 (400 wide) so value 125 is 100/400ths of this
53 assertEquals(0.25f, JvSwingUtils.getScrollBarProportion(sb), 0.001f);
56 @Test(groups = { "Functional" })
57 public void testGetScrollValueForProportion()
60 * orientation, value, extent (width), min, max
62 JScrollBar sb = new JScrollBar(0, 125, 50, 0, 450);
65 * operating range is 25 - 425 (400 wide) so value 125 is a quarter of this
68 assertEquals(125, JvSwingUtils.getScrollValueForProportion(sb, 0.25f));
72 * Test wrap tooltip where it is less than or equal to 60 characters long - no
73 * wrap should be applied
75 @Test(groups = { "Functional" })
76 public void testWrapTooltip_shortText()
78 String tip = "hello world";
79 assertEquals(tip, JvSwingUtils.wrapTooltip(false, tip));
80 assertEquals("<html>" + tip + "</html>",
81 JvSwingUtils.wrapTooltip(true, tip));
83 tip = "012345678901234567890123456789012345678901234567890123456789"; // 60
84 assertEquals(tip, JvSwingUtils.wrapTooltip(false, tip));
85 assertEquals("<html>" + tip + "</html>",
86 JvSwingUtils.wrapTooltip(true, tip));
88 tip = "0123456789012345678901234567890123456789012345678901234567890"; // 61
89 // n/a -- message is too long for "false"
91 // assertFalse(tip.equals(JvSwingUtils.wrapTooltip(false, tip)));
94 assertFalse(("<html>" + tip + "</html>").equals(JvSwingUtils
95 .wrapTooltip(true, tip)));
99 * Test wrap tooltip where it is more than one line (separated by <br>
100 * tags) of less than or equal to 60 characters long - no wrap should be
103 @Test(groups = { "Functional" })
104 public void testWrapTooltip_multilineShortText()
106 String tip = "Now is the winter of our discontent<br>Made glorious summer by this sun of York";
107 String tip2 = "Now is the winter of our discontent<br/>Made glorious summer by this sun of York";
109 // BH not applicable in Jalview; "false" is only for when no <br> and only for short j2s2Discover messages
111 // String s = JvSwingUtils.wrapTooltip(false, tip);
112 // System.out.println("<html>" + tip + "</html>");
113 // assertEquals(tip, s);
116 s = JvSwingUtils.wrapTooltip(true, tip);
117 System.out.println(s);
118 assertEquals("<html>" + tip + "</html>", s);
119 s = JvSwingUtils.wrapTooltip(true, tip2);
120 System.out.println(s);
121 assertEquals("<html>" + tip + "</html>", s);
125 * Test wrap tooltip where it is more than 60 characters long - word break and
126 * word wrap styling should be applied
128 @Test(groups = { "Functional" })
129 public void testWrapTooltip_longText()
131 // BH should work in Java and JavaScript
132 String tip = "Now is the winter of our discontent made glorious summer by this sun of York";
133 String expected = JvSwingUtils.HTML_PREFIX + tip + "</div></html>";
134 String s = JvSwingUtils.wrapTooltip(true, tip);
135 assertEquals(expected, s);
136 // BH not applicable in Jalview; "false" is only for when no <br> and only for short j2s2Discover messages
137 // s = JvSwingUtils.wrapTooltip(false, tip);
138 // assertEquals(expected, s);