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