|
@@ -25,8 +25,16 @@ import com.dmdirc.Channel;
|
25
|
25
|
import com.dmdirc.FrameContainer;
|
26
|
26
|
import com.dmdirc.commandparser.CommandArguments;
|
27
|
27
|
import com.dmdirc.commandparser.commands.context.ChannelCommandContext;
|
|
28
|
+import com.dmdirc.events.DisplayProperty;
|
28
|
29
|
import com.dmdirc.interfaces.CommandController;
|
|
30
|
+import com.dmdirc.interfaces.Connection;
|
|
31
|
+import com.dmdirc.interfaces.GroupChatUser;
|
|
32
|
+import com.dmdirc.interfaces.User;
|
|
33
|
+import com.dmdirc.ui.messages.ColourManager;
|
29
|
34
|
import com.dmdirc.ui.messages.ColourManagerFactory;
|
|
35
|
+import com.dmdirc.util.colours.Colour;
|
|
36
|
+
|
|
37
|
+import java.util.Optional;
|
30
|
38
|
|
31
|
39
|
import org.junit.Before;
|
32
|
40
|
import org.junit.Test;
|
|
@@ -34,18 +42,25 @@ import org.junit.runner.RunWith;
|
34
|
42
|
import org.mockito.Mock;
|
35
|
43
|
import org.mockito.runners.MockitoJUnitRunner;
|
36
|
44
|
|
|
45
|
+import static org.mockito.Matchers.any;
|
37
|
46
|
import static org.mockito.Mockito.anyChar;
|
38
|
47
|
import static org.mockito.Mockito.anyString;
|
39
|
48
|
import static org.mockito.Mockito.eq;
|
40
|
49
|
import static org.mockito.Mockito.mock;
|
|
50
|
+import static org.mockito.Mockito.never;
|
41
|
51
|
import static org.mockito.Mockito.verify;
|
42
|
52
|
import static org.mockito.Mockito.when;
|
43
|
53
|
|
44
|
54
|
@RunWith(MockitoJUnitRunner.class)
|
45
|
55
|
public class SetNickColourTest {
|
46
|
56
|
|
|
57
|
+ @Mock private Connection connection;
|
|
58
|
+ @Mock private User user1;
|
|
59
|
+ @Mock private User user2;
|
|
60
|
+ @Mock private GroupChatUser groupChatUser;
|
47
|
61
|
@Mock private Channel channel;
|
48
|
62
|
@Mock private ColourManagerFactory colourManagerFactory;
|
|
63
|
+ @Mock private ColourManager colourManager;
|
49
|
64
|
@Mock private CommandController controller;
|
50
|
65
|
private SetNickColour command;
|
51
|
66
|
|
|
@@ -54,6 +69,13 @@ public class SetNickColourTest {
|
54
|
69
|
command = new SetNickColour(controller, colourManagerFactory);
|
55
|
70
|
when(controller.getCommandChar()).thenReturn('/');
|
56
|
71
|
when(controller.getSilenceChar()).thenReturn('.');
|
|
72
|
+ when(channel.getConnection()).thenReturn(Optional.of(connection));
|
|
73
|
+ when(connection.getUser("moo")).thenReturn(user1);
|
|
74
|
+ when(connection.getUser("foo")).thenReturn(user2);
|
|
75
|
+ when(channel.getUser(user1)).thenReturn(Optional.of(groupChatUser));
|
|
76
|
+ when(channel.getUser(user2)).thenReturn(Optional.empty());
|
|
77
|
+ when(colourManagerFactory.getColourManager(any())).thenReturn(colourManager);
|
|
78
|
+ when(colourManager.getColourFromString(eq("4"), any())).thenReturn(Colour.RED);
|
57
|
79
|
}
|
58
|
80
|
|
59
|
81
|
@Test
|
|
@@ -66,21 +88,40 @@ public class SetNickColourTest {
|
66
|
88
|
}
|
67
|
89
|
|
68
|
90
|
@Test
|
69
|
|
- public void testUsageNicklist() {
|
|
91
|
+ public void testUsageNicknameValid() {
|
70
|
92
|
final FrameContainer tiw = mock(FrameContainer.class);
|
71
|
|
- command.execute(tiw, new CommandArguments(controller, "/foo --nicklist"),
|
|
93
|
+ command.execute(tiw, new CommandArguments(controller, "/foo moo"),
|
72
|
94
|
new ChannelCommandContext(null, SetNickColour.INFO, channel));
|
|
95
|
+ verify(channel).refreshClients();
|
|
96
|
+ verify(groupChatUser).removeDisplayProperty(DisplayProperty.FOREGROUND_COLOUR);
|
|
97
|
+ }
|
73
|
98
|
|
74
|
|
- verify(tiw).addLine(eq("commandUsage"), anyChar(), anyString(), anyString());
|
|
99
|
+ @Test
|
|
100
|
+ public void testUsageNicknameInvalid() {
|
|
101
|
+ final FrameContainer tiw = mock(FrameContainer.class);
|
|
102
|
+ command.execute(tiw, new CommandArguments(controller, "/foo foo"),
|
|
103
|
+ new ChannelCommandContext(null, SetNickColour.INFO, channel));
|
|
104
|
+ verify(channel, never()).refreshClients();
|
|
105
|
+ verify(groupChatUser, never()).removeDisplayProperty(DisplayProperty.FOREGROUND_COLOUR);
|
|
106
|
+ verify(tiw).addLine(eq("commandError"), eq("No such nickname (foo)!"));
|
75
|
107
|
}
|
76
|
108
|
|
77
|
109
|
@Test
|
78
|
|
- public void testUsageText() {
|
|
110
|
+ public void testUsageInvalidColour() {
|
79
|
111
|
final FrameContainer tiw = mock(FrameContainer.class);
|
80
|
|
- command.execute(tiw, new CommandArguments(controller, "/foo --text"),
|
|
112
|
+ command.execute(tiw, new CommandArguments(controller, "/foo moo omg"),
|
81
|
113
|
new ChannelCommandContext(null, SetNickColour.INFO, channel));
|
82
|
114
|
|
83
|
|
- verify(tiw).addLine(eq("commandUsage"), anyChar(), anyString(), anyString());
|
|
115
|
+ verify(tiw).addLine(eq("commandError"), eq("Invalid colour specified (omg)."));
|
|
116
|
+ }
|
|
117
|
+
|
|
118
|
+ @Test
|
|
119
|
+ public void testUsageValidColour() {
|
|
120
|
+ final FrameContainer tiw = mock(FrameContainer.class);
|
|
121
|
+ command.execute(tiw, new CommandArguments(controller, "/foo moo 4"),
|
|
122
|
+ new ChannelCommandContext(null, SetNickColour.INFO, channel));
|
|
123
|
+ verify(channel).refreshClients();
|
|
124
|
+ verify(groupChatUser).setDisplayProperty(DisplayProperty.FOREGROUND_COLOUR, Colour.RED);
|
84
|
125
|
}
|
85
|
126
|
|
86
|
127
|
}
|