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 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * Copyright (c) 2006-2017 DMDirc Developers
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
  5. * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
  6. * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
  7. * permit persons to whom the Software is furnished to do so, subject to the following conditions:
  8. *
  9. * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
  10. * Software.
  11. *
  12. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  13. * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
  14. * OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  15. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  16. */
  17. package com.dmdirc.addons.awaycolours;
  18. import com.dmdirc.Channel;
  19. import com.dmdirc.config.ConfigBinder;
  20. import com.dmdirc.events.ChannelUserAwayEvent;
  21. import com.dmdirc.events.ChannelUserBackEvent;
  22. import com.dmdirc.events.DisplayProperty;
  23. import com.dmdirc.interfaces.EventBus;
  24. import com.dmdirc.interfaces.GroupChatUser;
  25. import com.dmdirc.interfaces.config.AggregateConfigProvider;
  26. import com.dmdirc.ui.messages.ColourManager;
  27. import com.dmdirc.util.colours.Colour;
  28. import org.junit.Before;
  29. import org.junit.Test;
  30. import org.junit.runner.RunWith;
  31. import org.mockito.Mock;
  32. import org.mockito.runners.MockitoJUnitRunner;
  33. import static org.mockito.Matchers.anyString;
  34. import static org.mockito.Mockito.verify;
  35. import static org.mockito.Mockito.when;
  36. @RunWith(MockitoJUnitRunner.class)
  37. public class AwayColoursManagerTest {
  38. @Mock private EventBus eventBus;
  39. @Mock private AggregateConfigProvider config;
  40. @Mock private ConfigBinder binder;
  41. @Mock private ChannelUserAwayEvent awayEvent;
  42. @Mock private ChannelUserBackEvent backEvent;
  43. @Mock private GroupChatUser user;
  44. @Mock private Channel channel;
  45. @Mock private ColourManager colourManager;
  46. private AwayColoursManager instance;
  47. private String red;
  48. private Colour redColour;
  49. private String black;
  50. private Colour blackColour;
  51. @Before
  52. public void setUp() throws Exception {
  53. red = "red";
  54. black = "black";
  55. redColour = Colour.RED;
  56. blackColour = Colour.BLACK;
  57. when(awayEvent.getUser()).thenReturn(user);
  58. when(awayEvent.getChannel()).thenReturn(channel);
  59. when(backEvent.getUser()).thenReturn(user);
  60. when(backEvent.getChannel()).thenReturn(channel);
  61. when(config.getBinder()).thenReturn(binder);
  62. when(binder.withDefaultDomain(anyString())).thenReturn(binder);
  63. when(colourManager.getColourFromString(red, Colour.GRAY)).thenReturn(redColour);
  64. when(colourManager.getColourFromString(black, Colour.GRAY)).thenReturn(blackColour);
  65. instance = new AwayColoursManager(eventBus, config, "test", colourManager);
  66. }
  67. @Test
  68. public void testLoad() throws Exception {
  69. instance.load();
  70. verify(eventBus).subscribe(instance);
  71. }
  72. @Test
  73. public void testUnload() throws Exception {
  74. instance.unload();
  75. verify(eventBus).unsubscribe(instance);
  76. }
  77. @Test
  78. public void testHandleColourChange() throws Exception {
  79. instance.handleColourChange(red);
  80. instance.handleAwayEvent(awayEvent);
  81. verify(user).setDisplayProperty(DisplayProperty.FOREGROUND_COLOUR, redColour);
  82. instance.handleColourChange(black);
  83. instance.handleAwayEvent(awayEvent);
  84. verify(user).setDisplayProperty(DisplayProperty.FOREGROUND_COLOUR, blackColour);
  85. }
  86. @Test
  87. public void testHandleAwayEvent() throws Exception {
  88. instance.handleBackEvent(backEvent);
  89. verify(user).removeDisplayProperty(DisplayProperty.FOREGROUND_COLOUR);
  90. }
  91. @Test
  92. public void testHandleBackEvent() throws Exception {
  93. instance.handleColourChange(red);
  94. instance.handleAwayEvent(awayEvent);
  95. verify(user).setDisplayProperty(DisplayProperty.FOREGROUND_COLOUR, redColour);
  96. }
  97. }