add tests
This commit is contained in:
parent
842fcfe5ac
commit
8943d6d4a4
@ -7,6 +7,7 @@ log4j = "2.24.1"
|
||||
javacord = "3.8.0"
|
||||
discord4j = "3.2.7"
|
||||
geantyref = "2.0.0"
|
||||
mockito = "5.15.2"
|
||||
|
||||
[libraries]
|
||||
junit-jupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit-jupiter" }
|
||||
@ -14,3 +15,4 @@ log4j = { module = "org.apache.logging.log4j:log4j-api", version.ref = "log4j"}
|
||||
javacord = { module = "org.javacord:javacord", version.ref = "javacord"}
|
||||
discord4j = { module = "com.discord4j:discord4j-core", version.ref = "discord4j"}
|
||||
geantyref = { module = "io.leangen.geantyref:geantyref", version.ref = "geantyref"}
|
||||
mockito = {module = "org.mockito:mockito-core", version.ref = "mockito"}
|
||||
|
@ -18,11 +18,12 @@ repositories {
|
||||
dependencies {
|
||||
// Use JUnit Jupiter for testing.
|
||||
testImplementation(libs.junit.jupiter)
|
||||
testImplementation(libs.mockito)
|
||||
|
||||
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
|
||||
implementation(libs.log4j)
|
||||
implementation(libs.discord4j) {
|
||||
exclude(module="discord4j-voice")
|
||||
// exclude(module="discord4j-voice")
|
||||
}
|
||||
implementation(libs.geantyref)
|
||||
implementation(project(":lib"))
|
||||
|
@ -1,23 +1,45 @@
|
||||
package net.tomatentum.marinara.test.discord4j;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import discord4j.core.event.domain.interaction.ChatInputAutoCompleteEvent;
|
||||
import discord4j.core.object.command.ApplicationCommandInteractionOption;
|
||||
import discord4j.core.object.command.ApplicationCommandInteractionOptionValue;
|
||||
import discord4j.core.object.command.ApplicationCommandOption.Type;
|
||||
import net.tomatentum.marinara.Marinara;
|
||||
import net.tomatentum.marinara.test.discord4j.mocks.AutocompleteInteractionMock;
|
||||
import net.tomatentum.marinara.test.discord4j.mocks.DiscordApiMock;
|
||||
import net.tomatentum.marinara.wrapper.LibraryWrapper;
|
||||
import net.tomatentum.marinara.wrapper.javacord.JavacordWrapper;
|
||||
import net.tomatentum.marinara.wrapper.discord4j.Discord4JWrapper;
|
||||
|
||||
public class AutoCompleteTest {
|
||||
|
||||
@Test
|
||||
public void testAutocomplete() {
|
||||
LibraryWrapper wrapper = new JavacordWrapper(new DiscordApiMock()); //null okay as we don't use the discord API in this test.
|
||||
ApplicationCommandInteractionOption optionMock = mock();
|
||||
ChatInputAutoCompleteEvent autoCompleteEventMock = mock();
|
||||
|
||||
when(optionMock.getName()).thenReturn("foo");
|
||||
when(optionMock.getType()).thenReturn(Type.STRING);
|
||||
when(optionMock.getValue()).thenReturn(
|
||||
Optional.of(
|
||||
new ApplicationCommandInteractionOptionValue(null, null, Type.STRING.getValue(), "test", null)
|
||||
));
|
||||
|
||||
when(autoCompleteEventMock.getCommandName()).thenReturn("test");
|
||||
when(autoCompleteEventMock.getOptions()).thenReturn(new ArrayList<>());
|
||||
when(autoCompleteEventMock.getFocusedOption()).thenReturn(optionMock);
|
||||
|
||||
LibraryWrapper wrapper = new Discord4JWrapper(null); //null okay as we don't use the discord API in this test.
|
||||
Marinara marinara = Marinara.load(wrapper);
|
||||
marinara.getRegistry().addInteractions(new TestAutocomplete());
|
||||
wrapper.handleInteraction(new AutocompleteInteractionMock());
|
||||
assertTrue(AutocompleteInteractionMock.didAutocompleteRun);
|
||||
wrapper.handleInteraction(autoCompleteEventMock);
|
||||
verify(autoCompleteEventMock).respondWithSuggestions(any());
|
||||
}
|
||||
}
|
||||
|
@ -6,21 +6,23 @@ import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.api.TestInstance.Lifecycle;
|
||||
|
||||
import discord4j.core.event.domain.interaction.ButtonInteractionEvent;
|
||||
import net.tomatentum.marinara.Marinara;
|
||||
import net.tomatentum.marinara.test.discord4j.mocks.ButtonInteractionMock;
|
||||
import net.tomatentum.marinara.test.discord4j.mocks.DiscordApiMock;
|
||||
import net.tomatentum.marinara.test.discord4j.mocks.CommonMocks;
|
||||
import net.tomatentum.marinara.wrapper.LibraryWrapper;
|
||||
import net.tomatentum.marinara.wrapper.javacord.JavacordWrapper;
|
||||
import net.tomatentum.marinara.wrapper.discord4j.Discord4JWrapper;
|
||||
|
||||
@TestInstance(Lifecycle.PER_CLASS)
|
||||
public class ButtonTest {
|
||||
|
||||
@Test
|
||||
public void testButtonExecution() {
|
||||
LibraryWrapper wrapper = new JavacordWrapper(new DiscordApiMock()); //null okay as we don't use the discord API in this test.
|
||||
ButtonInteractionEvent buttonEventMock = CommonMocks.getButtonEventMock("test");
|
||||
|
||||
LibraryWrapper wrapper = new Discord4JWrapper(null); //null okay as we don't use the discord API in this test.
|
||||
Marinara marinara = Marinara.load(wrapper);
|
||||
marinara.getRegistry().addInteractions(new TestButton());
|
||||
wrapper.handleInteraction(new ButtonInteractionMock("test"));
|
||||
wrapper.handleInteraction(buttonEventMock);
|
||||
assertTrue(TestButton.didRun);
|
||||
}
|
||||
|
||||
|
@ -2,46 +2,69 @@ package net.tomatentum.marinara.test.discord4j;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.javacord.api.entity.permission.PermissionType;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.api.TestInstance.Lifecycle;
|
||||
|
||||
import discord4j.core.event.domain.interaction.ButtonInteractionEvent;
|
||||
import discord4j.core.object.command.Interaction;
|
||||
import discord4j.core.object.entity.Member;
|
||||
import discord4j.rest.util.Permission;
|
||||
import discord4j.rest.util.PermissionSet;
|
||||
import net.tomatentum.marinara.Marinara;
|
||||
import net.tomatentum.marinara.test.discord4j.mocks.ButtonInteractionMock;
|
||||
import net.tomatentum.marinara.test.discord4j.mocks.DiscordApiMock;
|
||||
import net.tomatentum.marinara.test.discord4j.mocks.ServerMock;
|
||||
import net.tomatentum.marinara.test.discord4j.mocks.CommonMocks;
|
||||
import net.tomatentum.marinara.wrapper.LibraryWrapper;
|
||||
import net.tomatentum.marinara.wrapper.javacord.JavacordWrapper;
|
||||
import net.tomatentum.marinara.wrapper.javacord.checks.PermissionCheck;
|
||||
import net.tomatentum.marinara.wrapper.discord4j.Discord4JWrapper;
|
||||
import net.tomatentum.marinara.wrapper.discord4j.checks.PermissionCheck;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@TestInstance(Lifecycle.PER_CLASS)
|
||||
public class InteractionCheckTest {
|
||||
|
||||
@Test
|
||||
public void testInteractionCheck() {
|
||||
LibraryWrapper wrapper = new JavacordWrapper(new DiscordApiMock());
|
||||
ButtonInteractionEvent buttonEventMock = CommonMocks.getButtonEventMock("test");
|
||||
|
||||
LibraryWrapper wrapper = new Discord4JWrapper(null);
|
||||
Marinara marinara = Marinara.load(wrapper);
|
||||
marinara.getCheckRegistry().addCheck(new TestInteractionCheck());
|
||||
marinara.getRegistry().addInteractions(new TestButton());
|
||||
wrapper.handleInteraction(new ButtonInteractionMock("test"));
|
||||
wrapper.handleInteraction(buttonEventMock);
|
||||
|
||||
assertTrue(TestInteractionCheck.preExecuted);
|
||||
assertTrue(TestInteractionCheck.postExecuted);
|
||||
assertTrue(TestButton.didRun);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPermissionCheck() {
|
||||
LibraryWrapper wrapper = new JavacordWrapper(new DiscordApiMock());
|
||||
Member memberMock = mock();
|
||||
Interaction interactionMock = mock();
|
||||
|
||||
when(memberMock.getBasePermissions()).thenReturn(Mono.just(PermissionSet.none()));
|
||||
|
||||
when(interactionMock.getMember()).thenReturn(Optional.of(memberMock));
|
||||
|
||||
ButtonInteractionEvent buttonEventMock = CommonMocks.getButtonEventMock("permissionCheck", interactionMock);
|
||||
|
||||
LibraryWrapper wrapper = new Discord4JWrapper(null);
|
||||
Marinara marinara = Marinara.load(wrapper);
|
||||
marinara.getCheckRegistry().addCheck(new PermissionCheck());
|
||||
marinara.getRegistry().addInteractions(new TestButton());
|
||||
wrapper.handleInteraction(new ButtonInteractionMock("permissionCheck"));
|
||||
assertTrue(TestButton.didPermRun);
|
||||
TestButton.didPermRun = false;
|
||||
ServerMock.TESTPERMISSION = PermissionType.ATTACH_FILE;
|
||||
wrapper.handleInteraction(new ButtonInteractionMock("permissionCheck"));
|
||||
|
||||
wrapper.handleInteraction(buttonEventMock);
|
||||
assertFalse(TestButton.didPermRun);
|
||||
TestButton.didPermRun = false;
|
||||
|
||||
when(memberMock.getBasePermissions()).thenReturn(Mono.just(PermissionSet.of(Permission.ATTACH_FILES)));
|
||||
|
||||
wrapper.handleInteraction(buttonEventMock);
|
||||
assertTrue(TestButton.didPermRun);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,39 +1,46 @@
|
||||
package net.tomatentum.marinara.test.discord4j;
|
||||
|
||||
import org.javacord.api.DiscordApi;
|
||||
import org.javacord.api.DiscordApiBuilder;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.api.TestInstance.Lifecycle;
|
||||
|
||||
import discord4j.core.DiscordClient;
|
||||
import discord4j.core.GatewayDiscordClient;
|
||||
import discord4j.core.event.domain.interaction.ChatInputInteractionEvent;
|
||||
import discord4j.core.object.command.ApplicationCommandInteractionOption;
|
||||
import discord4j.core.object.command.ApplicationCommandInteractionOptionValue;
|
||||
import discord4j.core.object.command.ApplicationCommandOption.Type;
|
||||
import net.tomatentum.marinara.Marinara;
|
||||
import net.tomatentum.marinara.test.discord4j.mocks.SlashCommandInteractionMock;
|
||||
import net.tomatentum.marinara.wrapper.LibraryWrapper;
|
||||
import net.tomatentum.marinara.wrapper.javacord.JavacordWrapper;
|
||||
import net.tomatentum.marinara.wrapper.discord4j.Discord4JWrapper;
|
||||
@TestInstance(Lifecycle.PER_CLASS)
|
||||
public class SlashCommandTest {
|
||||
|
||||
String DISCORD_TOKEN = System.getenv("DISCORD_TEST_TOKEN");
|
||||
DiscordApi api;
|
||||
GatewayDiscordClient client;
|
||||
|
||||
@BeforeAll
|
||||
void setUp() {
|
||||
api = new DiscordApiBuilder()
|
||||
.setToken(DISCORD_TOKEN)
|
||||
.login().join();
|
||||
client = DiscordClient.create(DISCORD_TOKEN).login().block();
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
void tearDown() {
|
||||
api.disconnect();
|
||||
api = null;
|
||||
client.logout().block();
|
||||
client = null;
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSlashCommand() {
|
||||
Marinara marinara = Marinara.load(new JavacordWrapper(api));
|
||||
Marinara marinara = Marinara.load(new Discord4JWrapper(client));
|
||||
marinara.getRegistry().addInteractions(new TestCommand());
|
||||
marinara.getRegistry().registerCommands();
|
||||
System.out.println("Success!");
|
||||
@ -41,11 +48,25 @@ public class SlashCommandTest {
|
||||
|
||||
@Test
|
||||
void testSlashCommandExecution() {
|
||||
LibraryWrapper wrapper = new JavacordWrapper(api);
|
||||
ApplicationCommandInteractionOption optionMock = mock();
|
||||
ChatInputInteractionEvent eventMock = mock();
|
||||
|
||||
when(optionMock.getName()).thenReturn("foo");
|
||||
when(optionMock.getType()).thenReturn(Type.STRING);
|
||||
when(optionMock.getValue()).thenReturn(
|
||||
Optional.of(
|
||||
new ApplicationCommandInteractionOptionValue(null, null, Type.STRING.getValue(), "test", null)
|
||||
));
|
||||
|
||||
when(eventMock.getCommandName()).thenReturn("test");
|
||||
when(eventMock.getOptions()).thenReturn(Arrays.asList(optionMock));
|
||||
when(eventMock.getOption("foo")).thenReturn(Optional.of(optionMock));
|
||||
|
||||
LibraryWrapper wrapper = new Discord4JWrapper(client);
|
||||
Marinara marinara = Marinara.load(wrapper);
|
||||
marinara.getRegistry().addInteractions(new TestCommand());
|
||||
|
||||
wrapper.handleInteraction(new SlashCommandInteractionMock());
|
||||
wrapper.handleInteraction(eventMock);
|
||||
}
|
||||
|
||||
|
||||
|
@ -4,8 +4,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import org.javacord.api.interaction.AutocompleteInteraction;
|
||||
|
||||
import discord4j.core.event.domain.interaction.ChatInputAutoCompleteEvent;
|
||||
import net.tomatentum.marinara.interaction.InteractionHandler;
|
||||
import net.tomatentum.marinara.interaction.annotation.AutoComplete;
|
||||
import net.tomatentum.marinara.interaction.commands.annotation.SlashCommand;
|
||||
@ -14,10 +13,10 @@ public class TestAutocomplete implements InteractionHandler {
|
||||
|
||||
@SlashCommand(name = "test")
|
||||
@AutoComplete
|
||||
public void autocomplete(AutocompleteInteraction context, String value) {
|
||||
public void autocomplete(ChatInputAutoCompleteEvent context, String value) {
|
||||
System.out.println("Success!");
|
||||
assertEquals(value, "test");
|
||||
context.respondWithChoices(Collections.emptyList());
|
||||
context.respondWithSuggestions(Collections.emptyList());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,17 +2,17 @@ package net.tomatentum.marinara.test.discord4j;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
import org.javacord.api.entity.channel.TextChannel;
|
||||
import org.javacord.api.entity.message.Message;
|
||||
import org.javacord.api.entity.permission.PermissionType;
|
||||
import org.javacord.api.entity.server.Server;
|
||||
import org.javacord.api.entity.user.User;
|
||||
import org.javacord.api.interaction.ButtonInteraction;
|
||||
|
||||
import discord4j.core.event.domain.interaction.ButtonInteractionEvent;
|
||||
import discord4j.core.object.entity.Guild;
|
||||
import discord4j.core.object.entity.Member;
|
||||
import discord4j.core.object.entity.Message;
|
||||
import discord4j.core.object.entity.User;
|
||||
import discord4j.core.object.entity.channel.MessageChannel;
|
||||
import discord4j.rest.util.Permission;
|
||||
import net.tomatentum.marinara.interaction.InteractionHandler;
|
||||
import net.tomatentum.marinara.interaction.annotation.Button;
|
||||
import net.tomatentum.marinara.test.discord4j.TestInteractionCheck.TestCheck;
|
||||
import net.tomatentum.marinara.wrapper.javacord.checks.PermissionCheck.HasPermission;
|
||||
import net.tomatentum.marinara.wrapper.discord4j.checks.PermissionCheck.HasPermission;
|
||||
|
||||
public class TestButton implements InteractionHandler {
|
||||
|
||||
@ -20,11 +20,12 @@ public class TestButton implements InteractionHandler {
|
||||
public static boolean didRun = false;
|
||||
@Button("test")
|
||||
@TestCheck
|
||||
public void exec(ButtonInteraction interaction, TextChannel channel, Message message, User member, Server server) {
|
||||
public void exec(ButtonInteractionEvent interaction, MessageChannel channel, Message message, Member member, User user, Guild server) {
|
||||
assertNotNull(interaction);
|
||||
assertNotNull(channel);
|
||||
assertNotNull(message);
|
||||
assertNotNull(member);
|
||||
assertNotNull(user);
|
||||
assertNotNull(server);
|
||||
didRun = true;
|
||||
System.out.println("Success!");
|
||||
@ -33,8 +34,8 @@ public class TestButton implements InteractionHandler {
|
||||
public static boolean didPermRun = false;
|
||||
|
||||
@Button("permissionCheck")
|
||||
@HasPermission({PermissionType.ADMINISTRATOR})
|
||||
public void exec(ButtonInteraction interaction) {
|
||||
@HasPermission({Permission.ATTACH_FILES})
|
||||
public void exec(ButtonInteractionEvent interaction) {
|
||||
didPermRun = true;
|
||||
System.out.println("It worked!");
|
||||
}
|
||||
|
@ -2,8 +2,7 @@ package net.tomatentum.marinara.test.discord4j;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.javacord.api.interaction.SlashCommandInteraction;
|
||||
|
||||
import discord4j.core.event.domain.interaction.ChatInputInteractionEvent;
|
||||
import net.tomatentum.marinara.interaction.InteractionHandler;
|
||||
import net.tomatentum.marinara.interaction.commands.annotation.SlashCommand;
|
||||
import net.tomatentum.marinara.interaction.commands.annotation.SlashCommandOption;
|
||||
@ -25,7 +24,7 @@ public class TestCommand implements InteractionHandler {
|
||||
)
|
||||
}
|
||||
)
|
||||
public void exec(SlashCommandInteraction interaction, String test) {
|
||||
public void exec(ChatInputInteractionEvent event, String test) {
|
||||
assertEquals(test, "test");
|
||||
System.out.println("Success!");
|
||||
}
|
||||
|
@ -1,17 +0,0 @@
|
||||
package net.tomatentum.marinara.test.discord4j.mocks;
|
||||
|
||||
import discord4j.core.GatewayDiscordClient;
|
||||
import discord4j.core.event.domain.interaction.ChatInputAutoCompleteEvent;
|
||||
import discord4j.core.object.command.Interaction;
|
||||
import discord4j.gateway.ShardInfo;
|
||||
|
||||
public class AutocompleteInteractionMock extends ChatInputAutoCompleteEvent {
|
||||
|
||||
public AutocompleteInteractionMock(GatewayDiscordClient gateway, ShardInfo shardInfo, Interaction interaction) {
|
||||
super(gateway, shardInfo, interaction);
|
||||
//TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public static boolean didAutocompleteRun = false;
|
||||
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
package net.tomatentum.marinara.test.discord4j.mocks;
|
||||
|
||||
import discord4j.core.event.domain.interaction.ButtonInteractionEvent;
|
||||
import discord4j.core.object.command.Interaction;
|
||||
|
||||
public class ButtonInteractionMock extends ButtonInteractionEvent {
|
||||
|
||||
private String customId;
|
||||
|
||||
public ButtonInteractionMock(String customId) {
|
||||
super(null, null, null);
|
||||
this.customId = customId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCustomId() {
|
||||
return customId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Interaction getInteraction() {
|
||||
return new InteractionMock();
|
||||
}
|
||||
|
||||
}
|
@ -1,130 +0,0 @@
|
||||
package net.tomatentum.marinara.test.discord4j.mocks;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.reactivestreams.Publisher;
|
||||
|
||||
import discord4j.common.util.Snowflake;
|
||||
import discord4j.core.GatewayDiscordClient;
|
||||
import discord4j.core.object.entity.Message;
|
||||
import discord4j.core.object.entity.channel.MessageChannel;
|
||||
import discord4j.core.retriever.EntityRetrievalStrategy;
|
||||
import discord4j.core.spec.MessageCreateSpec;
|
||||
import discord4j.core.spec.legacy.LegacyMessageCreateSpec;
|
||||
import discord4j.rest.entity.RestChannel;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
public class ChannelMock implements MessageChannel {
|
||||
|
||||
@Override
|
||||
public Type getType() {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'getType'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Void> delete(String reason) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'delete'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public RestChannel getRestChannel() {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'getRestChannel'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Snowflake getId() {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'getId'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public GatewayDiscordClient getClient() {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'getClient'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Snowflake> getLastMessageId() {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'getLastMessageId'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Message> getLastMessage() {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'getLastMessage'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Message> getLastMessage(EntityRetrievalStrategy retrievalStrategy) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'getLastMessage'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Instant> getLastPinTimestamp() {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'getLastPinTimestamp'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Message> createMessage(Consumer<? super LegacyMessageCreateSpec> spec) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'createMessage'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Message> createMessage(MessageCreateSpec spec) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'createMessage'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Void> type() {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'type'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Flux<Long> typeUntil(Publisher<?> until) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'typeUntil'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Flux<Message> getMessagesBefore(Snowflake messageId) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'getMessagesBefore'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Flux<Message> getMessagesAfter(Snowflake messageId) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'getMessagesAfter'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Message> getMessageById(Snowflake id) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'getMessageById'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Message> getMessageById(Snowflake id, EntityRetrievalStrategy retrievalStrategy) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'getMessageById'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Flux<Message> getPinnedMessages() {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'getPinnedMessages'");
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package net.tomatentum.marinara.test.discord4j.mocks;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import discord4j.core.event.domain.interaction.ButtonInteractionEvent;
|
||||
import discord4j.core.object.command.Interaction;
|
||||
import discord4j.core.object.entity.Guild;
|
||||
import discord4j.core.object.entity.Member;
|
||||
import discord4j.core.object.entity.Message;
|
||||
import discord4j.core.object.entity.User;
|
||||
import discord4j.core.object.entity.channel.MessageChannel;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
public class CommonMocks {
|
||||
public static Interaction getInteractionMock() {
|
||||
Interaction interaction = mock(Interaction.class);
|
||||
Message message = mock(Message.class);
|
||||
MessageChannel channel = mock(MessageChannel.class);
|
||||
Guild guild = mock(Guild.class);
|
||||
User user = mock(User.class);
|
||||
Member member = mock(Member.class);
|
||||
|
||||
|
||||
when(interaction.getMessage()).thenReturn(Optional.of(message));
|
||||
when(interaction.getChannel()).thenReturn(Mono.just(channel));
|
||||
when(interaction.getGuild()).thenReturn(Mono.just(guild));
|
||||
when(interaction.getUser()).thenReturn(user);
|
||||
when(interaction.getMember()).thenReturn(Optional.of(member));
|
||||
|
||||
|
||||
return interaction;
|
||||
}
|
||||
|
||||
public static ButtonInteractionEvent getButtonEventMock(String customId) {
|
||||
ButtonInteractionEvent buttonEventMock = mock(ButtonInteractionEvent.class);
|
||||
|
||||
when(buttonEventMock.getCustomId()).thenReturn(customId);
|
||||
Interaction interactionMock = getInteractionMock();
|
||||
when(buttonEventMock.getInteraction()).thenReturn(interactionMock);
|
||||
Optional<Message> message = interactionMock.getMessage();
|
||||
when (buttonEventMock.getMessage()).thenReturn(message);
|
||||
return buttonEventMock;
|
||||
}
|
||||
|
||||
public static ButtonInteractionEvent getButtonEventMock(String customId, Interaction interaction) {
|
||||
ButtonInteractionEvent buttonEventMock = mock(ButtonInteractionEvent.class);
|
||||
|
||||
when(buttonEventMock.getCustomId()).thenReturn(customId);
|
||||
when(buttonEventMock.getInteraction()).thenReturn(interaction);
|
||||
return buttonEventMock;
|
||||
}
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
package net.tomatentum.marinara.test.discord4j.mocks;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import discord4j.core.object.command.Interaction;
|
||||
import discord4j.core.object.entity.Guild;
|
||||
import discord4j.core.object.entity.Message;
|
||||
import discord4j.core.object.entity.User;
|
||||
import discord4j.core.object.entity.channel.MessageChannel;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
public class InteractionMock extends Interaction
|
||||
{
|
||||
|
||||
public InteractionMock() {
|
||||
super(null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Message> getMessage() {
|
||||
//return Optional.of(new MessageMock());
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<MessageChannel> getChannel() {
|
||||
return Mono.just(new ChannelMock());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Guild> getGuild() {
|
||||
//return Mono.just(new ServerMock());
|
||||
return Mono.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getUser() {
|
||||
return new UserMock();
|
||||
}
|
||||
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
package net.tomatentum.marinara.test.discord4j.mocks;
|
||||
|
||||
import discord4j.core.event.domain.interaction.ChatInputInteractionEvent;
|
||||
|
||||
public class SlashCommandInteractionMock extends ChatInputInteractionEvent {
|
||||
|
||||
public SlashCommandInteractionMock() {
|
||||
super(null, null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "test";
|
||||
}
|
||||
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
package net.tomatentum.marinara.test.discord4j.mocks;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import discord4j.core.object.command.ApplicationCommandInteractionOption;
|
||||
import discord4j.core.object.command.ApplicationCommandInteractionOptionValue;
|
||||
import discord4j.core.object.command.ApplicationCommandOption.Type;
|
||||
|
||||
public class SlashCommandInteractionOptionMock extends ApplicationCommandInteractionOption {
|
||||
|
||||
public SlashCommandInteractionOptionMock() {
|
||||
super(null, null, null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "foo";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ApplicationCommandInteractionOptionValue> getValue() {
|
||||
return Optional.of(new ApplicationCommandInteractionOptionValue(null, null, Type.STRING.getValue(), "test", null));
|
||||
}
|
||||
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
package net.tomatentum.marinara.test.discord4j.mocks;
|
||||
|
||||
import discord4j.core.object.entity.User;
|
||||
|
||||
public class UserMock extends User {
|
||||
|
||||
public UserMock() {
|
||||
super(null, null);
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user