add Discord4J Wrapper #14
@ -7,6 +7,7 @@ log4j = "2.24.1"
|
|||||||
javacord = "3.8.0"
|
javacord = "3.8.0"
|
||||||
discord4j = "3.2.7"
|
discord4j = "3.2.7"
|
||||||
geantyref = "2.0.0"
|
geantyref = "2.0.0"
|
||||||
|
mockito = "5.15.2"
|
||||||
|
|
||||||
[libraries]
|
[libraries]
|
||||||
junit-jupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit-jupiter" }
|
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"}
|
javacord = { module = "org.javacord:javacord", version.ref = "javacord"}
|
||||||
discord4j = { module = "com.discord4j:discord4j-core", version.ref = "discord4j"}
|
discord4j = { module = "com.discord4j:discord4j-core", version.ref = "discord4j"}
|
||||||
geantyref = { module = "io.leangen.geantyref:geantyref", version.ref = "geantyref"}
|
geantyref = { module = "io.leangen.geantyref:geantyref", version.ref = "geantyref"}
|
||||||
|
mockito = {module = "org.mockito:mockito-core", version.ref = "mockito"}
|
||||||
|
@ -18,11 +18,12 @@ repositories {
|
|||||||
dependencies {
|
dependencies {
|
||||||
// Use JUnit Jupiter for testing.
|
// Use JUnit Jupiter for testing.
|
||||||
testImplementation(libs.junit.jupiter)
|
testImplementation(libs.junit.jupiter)
|
||||||
|
testImplementation(libs.mockito)
|
||||||
|
|
||||||
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
|
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
|
||||||
implementation(libs.log4j)
|
implementation(libs.log4j)
|
||||||
implementation(libs.discord4j) {
|
implementation(libs.discord4j) {
|
||||||
exclude(module="discord4j-voice")
|
// exclude(module="discord4j-voice")
|
||||||
}
|
}
|
||||||
implementation(libs.geantyref)
|
implementation(libs.geantyref)
|
||||||
implementation(project(":lib"))
|
implementation(project(":lib"))
|
||||||
|
@ -1,23 +1,45 @@
|
|||||||
package net.tomatentum.marinara.test.discord4j;
|
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 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.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.LibraryWrapper;
|
||||||
import net.tomatentum.marinara.wrapper.javacord.JavacordWrapper;
|
import net.tomatentum.marinara.wrapper.discord4j.Discord4JWrapper;
|
||||||
|
|
||||||
public class AutoCompleteTest {
|
public class AutoCompleteTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAutocomplete() {
|
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 marinara = Marinara.load(wrapper);
|
||||||
marinara.getRegistry().addInteractions(new TestAutocomplete());
|
marinara.getRegistry().addInteractions(new TestAutocomplete());
|
||||||
wrapper.handleInteraction(new AutocompleteInteractionMock());
|
wrapper.handleInteraction(autoCompleteEventMock);
|
||||||
assertTrue(AutocompleteInteractionMock.didAutocompleteRun);
|
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;
|
||||||
import org.junit.jupiter.api.TestInstance.Lifecycle;
|
import org.junit.jupiter.api.TestInstance.Lifecycle;
|
||||||
|
|
||||||
|
import discord4j.core.event.domain.interaction.ButtonInteractionEvent;
|
||||||
import net.tomatentum.marinara.Marinara;
|
import net.tomatentum.marinara.Marinara;
|
||||||
import net.tomatentum.marinara.test.discord4j.mocks.ButtonInteractionMock;
|
import net.tomatentum.marinara.test.discord4j.mocks.CommonMocks;
|
||||||
import net.tomatentum.marinara.test.discord4j.mocks.DiscordApiMock;
|
|
||||||
import net.tomatentum.marinara.wrapper.LibraryWrapper;
|
import net.tomatentum.marinara.wrapper.LibraryWrapper;
|
||||||
import net.tomatentum.marinara.wrapper.javacord.JavacordWrapper;
|
import net.tomatentum.marinara.wrapper.discord4j.Discord4JWrapper;
|
||||||
|
|
||||||
@TestInstance(Lifecycle.PER_CLASS)
|
@TestInstance(Lifecycle.PER_CLASS)
|
||||||
public class ButtonTest {
|
public class ButtonTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testButtonExecution() {
|
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 marinara = Marinara.load(wrapper);
|
||||||
marinara.getRegistry().addInteractions(new TestButton());
|
marinara.getRegistry().addInteractions(new TestButton());
|
||||||
wrapper.handleInteraction(new ButtonInteractionMock("test"));
|
wrapper.handleInteraction(buttonEventMock);
|
||||||
assertTrue(TestButton.didRun);
|
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.assertFalse;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
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.Test;
|
||||||
import org.junit.jupiter.api.TestInstance;
|
import org.junit.jupiter.api.TestInstance;
|
||||||
import org.junit.jupiter.api.TestInstance.Lifecycle;
|
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.Marinara;
|
||||||
import net.tomatentum.marinara.test.discord4j.mocks.ButtonInteractionMock;
|
import net.tomatentum.marinara.test.discord4j.mocks.CommonMocks;
|
||||||
import net.tomatentum.marinara.test.discord4j.mocks.DiscordApiMock;
|
|
||||||
import net.tomatentum.marinara.test.discord4j.mocks.ServerMock;
|
|
||||||
import net.tomatentum.marinara.wrapper.LibraryWrapper;
|
import net.tomatentum.marinara.wrapper.LibraryWrapper;
|
||||||
import net.tomatentum.marinara.wrapper.javacord.JavacordWrapper;
|
import net.tomatentum.marinara.wrapper.discord4j.Discord4JWrapper;
|
||||||
import net.tomatentum.marinara.wrapper.javacord.checks.PermissionCheck;
|
import net.tomatentum.marinara.wrapper.discord4j.checks.PermissionCheck;
|
||||||
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
@TestInstance(Lifecycle.PER_CLASS)
|
@TestInstance(Lifecycle.PER_CLASS)
|
||||||
public class InteractionCheckTest {
|
public class InteractionCheckTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInteractionCheck() {
|
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 marinara = Marinara.load(wrapper);
|
||||||
marinara.getCheckRegistry().addCheck(new TestInteractionCheck());
|
marinara.getCheckRegistry().addCheck(new TestInteractionCheck());
|
||||||
marinara.getRegistry().addInteractions(new TestButton());
|
marinara.getRegistry().addInteractions(new TestButton());
|
||||||
wrapper.handleInteraction(new ButtonInteractionMock("test"));
|
wrapper.handleInteraction(buttonEventMock);
|
||||||
|
|
||||||
assertTrue(TestInteractionCheck.preExecuted);
|
assertTrue(TestInteractionCheck.preExecuted);
|
||||||
assertTrue(TestInteractionCheck.postExecuted);
|
assertTrue(TestInteractionCheck.postExecuted);
|
||||||
|
assertTrue(TestButton.didRun);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPermissionCheck() {
|
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 marinara = Marinara.load(wrapper);
|
||||||
marinara.getCheckRegistry().addCheck(new PermissionCheck());
|
marinara.getCheckRegistry().addCheck(new PermissionCheck());
|
||||||
marinara.getRegistry().addInteractions(new TestButton());
|
marinara.getRegistry().addInteractions(new TestButton());
|
||||||
wrapper.handleInteraction(new ButtonInteractionMock("permissionCheck"));
|
|
||||||
assertTrue(TestButton.didPermRun);
|
wrapper.handleInteraction(buttonEventMock);
|
||||||
TestButton.didPermRun = false;
|
|
||||||
ServerMock.TESTPERMISSION = PermissionType.ATTACH_FILE;
|
|
||||||
wrapper.handleInteraction(new ButtonInteractionMock("permissionCheck"));
|
|
||||||
assertFalse(TestButton.didPermRun);
|
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;
|
package net.tomatentum.marinara.test.discord4j;
|
||||||
|
|
||||||
import org.javacord.api.DiscordApi;
|
import static org.mockito.Mockito.mock;
|
||||||
import org.javacord.api.DiscordApiBuilder;
|
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.AfterAll;
|
||||||
import org.junit.jupiter.api.BeforeAll;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.TestInstance;
|
import org.junit.jupiter.api.TestInstance;
|
||||||
import org.junit.jupiter.api.TestInstance.Lifecycle;
|
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.Marinara;
|
||||||
import net.tomatentum.marinara.test.discord4j.mocks.SlashCommandInteractionMock;
|
|
||||||
import net.tomatentum.marinara.wrapper.LibraryWrapper;
|
import net.tomatentum.marinara.wrapper.LibraryWrapper;
|
||||||
import net.tomatentum.marinara.wrapper.javacord.JavacordWrapper;
|
import net.tomatentum.marinara.wrapper.discord4j.Discord4JWrapper;
|
||||||
@TestInstance(Lifecycle.PER_CLASS)
|
@TestInstance(Lifecycle.PER_CLASS)
|
||||||
public class SlashCommandTest {
|
public class SlashCommandTest {
|
||||||
|
|
||||||
String DISCORD_TOKEN = System.getenv("DISCORD_TEST_TOKEN");
|
String DISCORD_TOKEN = System.getenv("DISCORD_TEST_TOKEN");
|
||||||
DiscordApi api;
|
GatewayDiscordClient client;
|
||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
void setUp() {
|
void setUp() {
|
||||||
api = new DiscordApiBuilder()
|
client = DiscordClient.create(DISCORD_TOKEN).login().block();
|
||||||
.setToken(DISCORD_TOKEN)
|
|
||||||
.login().join();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterAll
|
@AfterAll
|
||||||
void tearDown() {
|
void tearDown() {
|
||||||
api.disconnect();
|
client.logout().block();
|
||||||
api = null;
|
client = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testSlashCommand() {
|
void testSlashCommand() {
|
||||||
Marinara marinara = Marinara.load(new JavacordWrapper(api));
|
Marinara marinara = Marinara.load(new Discord4JWrapper(client));
|
||||||
marinara.getRegistry().addInteractions(new TestCommand());
|
marinara.getRegistry().addInteractions(new TestCommand());
|
||||||
marinara.getRegistry().registerCommands();
|
marinara.getRegistry().registerCommands();
|
||||||
System.out.println("Success!");
|
System.out.println("Success!");
|
||||||
@ -41,11 +48,25 @@ public class SlashCommandTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testSlashCommandExecution() {
|
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 marinara = Marinara.load(wrapper);
|
||||||
marinara.getRegistry().addInteractions(new TestCommand());
|
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 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.InteractionHandler;
|
||||||
import net.tomatentum.marinara.interaction.annotation.AutoComplete;
|
import net.tomatentum.marinara.interaction.annotation.AutoComplete;
|
||||||
import net.tomatentum.marinara.interaction.commands.annotation.SlashCommand;
|
import net.tomatentum.marinara.interaction.commands.annotation.SlashCommand;
|
||||||
@ -14,10 +13,10 @@ public class TestAutocomplete implements InteractionHandler {
|
|||||||
|
|
||||||
@SlashCommand(name = "test")
|
@SlashCommand(name = "test")
|
||||||
@AutoComplete
|
@AutoComplete
|
||||||
public void autocomplete(AutocompleteInteraction context, String value) {
|
public void autocomplete(ChatInputAutoCompleteEvent context, String value) {
|
||||||
System.out.println("Success!");
|
System.out.println("Success!");
|
||||||
assertEquals(value, "test");
|
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 static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
|
||||||
import org.javacord.api.entity.channel.TextChannel;
|
import discord4j.core.event.domain.interaction.ButtonInteractionEvent;
|
||||||
import org.javacord.api.entity.message.Message;
|
import discord4j.core.object.entity.Guild;
|
||||||
import org.javacord.api.entity.permission.PermissionType;
|
import discord4j.core.object.entity.Member;
|
||||||
import org.javacord.api.entity.server.Server;
|
import discord4j.core.object.entity.Message;
|
||||||
import org.javacord.api.entity.user.User;
|
import discord4j.core.object.entity.User;
|
||||||
import org.javacord.api.interaction.ButtonInteraction;
|
import discord4j.core.object.entity.channel.MessageChannel;
|
||||||
|
import discord4j.rest.util.Permission;
|
||||||
import net.tomatentum.marinara.interaction.InteractionHandler;
|
import net.tomatentum.marinara.interaction.InteractionHandler;
|
||||||
import net.tomatentum.marinara.interaction.annotation.Button;
|
import net.tomatentum.marinara.interaction.annotation.Button;
|
||||||
import net.tomatentum.marinara.test.discord4j.TestInteractionCheck.TestCheck;
|
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 {
|
public class TestButton implements InteractionHandler {
|
||||||
|
|
||||||
@ -20,11 +20,12 @@ public class TestButton implements InteractionHandler {
|
|||||||
public static boolean didRun = false;
|
public static boolean didRun = false;
|
||||||
@Button("test")
|
@Button("test")
|
||||||
@TestCheck
|
@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(interaction);
|
||||||
assertNotNull(channel);
|
assertNotNull(channel);
|
||||||
assertNotNull(message);
|
assertNotNull(message);
|
||||||
assertNotNull(member);
|
assertNotNull(member);
|
||||||
|
assertNotNull(user);
|
||||||
assertNotNull(server);
|
assertNotNull(server);
|
||||||
didRun = true;
|
didRun = true;
|
||||||
System.out.println("Success!");
|
System.out.println("Success!");
|
||||||
@ -33,8 +34,8 @@ public class TestButton implements InteractionHandler {
|
|||||||
public static boolean didPermRun = false;
|
public static boolean didPermRun = false;
|
||||||
|
|
||||||
@Button("permissionCheck")
|
@Button("permissionCheck")
|
||||||
@HasPermission({PermissionType.ADMINISTRATOR})
|
@HasPermission({Permission.ATTACH_FILES})
|
||||||
public void exec(ButtonInteraction interaction) {
|
public void exec(ButtonInteractionEvent interaction) {
|
||||||
didPermRun = true;
|
didPermRun = true;
|
||||||
System.out.println("It worked!");
|
System.out.println("It worked!");
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,7 @@ package net.tomatentum.marinara.test.discord4j;
|
|||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
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.InteractionHandler;
|
||||||
import net.tomatentum.marinara.interaction.commands.annotation.SlashCommand;
|
import net.tomatentum.marinara.interaction.commands.annotation.SlashCommand;
|
||||||
import net.tomatentum.marinara.interaction.commands.annotation.SlashCommandOption;
|
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");
|
assertEquals(test, "test");
|
||||||
System.out.println("Success!");
|
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