JAL-1270 JUnit to TestNG refactoring
[jalview.git] / test / jalview / util / ColorUtilsTest.java
1 package jalview.util;
2
3 import static org.testng.AssertJUnit.assertEquals;
4 import static org.testng.AssertJUnit.assertNull;
5 import org.testng.annotations.Test;
6 import java.awt.Color;
7
8 public class ColorUtilsTest
9 {
10
11   Color paleColour = new Color(97, 203, 111); // pale green
12
13   Color midColour = new Color(135, 57, 41); // mid red
14
15   Color darkColour = new Color(11, 30, 50); // dark blue
16
17   @Test
18   public void testDarkerThan()
19   {
20     assertEquals("Wrong darker shade", new Color(32, 69, 37),
21             ColorUtils.darkerThan(paleColour));
22     assertEquals("Wrong darker shade", new Color(45, 18, 13),
23             ColorUtils.darkerThan(midColour));
24     assertEquals("Wrong darker shade", new Color(2, 9, 16),
25             ColorUtils.darkerThan(darkColour));
26     assertNull(ColorUtils.darkerThan(null));
27   }
28
29   @Test
30   public void testBrighterThan()
31   {
32     assertEquals("Wrong brighter shade", new Color(255, 255, 255), // white
33             ColorUtils.brighterThan(paleColour));
34     assertEquals("Wrong brighter shade", new Color(255, 164, 117),
35             ColorUtils.brighterThan(midColour));
36     assertEquals("Wrong brighter shade", new Color(30, 85, 144),
37             ColorUtils.brighterThan(darkColour));
38     assertNull(ColorUtils.brighterThan(null));
39   }
40
41   /**
42    * @see http://www.rtapo.com/notes/named_colors.html
43    */
44   @Test
45   public void testToTkCode()
46   {
47     assertEquals("#fffafa", ColorUtils.toTkCode(new Color(255, 250, 250))); // snow
48     assertEquals("#e6e6fa", ColorUtils.toTkCode(new Color(230, 230, 250))); // lavender
49     assertEquals("#dda0dd", ColorUtils.toTkCode(new Color(221, 160, 221))); // plum
50     assertEquals("#800080", ColorUtils.toTkCode(new Color(128, 0, 128))); // purple
51     assertEquals("#00ff00", ColorUtils.toTkCode(new Color(0, 255, 0))); // lime
52   }
53 }