Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

AwayColoursManagerTest.java 5.7KB

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