Clover icon

jalviewX

  1. Project Clover database Wed Oct 31 2018 15:13:58 GMT
  2. Package jalview.gui

File JvSwingUtilsTest.java

 

Code metrics

0
22
6
1
122
61
6
0.27
3.67
6
1

Classes

Class Line # Actions
JvSwingUtilsTest 31 22 6 0
1.0100%
 

Contributing tests

This file is covered by 5 tests. .

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ 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.BeforeClass;
29    import org.testng.annotations.Test;
30   
 
31    public class JvSwingUtilsTest
32    {
33   
 
34  1 toggle @BeforeClass(alwaysRun = true)
35    public void setUpJvOptionPane()
36    {
37  1 JvOptionPane.setInteractiveMode(false);
38  1 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
39    }
40   
 
41  1 toggle @Test(groups = { "Functional" })
42    public void testGetScrollBarProportion()
43    {
44    /*
45    * orientation, value, extent (width), min, max
46    */
47  1 JScrollBar sb = new JScrollBar(0, 125, 50, 0, 450);
48   
49    /*
50    * operating range is 25 - 425 (400 wide) so value 125 is 100/400ths of this
51    * range
52    */
53  1 assertEquals(0.25f, JvSwingUtils.getScrollBarProportion(sb), 0.001f);
54    }
55   
 
56  1 toggle @Test(groups = { "Functional" })
57    public void testGetScrollValueForProportion()
58    {
59    /*
60    * orientation, value, extent (width), min, max
61    */
62  1 JScrollBar sb = new JScrollBar(0, 125, 50, 0, 450);
63   
64    /*
65    * operating range is 25 - 425 (400 wide) so value 125 is a quarter of this
66    * range
67    */
68  1 assertEquals(125, JvSwingUtils.getScrollValueForProportion(sb, 0.25f));
69    }
70   
71    /**
72    * Test wrap tooltip where it is less than or equal to 60 characters long - no
73    * wrap should be applied
74    */
 
75  1 toggle @Test(groups = { "Functional" })
76    public void testWrapTooltip_shortText()
77    {
78  1 String tip = "hello world";
79  1 assertEquals(tip, JvSwingUtils.wrapTooltip(false, tip));
80  1 assertEquals("<html>" + tip + "</html>",
81    JvSwingUtils.wrapTooltip(true, tip));
82   
83  1 tip = "012345678901234567890123456789012345678901234567890123456789"; // 60
84  1 assertEquals(tip, JvSwingUtils.wrapTooltip(false, tip));
85  1 assertEquals("<html>" + tip + "</html>",
86    JvSwingUtils.wrapTooltip(true, tip));
87   
88  1 tip = "0123456789012345678901234567890123456789012345678901234567890"; // 61
89  1 assertFalse(tip.equals(JvSwingUtils.wrapTooltip(false, tip)));
90  1 assertFalse(("<html>" + tip + "</html>").equals(JvSwingUtils
91    .wrapTooltip(true, tip)));
92    }
93   
94    /**
95    * Test wrap tooltip where it is more than one line (separated by &lt;br&gt;
96    * tags) of less than or equal to 60 characters long - no wrap should be
97    * applied
98    */
 
99  1 toggle @Test(groups = { "Functional" })
100    public void testWrapTooltip_multilineShortText()
101    {
102  1 String tip = "Now is the winter of our discontent<br>Made glorious summer by this sun of York";
103  1 assertEquals(tip, JvSwingUtils.wrapTooltip(false, tip));
104  1 assertEquals("<html>" + tip + "</html>",
105    JvSwingUtils.wrapTooltip(true, tip));
106    }
107   
108    /**
109    * Test wrap tooltip where it is more than 60 characters long - word break and
110    * word wrap styling should be applied
111    */
 
112  1 toggle @Test(groups = { "Functional" })
113    public void testWrapTooltip_longText()
114    {
115  1 String tip = "Now is the winter of our discontent made glorious summer by this sun of York";
116  1 String expected = "<style> div.ttip {width:350px;white-space:pre-wrap;padding:2px;overflow-wrap:break-word;}</style>"
117    + "<div class=\"ttip\">" + tip + " </div>";
118  1 assertEquals("<html>" + expected + "</html>",
119    JvSwingUtils.wrapTooltip(true, tip));
120  1 assertEquals(expected, JvSwingUtils.wrapTooltip(false, tip));
121    }
122    }