>any(), anyLong()))
.thenReturn(textChannel);
when(jda.getPrivateChannelById(anyLong())).thenReturn(privateChannel);
@@ -188,6 +197,7 @@ public JdaTester() {
when(jda.retrieveUserById(anyLong())).thenReturn(userAction);
doReturn(null).when(textChannel).retrieveMessageById(any());
+ doReturn(null).when(threadChannel).retrieveMessageById(any());
interactionHook = mock(InteractionHook.class);
when(interactionHook.editOriginal(anyString())).thenReturn(webhookMessageEditAction);
@@ -197,8 +207,11 @@ public JdaTester() {
.thenReturn(webhookMessageEditAction);
doReturn(messageCreateAction).when(textChannel).sendMessageEmbeds(any(), any());
+ doReturn(messageCreateAction).when(threadChannel).sendMessageEmbeds(any(), any());
doReturn(messageCreateAction).when(textChannel).sendMessageEmbeds(any());
+ doReturn(messageCreateAction).when(threadChannel).sendMessageEmbeds(any());
doReturn(privateChannel).when(textChannel).asPrivateChannel();
+ doReturn(textChannel).when(threadChannel).getParentChannel();
doNothing().when(messageCreateAction).queue();
when(messageCreateAction.setContent(any())).thenReturn(messageCreateAction);
@@ -265,7 +278,7 @@ public ButtonClickEventBuilder createButtonInteractionEvent() {
Message message =
mockingDetails.isMock() || mockingDetails.isSpy() ? event : spy(event);
- mockMessage(message);
+ mockMessage(message, ChannelType.TEXT);
return message;
};
@@ -354,6 +367,20 @@ public TextChannel getTextChannelSpy() {
return textChannel;
}
+ /**
+ * Gets the thread channel spy used as universal thread channel by all mocks created by this
+ * tester instance.
+ *
+ * For example the events created by
+ * {@link #createMessageReceiveEvent(MessageCreateData, List, ChannelType)} can return this
+ * channel spy
+ *
+ * @return the thread channel spy used by this tester
+ */
+ public ThreadChannel getThreadChannelSpy() {
+ return threadChannel;
+ }
+
/**
* Gets the private channel spy used as universal private channel by all mocks created by this
* tester instance.
@@ -554,12 +581,14 @@ public ErrorResponseException createErrorResponseException(ErrorResponse reason)
*
* @param message the message that has been received
* @param attachments attachments of the message, empty if none
+ * @param channelType the type of the channel the message was sent in. See
+ * {@link #mockMessage(Message, ChannelType)} for supported channel types
* @return the event of receiving the given message
*/
public MessageReceivedEvent createMessageReceiveEvent(MessageCreateData message,
- List attachments) {
+ List attachments, ChannelType channelType) {
Message receivedMessage = clientMessageToReceivedMessageMock(message);
- mockMessage(receivedMessage);
+ mockMessage(receivedMessage, channelType);
doReturn(attachments).when(receivedMessage).getAttachments();
return new MessageReceivedEvent(jda, responseNumber.getAndIncrement(), receivedMessage);
@@ -638,7 +667,14 @@ private void mockButtonClickEvent(ButtonInteractionEvent event) {
doReturn(replyAction).when(event).editButton(any());
}
- private void mockMessage(Message message) {
+ private void mockMessage(Message message, ChannelType channelType) {
+ MessageChannelUnion channel = switch (channelType) {
+ case TEXT -> textChannel;
+ case GUILD_PUBLIC_THREAD -> threadChannel;
+ default -> throw new IllegalArgumentException(
+ "Unsupported channel type: " + channelType);
+ };
+
doReturn(messageCreateAction).when(message).reply(anyString());
doReturn(messageCreateAction).when(message)
.replyEmbeds(ArgumentMatchers.any());
@@ -651,7 +687,7 @@ private void mockMessage(Message message) {
doReturn(member).when(message).getMember();
doReturn(member.getUser()).when(message).getAuthor();
- doReturn(textChannel).when(message).getChannel();
+ doReturn(channel).when(message).getChannel();
doReturn(1L).when(message).getIdLong();
doReturn(false).when(message).isWebhookMessage();