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.

ActionGroupInformationPanelTest.java 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Copyright (c) 2006-2010 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.addons.ui_swing.dialogs.actionsmanager;
  23. import com.dmdirc.actions.ActionGroup;
  24. import com.dmdirc.updater.Version;
  25. import org.junit.Test;
  26. import org.uispec4j.Panel;
  27. import org.uispec4j.UISpecTestCase;
  28. import static org.junit.Assert.*;
  29. import static org.mockito.Mockito.*;
  30. public class ActionGroupInformationPanelTest extends UISpecTestCase {
  31. @Test
  32. public void testShouldDisplayNull() {
  33. assertFalse(new ActionGroupInformationPanel(null).shouldDisplay());
  34. }
  35. @Test
  36. public void testShouldDisplayNoDescription() {
  37. assertFalse(new ActionGroupInformationPanel(mock(ActionGroup.class)).shouldDisplay());
  38. }
  39. @Test
  40. public void testShouldDisplay() {
  41. final ActionGroup group = mock(ActionGroup.class);
  42. when(group.getDescription()).thenReturn("description");
  43. assertTrue(new ActionGroupInformationPanel(group).shouldDisplay());
  44. }
  45. @Test
  46. public void testAllLabels() {
  47. final ActionGroup group = mock(ActionGroup.class);
  48. when(group.getDescription()).thenReturn("description");
  49. when(group.getVersion()).thenReturn(new Version(17));
  50. when(group.getAuthor()).thenReturn("foo <bar@baz>");
  51. final Panel panel = new Panel(new ActionGroupInformationPanel(group));
  52. assertEquals("<panel>"
  53. + "<textBox text=\"description\"/>"
  54. + "<textBox text=\"Author: \"/>"
  55. + "<textBox text=\"foo &lt;bar@baz&gt;\"/>"
  56. + "<textBox text=\"Version: \"/>"
  57. + "<textBox text=\"17\"/>"
  58. + "</panel>", panel.getDescription().replace("\n", ""));
  59. }
  60. @Test
  61. public void testNoAuthor() {
  62. final ActionGroup group = mock(ActionGroup.class);
  63. when(group.getDescription()).thenReturn("description");
  64. when(group.getVersion()).thenReturn(new Version(17));
  65. final Panel panel = new Panel(new ActionGroupInformationPanel(group));
  66. assertEquals("<panel>"
  67. + "<textBox text=\"description\"/>"
  68. + "<textBox text=\"Version: \"/>"
  69. + "<textBox text=\"17\"/>"
  70. + "</panel>", panel.getDescription().replace("\n", ""));
  71. }
  72. @Test
  73. public void testNoVersion() {
  74. final ActionGroup group = mock(ActionGroup.class);
  75. when(group.getDescription()).thenReturn("description");
  76. when(group.getVersion()).thenReturn(null);
  77. when(group.getAuthor()).thenReturn("foo <bar@baz>");
  78. final Panel panel = new Panel(new ActionGroupInformationPanel(group));
  79. assertEquals("<panel>"
  80. + "<textBox text=\"description\"/>"
  81. + "<textBox text=\"Author: \"/>"
  82. + "<textBox text=\"foo &lt;bar@baz&gt;\"/>"
  83. + "</panel>", panel.getDescription().replace("\n", ""));
  84. }
  85. }