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.

AwayColoursManagerTest.java 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. * Copyright (c) 2006-2014 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.addons.awaycolours;
  23. import com.dmdirc.ChannelClientProperty;
  24. import com.dmdirc.DMDircMBassador;
  25. import com.dmdirc.config.ConfigBinder;
  26. import com.dmdirc.events.ChannelUserAwayEvent;
  27. import com.dmdirc.events.ChannelUserBackEvent;
  28. import com.dmdirc.interfaces.config.AggregateConfigProvider;
  29. import com.dmdirc.parser.interfaces.ChannelClientInfo;
  30. import com.dmdirc.ui.messages.ColourManager;
  31. import com.dmdirc.util.colours.Colour;
  32. import java.util.Map;
  33. import org.junit.Before;
  34. import org.junit.Test;
  35. import org.junit.runner.RunWith;
  36. import org.mockito.Mock;
  37. import org.mockito.runners.MockitoJUnitRunner;
  38. import static org.mockito.Mockito.never;
  39. import static org.mockito.Mockito.verify;
  40. import static org.mockito.Mockito.when;
  41. @RunWith(MockitoJUnitRunner.class)
  42. public class AwayColoursManagerTest {
  43. @Mock private DMDircMBassador eventBus;
  44. @Mock private AggregateConfigProvider config;
  45. @Mock private ConfigBinder binder;
  46. @Mock private ChannelUserAwayEvent awayEvent;
  47. @Mock private ChannelUserBackEvent backEvent;
  48. @Mock private ChannelClientInfo user;
  49. @Mock private Map<Object, Object> map;
  50. @Mock private ColourManager colourManager;
  51. private AwayColoursManager instance;
  52. private String red;
  53. private Colour redColour;
  54. private String black;
  55. private Colour blackColour;
  56. @Before
  57. public void setUp() throws Exception {
  58. red = "red";
  59. black = "black";
  60. redColour = Colour.RED;
  61. blackColour = Colour.BLACK;
  62. instance = new AwayColoursManager(eventBus, config, "test", colourManager);
  63. when(awayEvent.getUser()).thenReturn(user);
  64. when(backEvent.getUser()).thenReturn(user);
  65. when(user.getMap()).thenReturn(map);
  66. when(colourManager.getColourFromString(red, Colour.GRAY)).thenReturn(redColour);
  67. when(colourManager.getColourFromString(black, Colour.GRAY)).thenReturn(blackColour);
  68. }
  69. @Test
  70. public void testLoad() throws Exception {
  71. instance.load();
  72. verify(eventBus).subscribe(instance);
  73. }
  74. @Test
  75. public void testUnload() throws Exception {
  76. instance.unload();
  77. verify(eventBus).unsubscribe(instance);
  78. }
  79. @Test
  80. public void testHandleColourChange() throws Exception {
  81. instance.handleColourChange(red);
  82. instance.handleNicklistChange(true);
  83. instance.handleTextChange(true);
  84. instance.handleAwayEvent(awayEvent);
  85. verify(map).put(ChannelClientProperty.NICKLIST_FOREGROUND, redColour);
  86. verify(map).put(ChannelClientProperty.TEXT_FOREGROUND, redColour);
  87. instance.handleColourChange(black);
  88. instance.handleNicklistChange(true);
  89. instance.handleTextChange(true);
  90. instance.handleAwayEvent(awayEvent);
  91. verify(map).put(ChannelClientProperty.NICKLIST_FOREGROUND, blackColour);
  92. verify(map).put(ChannelClientProperty.TEXT_FOREGROUND, blackColour);
  93. }
  94. @Test
  95. public void testHandleNicklistChange() throws Exception {
  96. instance.handleColourChange(red);
  97. instance.handleNicklistChange(true);
  98. instance.handleTextChange(true);
  99. instance.handleAwayEvent(awayEvent);
  100. verify(map).put(ChannelClientProperty.NICKLIST_FOREGROUND, redColour);
  101. verify(map).put(ChannelClientProperty.TEXT_FOREGROUND, redColour);
  102. instance.handleColourChange(black);
  103. instance.handleNicklistChange(false);
  104. instance.handleTextChange(true);
  105. instance.handleAwayEvent(awayEvent);
  106. verify(map, never()).put(ChannelClientProperty.NICKLIST_FOREGROUND, blackColour);
  107. verify(map).put(ChannelClientProperty.TEXT_FOREGROUND, blackColour);
  108. }
  109. @Test
  110. public void testHandleTextChange() throws Exception {
  111. instance.handleColourChange(red);
  112. instance.handleNicklistChange(true);
  113. instance.handleTextChange(true);
  114. instance.handleAwayEvent(awayEvent);
  115. verify(map).put(ChannelClientProperty.NICKLIST_FOREGROUND, redColour);
  116. verify(map).put(ChannelClientProperty.TEXT_FOREGROUND, redColour);
  117. instance.handleColourChange(black);
  118. instance.handleNicklistChange(true);
  119. instance.handleTextChange(false);
  120. instance.handleAwayEvent(awayEvent);
  121. verify(map).put(ChannelClientProperty.NICKLIST_FOREGROUND, blackColour);
  122. verify(map, never()).put(ChannelClientProperty.TEXT_FOREGROUND, blackColour);
  123. }
  124. @Test
  125. public void testHandleAwayEvent() throws Exception {
  126. instance.handleNicklistChange(true);
  127. instance.handleTextChange(true);
  128. instance.handleBackEvent(backEvent);
  129. verify(map).remove(ChannelClientProperty.NICKLIST_FOREGROUND);
  130. verify(map).remove(ChannelClientProperty.TEXT_FOREGROUND);
  131. }
  132. @Test
  133. public void testHandleBackEvent() throws Exception {
  134. instance.handleColourChange(red);
  135. instance.handleNicklistChange(true);
  136. instance.handleTextChange(true);
  137. instance.handleAwayEvent(awayEvent);
  138. verify(map).put(ChannelClientProperty.NICKLIST_FOREGROUND, redColour);
  139. verify(map).put(ChannelClientProperty.TEXT_FOREGROUND, redColour);
  140. }
  141. }