Add unit test for CTCP handler; refactor CTCP handler.
[xudocci.git] / src / test / java / net / pterodactylus / irc / connection / Replies.java
1 package net.pterodactylus.irc.connection;
2
3 import static com.google.common.base.Optional.fromNullable;
4 import static java.util.Arrays.asList;
5 import static org.mockito.Mockito.mock;
6 import static org.mockito.Mockito.when;
7
8 import java.util.ArrayList;
9 import java.util.List;
10
11 import net.pterodactylus.irc.Reply;
12 import net.pterodactylus.irc.Source;
13
14 /**
15  * Helper class to mock {@link Reply}s for testing {@link Handler}s.
16  *
17  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
18  */
19 public class Replies {
20
21         public static Reply createReply(Source source, String command,
22                         String... parameters) {
23                 Reply reply = createReply(command, parameters);
24                 when(reply.source()).thenReturn(fromNullable(source));
25                 return reply;
26         }
27
28         public static Reply createReply(String command, String... parameters) {
29                 final Reply reply = mock(Reply.class);
30                 when(reply.command()).thenReturn(command);
31                 List<String> allParameters = new ArrayList<>();
32                 allParameters.add(":some.server");
33                 allParameters.addAll(asList(parameters));
34                 when(reply.parameters()).thenReturn(allParameters);
35                 return reply;
36         }
37
38         public static Reply createReply(String command) {
39                 Reply reply = mock(Reply.class);
40                 return when(reply.command()).thenReturn(command).getMock();
41         }
42
43 }