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.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * Copyright (c) 2006-2011 DMDirc Developers
  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.BeforeClass;
  26. import org.junit.Test;
  27. import static org.junit.Assert.*;
  28. public class ColourManagerTest {
  29. @BeforeClass
  30. public static void setUp() throws Exception {
  31. IdentityManager.load();
  32. }
  33. @Test
  34. public void testGetColourInt() {
  35. int spec = 4;
  36. Color expResult = Color.RED;
  37. Color result = ColourManager.getColour(spec);
  38. assertEquals(expResult, result);
  39. }
  40. @Test
  41. public void testGetColourOOB() {
  42. Color result = ColourManager.getColour(20);
  43. assertEquals(Color.WHITE, result);
  44. }
  45. @Test
  46. public void testGetColourHexInvalid() {
  47. String spec = "FFZZFF";
  48. Color result = ColourManager.getColour(spec);
  49. assertEquals(Color.WHITE, result);
  50. }
  51. @Test
  52. public void testGetColourHex() {
  53. String spec = "FFFFFF";
  54. Color expResult = Color.decode("#FFFFFF");
  55. Color result = ColourManager.getColour(spec);
  56. assertEquals(expResult, result);
  57. }
  58. @Test
  59. public void testParseColourNull() {
  60. Color fallback = Color.RED;
  61. Color result = ColourManager.parseColour(null, fallback);
  62. assertEquals(fallback, result);
  63. }
  64. @Test
  65. public void testParseColourInvalidNumber() {
  66. Color fallback = Color.RED;
  67. Color result = ColourManager.parseColour("zz", fallback);
  68. assertEquals(fallback, result);
  69. }
  70. @Test
  71. public void testParseColourOOBNumber() {
  72. Color fallback = Color.RED;
  73. Color result = ColourManager.parseColour("20", fallback);
  74. assertEquals(fallback, result);
  75. }
  76. @Test
  77. public void testParseColourShortNumber() {
  78. Color fallback = Color.RED;
  79. Color result = ColourManager.parseColour("1234", fallback);
  80. assertEquals(fallback, result);
  81. }
  82. @Test
  83. public void testColourCache() {
  84. Color result1 = ColourManager.parseColour("ff0f0f");
  85. Color result2 = ColourManager.parseColour("ff0f0f");
  86. Color result3 = ColourManager.getColour("ff0f0f");
  87. assertSame(result1, result2);
  88. assertSame(result2, result3);
  89. }
  90. @Test
  91. public void testColourToHex() {
  92. Color c1 = ColourManager.parseColour("ab3400");
  93. assertEquals("ab3400", ColourManager.getHex(c1).toLowerCase());
  94. }
  95. @Test
  96. public void testCustomColours() {
  97. IdentityManager.getConfigIdentity().setOption("colour", "4", "00ff00");
  98. assertEquals("00ff00", ColourManager.getHex(ColourManager.getColour(4)).toLowerCase());
  99. IdentityManager.getConfigIdentity().unsetOption("colour", "4");
  100. }
  101. @Test
  102. public void testCustomColours2() {
  103. IdentityManager.getConfigIdentity().setOption("colour", "4", "000000");
  104. IdentityManager.getConfigIdentity().unsetOption("colour", "4");
  105. assertEquals("ff0000", ColourManager.getHex(ColourManager.getColour(4)).toLowerCase());
  106. }
  107. }