1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.util; |
22 |
|
|
23 |
|
import static org.testng.AssertJUnit.assertEquals; |
24 |
|
import static org.testng.AssertJUnit.assertNull; |
25 |
|
import static org.testng.AssertJUnit.assertSame; |
26 |
|
|
27 |
|
import jalview.gui.JvOptionPane; |
28 |
|
|
29 |
|
import java.awt.Color; |
30 |
|
|
31 |
|
import org.testng.annotations.BeforeClass; |
32 |
|
import org.testng.annotations.Test; |
33 |
|
|
|
|
| 0% |
Uncovered Elements: 88 (88) |
Complexity: 9 |
Complexity Density: 0.11 |
|
34 |
|
public class ColorUtilsTest |
35 |
|
{ |
36 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
37 |
0 |
@BeforeClass(alwaysRun = true)... |
38 |
|
public void setUpJvOptionPane() |
39 |
|
{ |
40 |
0 |
JvOptionPane.setInteractiveMode(false); |
41 |
0 |
JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); |
42 |
|
} |
43 |
|
|
44 |
|
Color paleColour = new Color(97, 203, 111); |
45 |
|
|
46 |
|
Color midColour = new Color(135, 57, 41); |
47 |
|
|
48 |
|
Color darkColour = new Color(11, 30, 50); |
49 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
4-
|
|
50 |
0 |
@Test(groups = { "Functional" })... |
51 |
|
public void testDarkerThan() |
52 |
|
{ |
53 |
0 |
assertEquals("Wrong darker shade", new Color(32, 69, 37), |
54 |
|
ColorUtils.darkerThan(paleColour)); |
55 |
0 |
assertEquals("Wrong darker shade", new Color(45, 18, 13), |
56 |
|
ColorUtils.darkerThan(midColour)); |
57 |
0 |
assertEquals("Wrong darker shade", new Color(2, 9, 16), |
58 |
|
ColorUtils.darkerThan(darkColour)); |
59 |
0 |
assertNull(ColorUtils.darkerThan(null)); |
60 |
|
} |
61 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
4-
|
|
62 |
0 |
@Test(groups = { "Functional" })... |
63 |
|
public void testBrighterThan() |
64 |
|
{ |
65 |
0 |
assertEquals("Wrong brighter shade", new Color(255, 255, 255), |
66 |
|
ColorUtils.brighterThan(paleColour)); |
67 |
0 |
assertEquals("Wrong brighter shade", new Color(255, 164, 117), |
68 |
|
ColorUtils.brighterThan(midColour)); |
69 |
0 |
assertEquals("Wrong brighter shade", new Color(30, 85, 144), |
70 |
|
ColorUtils.brighterThan(darkColour)); |
71 |
0 |
assertNull(ColorUtils.brighterThan(null)); |
72 |
|
} |
73 |
|
|
74 |
|
|
75 |
|
@see |
76 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
4-
|
|
77 |
0 |
@Test(groups = { "Functional" })... |
78 |
|
public void testToTkCode() |
79 |
|
{ |
80 |
0 |
assertEquals("#fffafa", ColorUtils.toTkCode(new Color(255, 250, 250))); |
81 |
0 |
assertEquals("#e6e6fa", ColorUtils.toTkCode(new Color(230, 230, 250))); |
82 |
0 |
assertEquals("#dda0dd", ColorUtils.toTkCode(new Color(221, 160, 221))); |
83 |
0 |
assertEquals("#800080", ColorUtils.toTkCode(new Color(128, 0, 128))); |
84 |
0 |
assertEquals("#00ff00", ColorUtils.toTkCode(new Color(0, 255, 0))); |
85 |
|
} |
86 |
|
|
|
|
| 0% |
Uncovered Elements: 20 (20) |
Complexity: 1 |
Complexity Density: 0.05 |
4-
|
|
87 |
0 |
@Test(groups = { "Functional" })... |
88 |
|
public void testGetGraduatedColour() |
89 |
|
{ |
90 |
0 |
Color minColour = new Color(100, 100, 100); |
91 |
0 |
Color maxColour = new Color(180, 200, 220); |
92 |
|
|
93 |
|
|
94 |
|
|
95 |
|
|
96 |
0 |
Color col = ColorUtils.getGraduatedColour(20f, 10f, minColour, 30f, |
97 |
|
maxColour); |
98 |
0 |
assertEquals(140, col.getRed()); |
99 |
0 |
assertEquals(150, col.getGreen()); |
100 |
0 |
assertEquals(160, col.getBlue()); |
101 |
|
|
102 |
|
|
103 |
|
|
104 |
|
|
105 |
0 |
col = ColorUtils.getGraduatedColour(30f, 10f, minColour, 40f, |
106 |
|
maxColour); |
107 |
0 |
assertEquals(153, col.getRed()); |
108 |
|
|
109 |
0 |
assertEquals(167, col.getGreen()); |
110 |
0 |
assertEquals(180, col.getBlue()); |
111 |
|
|
112 |
|
|
113 |
|
|
114 |
|
|
115 |
0 |
col = ColorUtils.getGraduatedColour(10f, 10f, minColour, 30f, |
116 |
|
maxColour); |
117 |
0 |
assertEquals(minColour, col); |
118 |
|
|
119 |
|
|
120 |
|
|
121 |
|
|
122 |
0 |
col = ColorUtils.getGraduatedColour(30f, 10f, minColour, 30f, |
123 |
|
maxColour); |
124 |
0 |
assertEquals(maxColour, col); |
125 |
|
|
126 |
|
|
127 |
|
|
128 |
|
|
129 |
0 |
col = ColorUtils.getGraduatedColour(0f, 10f, minColour, 30f, maxColour); |
130 |
0 |
assertEquals(minColour, col); |
131 |
|
|
132 |
|
|
133 |
|
|
134 |
|
|
135 |
0 |
col = ColorUtils.getGraduatedColour(40f, 10f, minColour, 30f, |
136 |
|
maxColour); |
137 |
0 |
assertEquals(maxColour, col); |
138 |
|
|
139 |
|
|
140 |
|
|
141 |
|
|
142 |
0 |
col = ColorUtils.getGraduatedColour(40f, 10f, minColour, 10f, |
143 |
|
maxColour); |
144 |
0 |
assertEquals(minColour, col); |
145 |
|
} |
146 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
4-
|
|
147 |
0 |
@Test(groups = { "Functional" })... |
148 |
|
public void testBleachColour() |
149 |
|
{ |
150 |
0 |
Color colour = new Color(155, 105, 55); |
151 |
0 |
assertSame(colour, ColorUtils.bleachColour(colour, 0)); |
152 |
0 |
assertEquals(Color.WHITE, ColorUtils.bleachColour(colour, 1)); |
153 |
0 |
assertEquals(Color.WHITE, ColorUtils.bleachColour(colour, 2)); |
154 |
0 |
assertEquals(new Color(175, 135, 95), |
155 |
|
ColorUtils.bleachColour(colour, 0.2f)); |
156 |
0 |
assertEquals(new Color(225, 210, 195), |
157 |
|
ColorUtils.bleachColour(colour, 0.7f)); |
158 |
|
|
159 |
|
|
160 |
|
|
161 |
|
|
162 |
0 |
assertEquals(Color.BLACK, ColorUtils.bleachColour(colour, -1)); |
163 |
0 |
assertEquals(Color.BLACK, ColorUtils.bleachColour(colour, -2)); |
164 |
0 |
assertEquals(new Color(124, 84, 44), |
165 |
|
ColorUtils.bleachColour(colour, -0.2f)); |
166 |
0 |
assertEquals(new Color(46, 31, 16), |
167 |
|
ColorUtils.bleachColour(colour, -0.7f)); |
168 |
|
} |
169 |
|
|
|
|
| 0% |
Uncovered Elements: 21 (21) |
Complexity: 1 |
Complexity Density: 0.05 |
4-
|
|
170 |
0 |
@Test(groups = "Functional")... |
171 |
|
public void testParseColourString() |
172 |
|
{ |
173 |
|
|
174 |
|
|
175 |
|
|
176 |
|
@see |
177 |
|
|
178 |
0 |
assertSame(Color.RED, ColorUtils.parseColourString("red")); |
179 |
0 |
assertSame(Color.RED, ColorUtils.parseColourString("Red")); |
180 |
0 |
assertSame(Color.RED, ColorUtils.parseColourString(" RED ")); |
181 |
|
|
182 |
|
|
183 |
|
|
184 |
|
|
185 |
0 |
String hexColour = Integer.toHexString(Color.RED.getRGB() & 0xffffff); |
186 |
0 |
assertEquals("ff0000", hexColour); |
187 |
0 |
assertEquals(Color.RED, ColorUtils.parseColourString(hexColour)); |
188 |
|
|
189 |
0 |
assertNull(ColorUtils.parseColourString("0x" + hexColour)); |
190 |
0 |
assertNull(ColorUtils.parseColourString("#" + hexColour)); |
191 |
|
|
192 |
0 |
assertEquals(Color.black, ColorUtils.parseColourString("1000000")); |
193 |
|
|
194 |
|
|
195 |
|
|
196 |
|
|
197 |
0 |
Color c = Color.pink; |
198 |
0 |
String rgb = String.format("%d,%d,%d", c.getRed(), c.getGreen(), |
199 |
|
c.getBlue()); |
200 |
0 |
assertEquals("255,175,175", rgb); |
201 |
0 |
assertEquals(c, ColorUtils.parseColourString(rgb)); |
202 |
0 |
assertEquals(c, ColorUtils.parseColourString("255, 175 , 175")); |
203 |
|
|
204 |
|
|
205 |
|
|
206 |
|
|
207 |
0 |
assertNull(ColorUtils.parseColourString(null)); |
208 |
0 |
assertNull(ColorUtils.parseColourString("rubbish")); |
209 |
0 |
assertEquals(Color.WHITE, ColorUtils.parseColourString("-1")); |
210 |
0 |
assertNull(ColorUtils |
211 |
|
.parseColourString(String.valueOf(Integer.MAX_VALUE))); |
212 |
0 |
assertNull(ColorUtils.parseColourString("100,200,300")); |
213 |
0 |
assertNull(ColorUtils.parseColourString("100,200")); |
214 |
0 |
assertNull(ColorUtils.parseColourString("100,200,100,200")); |
215 |
|
} |
216 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
4-
|
|
217 |
0 |
@Test(groups = "Functional")... |
218 |
|
public void testGetAWTColorFromName() |
219 |
|
{ |
220 |
0 |
assertEquals(Color.white, ColorUtils.getAWTColorFromName("white")); |
221 |
0 |
assertEquals(Color.white, ColorUtils.getAWTColorFromName("White")); |
222 |
0 |
assertEquals(Color.white, ColorUtils.getAWTColorFromName("WHITE")); |
223 |
0 |
assertEquals(Color.pink, ColorUtils.getAWTColorFromName("pink")); |
224 |
0 |
assertNull(ColorUtils.getAWTColorFromName("mauve")); |
225 |
0 |
assertNull(ColorUtils.getAWTColorFromName("")); |
226 |
0 |
assertNull(ColorUtils.getAWTColorFromName(null)); |
227 |
|
} |
228 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
4-
|
|
229 |
0 |
@Test(groups = "Functional")... |
230 |
|
public void testCreateColourFromName() |
231 |
|
{ |
232 |
0 |
assertEquals(Color.white, ColorUtils.createColourFromName(null)); |
233 |
0 |
assertEquals(new Color(20, 20, 20), |
234 |
|
ColorUtils.createColourFromName("")); |
235 |
0 |
assertEquals(new Color(98, 131, 171), |
236 |
|
ColorUtils.createColourFromName("None")); |
237 |
0 |
assertEquals(new Color(123, 211, 122), |
238 |
|
ColorUtils.createColourFromName("hello world")); |
239 |
0 |
assertEquals(new Color(27, 147, 112), |
240 |
|
ColorUtils.createColourFromName("HELLO WORLD")); |
241 |
|
|
242 |
|
|
243 |
|
|
244 |
|
|
245 |
0 |
assertEquals(new Color(184, 184, 184), |
246 |
|
ColorUtils.createColourFromName("HELLO HELLO HELLO ")); |
247 |
|
} |
248 |
|
} |