You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ColourManagerTest.java 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. * Copyright (c) 2006-2008 Chris Smith, Shane Mc Cormack, Gregory Holmes
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to deal
  6. * in the Software without restriction, including without limitation the rights
  7. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. * copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. * SOFTWARE.
  21. */
  22. package com.dmdirc.ui.messages;
  23. import com.dmdirc.config.IdentityManager;
  24. import java.awt.Color;
  25. import org.junit.Before;
  26. import org.junit.BeforeClass;
  27. import org.junit.Test;
  28. import static org.junit.Assert.*;
  29. public class ColourManagerTest {
  30. @BeforeClass
  31. public static void setUp() throws Exception {
  32. IdentityManager.load();
  33. }
  34. @Test
  35. public void testGetColourInt() {
  36. int spec = 4;
  37. Color expResult = Color.RED;
  38. Color result = ColourManager.getColour(spec);
  39. assertEquals(expResult, result);
  40. }
  41. @Test
  42. public void testGetColourOOB() {
  43. Color result = ColourManager.getColour(20);
  44. assertEquals(Color.WHITE, result);
  45. }
  46. @Test
  47. public void testGetColourHexInvalid() {
  48. String spec = "FFZZFF";
  49. Color result = ColourManager.getColour(spec);
  50. assertEquals(Color.WHITE, result);
  51. }
  52. @Test
  53. public void testGetColourHex() {
  54. String spec = "FFFFFF";
  55. Color expResult = Color.decode("#FFFFFF");
  56. Color result = ColourManager.getColour(spec);
  57. assertEquals(expResult, result);
  58. }
  59. @Test
  60. public void testParseColourNull() {
  61. Color fallback = Color.RED;
  62. Color result = ColourManager.parseColour(null, fallback);
  63. assertEquals(fallback, result);
  64. }
  65. @Test
  66. public void testParseColourInvalidNumber() {
  67. Color fallback = Color.RED;
  68. Color result = ColourManager.parseColour("zz", fallback);
  69. assertEquals(fallback, result);
  70. }
  71. @Test
  72. public void testParseColourOOBNumber() {
  73. Color fallback = Color.RED;
  74. Color result = ColourManager.parseColour("20", fallback);
  75. assertEquals(fallback, result);
  76. }
  77. @Test
  78. public void testParseColourShortNumber() {
  79. Color fallback = Color.RED;
  80. Color result = ColourManager.parseColour("1234", fallback);
  81. assertEquals(fallback, result);
  82. }
  83. @Test
  84. public void testColourCache() {
  85. Color result1 = ColourManager.parseColour("ff0f0f");
  86. Color result2 = ColourManager.parseColour("ff0f0f");
  87. Color result3 = ColourManager.getColour("ff0f0f");
  88. assertSame(result1, result2);
  89. assertSame(result2, result3);
  90. }
  91. @Test
  92. public void testColourToHex() {
  93. Color c1 = ColourManager.parseColour("ab3400");
  94. assertEquals("ab3400", ColourManager.getHex(c1).toLowerCase());
  95. }
  96. @Test
  97. public void testCustomColours() {
  98. IdentityManager.getConfigIdentity().setOption("colour", "4", "00ff00");
  99. assertEquals("00ff00", ColourManager.getHex(ColourManager.getColour(4)).toLowerCase());
  100. IdentityManager.getConfigIdentity().unsetOption("colour", "4");
  101. }
  102. @Test
  103. public void testCustomColours2() {
  104. IdentityManager.getConfigIdentity().setOption("colour", "4", "000000");
  105. IdentityManager.getConfigIdentity().unsetOption("colour", "4");
  106. assertEquals("ff0000", ColourManager.getHex(ColourManager.getColour(4)).toLowerCase());
  107. }
  108. public static junit.framework.Test suite() {
  109. return new junit.framework.JUnit4TestAdapter(ColourManagerTest.class);
  110. }
  111. }