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.

ConfigSourceTest.java 3.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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.config;
  23. import com.dmdirc.harness.TestConfigSource;
  24. import java.awt.Color;
  25. import org.junit.Test;
  26. import static org.junit.Assert.*;
  27. public class ConfigSourceTest extends junit.framework.TestCase {
  28. private final TestConfigSource s = new TestConfigSource();
  29. @Test
  30. public void testGetOption() {
  31. assertEquals("moo", s.getOption("false", "bar", "moo"));
  32. assertEquals("bar", s.getOption("true", "bar", "moo"));
  33. }
  34. @Test
  35. public void testGetColour() {
  36. assertEquals(Color.RED, s.getOptionColour("false", "moo", Color.RED));
  37. assertEquals(Color.WHITE, s.getOptionColour("true", "0", Color.RED));
  38. }
  39. @Test
  40. public void testGetChar() {
  41. assertEquals('c', s.getOptionChar("true", "c", 'd'));
  42. assertEquals('c', s.getOptionChar("true", "coo", 'd'));
  43. assertEquals('d', s.getOptionChar("false", "c", 'd'));
  44. assertEquals('d', s.getOptionChar("true", "", 'd'));
  45. }
  46. @Test
  47. public void testGetOptionalColour() {
  48. assertEquals(Color.RED, s.getOptionColour("true", "false:0", Color.RED));
  49. assertEquals(Color.WHITE, s.getOptionColour("true", "true:0", Color.RED));
  50. }
  51. @Test
  52. public void testGetBoolean() {
  53. assertTrue(s.getOptionBool("true", "true"));
  54. assertFalse(s.getOptionBool("true", "false"));
  55. assertTrue(s.getOptionBool("true", "true", false));
  56. assertTrue(s.getOptionBool("false", "true", true));
  57. assertFalse(s.getOptionBool("false", "true", false));
  58. }
  59. @Test
  60. public void testGetInt() {
  61. assertEquals(42, s.getOptionInt("false", "moo", 42));
  62. assertEquals(42, s.getOptionInt("true", "42", 0));
  63. assertEquals(42, s.getOptionInt("true", "moo", 42));
  64. }
  65. @Test
  66. public void testGetList() {
  67. assertTrue(s.getOptionList("false", "moo").isEmpty());
  68. assertTrue(s.getOptionList("true", "").isEmpty());
  69. assertTrue(s.getOptionList("true", "\n\n\n").isEmpty());
  70. assertEquals(4, s.getOptionList("true", "\n\n\na", false).size());
  71. assertEquals(4, s.getOptionList("true", "a\nb\nc\nd", true).size());
  72. assertEquals("c", s.getOptionList("true", "a\nb\nc\nd", true).get(2));
  73. }
  74. }