diff --git a/wrapper/javacord/src/test/java/net/tomatentum/marinara/test/SlashCommandTest.java b/wrapper/javacord/src/test/java/net/tomatentum/marinara/test/SlashCommandTest.java index 8f8ef5e..7498d33 100644 --- a/wrapper/javacord/src/test/java/net/tomatentum/marinara/test/SlashCommandTest.java +++ b/wrapper/javacord/src/test/java/net/tomatentum/marinara/test/SlashCommandTest.java @@ -2,24 +2,52 @@ package net.tomatentum.marinara.test; import org.javacord.api.DiscordApi; import org.javacord.api.DiscordApiBuilder; +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 net.tomatentum.marinara.Marinara; +import net.tomatentum.marinara.test.mocks.SlashCommandInteractionMock; +import net.tomatentum.marinara.wrapper.LibraryWrapper; import net.tomatentum.marinare.wrapper.javacord.JavacordWrapper; - +@TestInstance(Lifecycle.PER_CLASS) public class SlashCommandTest { String DISCORD_TOKEN = System.getenv("DISCORD_TEST_TOKEN"); + DiscordApi api; - @Test - public void testSlashCommand() { - DiscordApi api = new DiscordApiBuilder() + @BeforeAll + void setUp() { + api = new DiscordApiBuilder() .setToken(DISCORD_TOKEN) .login().join(); + } + + @AfterAll + void tearDown() { + api.disconnect(); + api = null; + } + + @Test + void testSlashCommand() { Marinara marinara = Marinara.load(new JavacordWrapper(api)); marinara.getRegistry().addInteractions(new TestCommand()); marinara.getRegistry().registerCommands(); - System.out.println("done"); + System.out.println("Success!"); + } + + @Test + void testSlashCommandExecution() { + LibraryWrapper wrapper = new JavacordWrapper(api); + Marinara marinara = Marinara.load(wrapper); + marinara.getRegistry().addInteractions(new TestCommand()); + + wrapper.handleInteraction(new SlashCommandInteractionMock()); } + + } diff --git a/wrapper/javacord/src/test/java/net/tomatentum/marinara/test/TestCommand.java b/wrapper/javacord/src/test/java/net/tomatentum/marinara/test/TestCommand.java index f65f323..f6710b0 100644 --- a/wrapper/javacord/src/test/java/net/tomatentum/marinara/test/TestCommand.java +++ b/wrapper/javacord/src/test/java/net/tomatentum/marinara/test/TestCommand.java @@ -1,5 +1,7 @@ package net.tomatentum.marinara.test; +import static org.junit.jupiter.api.Assertions.assertEquals; + import org.javacord.api.interaction.SlashCommandInteraction; import net.tomatentum.marinara.interaction.InteractionHandler; @@ -16,13 +18,14 @@ public class TestCommand implements InteractionHandler { }, options = { @SlashCommandOption( - name = "pommes", - description = "mit Fett", - type = SlashCommandOptionType.MENTIONABLE + name = "foo", + description = "foo bar is very fooby", + type = SlashCommandOptionType.STRING ) } ) - public void exec(SlashCommandInteraction interaction) { + public void exec(SlashCommandInteraction interaction, String test) { + assertEquals(test, "test"); System.out.println("Success!"); } } diff --git a/wrapper/javacord/src/test/java/net/tomatentum/marinara/test/mocks/SlashCommandInteractionMock.java b/wrapper/javacord/src/test/java/net/tomatentum/marinara/test/mocks/SlashCommandInteractionMock.java new file mode 100644 index 0000000..e4bc676 --- /dev/null +++ b/wrapper/javacord/src/test/java/net/tomatentum/marinara/test/mocks/SlashCommandInteractionMock.java @@ -0,0 +1,147 @@ +package net.tomatentum.marinara.test.mocks; + +import java.util.Arrays; +import java.util.Collections; +import java.util.EnumSet; +import java.util.List; +import java.util.Optional; +import java.util.concurrent.CompletableFuture; + +import org.javacord.api.DiscordApi; +import org.javacord.api.entity.channel.TextChannel; +import org.javacord.api.entity.message.component.HighLevelComponent; +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.DiscordLocale; +import org.javacord.api.interaction.InteractionType; +import org.javacord.api.interaction.SlashCommandInteraction; +import org.javacord.api.interaction.SlashCommandInteractionOption; +import org.javacord.api.interaction.callback.InteractionFollowupMessageBuilder; +import org.javacord.api.interaction.callback.InteractionImmediateResponseBuilder; +import org.javacord.api.interaction.callback.InteractionOriginalResponseUpdater; + +public class SlashCommandInteractionMock implements SlashCommandInteraction{ + + @Override + public long getCommandId() { + throw new UnsupportedOperationException("Unimplemented method 'getCommandId'"); + } + + @Override + public String getCommandIdAsString() { + throw new UnsupportedOperationException("Unimplemented method 'getCommandIdAsString'"); + } + + @Override + public String getCommandName() { + return "test"; + } + + @Override + public Optional getRegisteredCommandServerId() { + throw new UnsupportedOperationException("Unimplemented method 'getRegisteredCommandServerId'"); + } + + @Override + public long getApplicationId() { + throw new UnsupportedOperationException("Unimplemented method 'getApplicationId'"); + } + + @Override + public InteractionType getType() { + return InteractionType.APPLICATION_COMMAND; + } + + @Override + public InteractionImmediateResponseBuilder createImmediateResponder() { + throw new UnsupportedOperationException("Unimplemented method 'createImmediateResponder'"); + } + + @Override + public CompletableFuture respondLater() { + throw new UnsupportedOperationException("Unimplemented method 'respondLater'"); + } + + @Override + public CompletableFuture respondLater(boolean ephemeral) { + throw new UnsupportedOperationException("Unimplemented method 'respondLater'"); + } + + @Override + public CompletableFuture respondWithModal(String customId, String title, + List components) { + throw new UnsupportedOperationException("Unimplemented method 'respondWithModal'"); + } + + @Override + public InteractionFollowupMessageBuilder createFollowupMessageBuilder() { + throw new UnsupportedOperationException("Unimplemented method 'createFollowupMessageBuilder'"); + } + + @Override + public Optional getServer() { + throw new UnsupportedOperationException("Unimplemented method 'getServer'"); + } + + @Override + public Optional getChannel() { + throw new UnsupportedOperationException("Unimplemented method 'getChannel'"); + } + + @Override + public User getUser() { + throw new UnsupportedOperationException("Unimplemented method 'getUser'"); + } + + @Override + public String getToken() { + throw new UnsupportedOperationException("Unimplemented method 'getToken'"); + } + + @Override + public int getVersion() { + throw new UnsupportedOperationException("Unimplemented method 'getVersion'"); + } + + @Override + public DiscordLocale getLocale() { + throw new UnsupportedOperationException("Unimplemented method 'getLocale'"); + } + + @Override + public Optional getServerLocale() { + throw new UnsupportedOperationException("Unimplemented method 'getServerLocale'"); + } + + @Override + public Optional> getBotPermissions() { + throw new UnsupportedOperationException("Unimplemented method 'getBotPermissions'"); + } + + @Override + public DiscordApi getApi() { + throw new UnsupportedOperationException("Unimplemented method 'getApi'"); + } + + @Override + public long getId() { + throw new UnsupportedOperationException("Unimplemented method 'getId'"); + } + + @Override + public List getOptions() { + return Arrays.asList(new SlashCommandInteractionOptionMock()); + } + + @Override + public List getArguments() { + return Arrays.asList(new SlashCommandInteractionOptionMock()); + } + + @Override + public String getFullCommandName() { + return "test"; + } + +} diff --git a/wrapper/javacord/src/test/java/net/tomatentum/marinara/test/mocks/SlashCommandInteractionOptionMock.java b/wrapper/javacord/src/test/java/net/tomatentum/marinara/test/mocks/SlashCommandInteractionOptionMock.java new file mode 100644 index 0000000..4f077b1 --- /dev/null +++ b/wrapper/javacord/src/test/java/net/tomatentum/marinara/test/mocks/SlashCommandInteractionOptionMock.java @@ -0,0 +1,97 @@ +package net.tomatentum.marinara.test.mocks; + +import java.util.Collections; +import java.util.List; +import java.util.Optional; +import java.util.concurrent.CompletableFuture; + +import org.javacord.api.entity.Attachment; +import org.javacord.api.entity.Mentionable; +import org.javacord.api.entity.channel.ServerChannel; +import org.javacord.api.entity.permission.Role; +import org.javacord.api.entity.user.User; +import org.javacord.api.interaction.SlashCommandInteractionOption; + +public class SlashCommandInteractionOptionMock implements SlashCommandInteractionOption{ + + @Override + public List getArguments() { + return Collections.emptyList(); + } + + @Override + public String getName() { + return "foo"; + } + + @Override + public Optional isFocused() { + throw new UnsupportedOperationException("Unimplemented method 'isFocused'"); + } + + @Override + public Optional getStringRepresentationValue() { + throw new UnsupportedOperationException("Unimplemented method 'getStringRepresentationValue'"); + } + + @Override + public Optional getStringValue() { + return Optional.of("test"); + } + + @Override + public Optional getLongValue() { + throw new UnsupportedOperationException("Unimplemented method 'getLongValue'"); + } + + @Override + public Optional getBooleanValue() { + throw new UnsupportedOperationException("Unimplemented method 'getBooleanValue'"); + } + + @Override + public Optional getUserValue() { + throw new UnsupportedOperationException("Unimplemented method 'getUserValue'"); + } + + @Override + public Optional> requestUserValue() { + throw new UnsupportedOperationException("Unimplemented method 'requestUserValue'"); + } + + @Override + public Optional getChannelValue() { + throw new UnsupportedOperationException("Unimplemented method 'getChannelValue'"); + } + + @Override + public Optional getAttachmentValue() { + throw new UnsupportedOperationException("Unimplemented method 'getAttachmentValue'"); + } + + @Override + public Optional getRoleValue() { + throw new UnsupportedOperationException("Unimplemented method 'getRoleValue'"); + } + + @Override + public Optional getMentionableValue() { + throw new UnsupportedOperationException("Unimplemented method 'getMentionableValue'"); + } + + @Override + public Optional getDecimalValue() { + throw new UnsupportedOperationException("Unimplemented method 'getDecimalValue'"); + } + + @Override + public Optional> requestMentionableValue() { + throw new UnsupportedOperationException("Unimplemented method 'requestMentionableValue'"); + } + + @Override + public List getOptions() { + return Collections.emptyList(); + } + +}