From 141a62844c23f4b7734479273cef05cc065babeb Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sat, 18 Oct 2014 16:06:10 +0200 Subject: [PATCH] Move reply mocking into its own helper class. --- .../connection/ChannelNotJoinedHandlerTest.java | 15 +----------- .../net/pterodactylus/irc/connection/Replies.java | 28 ++++++++++++++++++++++ 2 files changed, 29 insertions(+), 14 deletions(-) create mode 100644 src/test/java/net/pterodactylus/irc/connection/Replies.java diff --git a/src/test/java/net/pterodactylus/irc/connection/ChannelNotJoinedHandlerTest.java b/src/test/java/net/pterodactylus/irc/connection/ChannelNotJoinedHandlerTest.java index 3c27ebc..0a7ef98 100644 --- a/src/test/java/net/pterodactylus/irc/connection/ChannelNotJoinedHandlerTest.java +++ b/src/test/java/net/pterodactylus/irc/connection/ChannelNotJoinedHandlerTest.java @@ -1,6 +1,7 @@ package net.pterodactylus.irc.connection; import static java.util.Arrays.asList; +import static net.pterodactylus.irc.connection.Replies.createReply; import static net.pterodactylus.irc.event.ChannelNotJoined.Reason.badChannelKey; import static net.pterodactylus.irc.event.ChannelNotJoined.Reason.banned; import static net.pterodactylus.irc.event.ChannelNotJoined.Reason.inviteOnly; @@ -10,10 +11,8 @@ import static org.hamcrest.Matchers.is; import static org.mockito.ArgumentCaptor.forClass; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; import net.pterodactylus.irc.Connection; -import net.pterodactylus.irc.Reply; import net.pterodactylus.irc.event.ChannelNotJoined; import net.pterodactylus.irc.event.ChannelNotJoined.Reason; @@ -48,11 +47,6 @@ public class ChannelNotJoinedHandlerTest { } } - private Reply createReply(String command) { - Reply reply = mock(Reply.class); - return when(reply.command()).thenReturn(command).getMock(); - } - @Test public void bannedChannelNotJoinedIsRecognizedCorrectly() { handler.handleReply(createReply("474", "#test")); @@ -86,11 +80,4 @@ public class ChannelNotJoinedHandlerTest { verifyReasonIs(registeredNicknamesOnly); } - private Reply createReply(String command, String channel) { - final Reply reply = mock(Reply.class); - when(reply.command()).thenReturn(command); - when(reply.parameters()).thenReturn(asList(":some.server", channel)); - return reply; - } - } diff --git a/src/test/java/net/pterodactylus/irc/connection/Replies.java b/src/test/java/net/pterodactylus/irc/connection/Replies.java new file mode 100644 index 0000000..214c3d4 --- /dev/null +++ b/src/test/java/net/pterodactylus/irc/connection/Replies.java @@ -0,0 +1,28 @@ +package net.pterodactylus.irc.connection; + +import static java.util.Arrays.asList; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import net.pterodactylus.irc.Reply; + +/** + * Helper class to mock {@link Reply}s for testing {@link Handler}s. + * + * @author David ‘Bombe’ Roden + */ +public class Replies { + + public static Reply createReply(String command, String channel) { + final Reply reply = mock(Reply.class); + when(reply.command()).thenReturn(command); + when(reply.parameters()).thenReturn(asList(":some.server", channel)); + return reply; + } + + public static Reply createReply(String command) { + Reply reply = mock(Reply.class); + return when(reply.command()).thenReturn(command).getMock(); + } + +} -- 2.7.4