add InteractionCheck test
This commit is contained in:
parent
b7333c2e5e
commit
33392b02fb
29
wrapper/javacord/src/test/java/net/tomatentum/marinara/test/InteractionCheckTest.java
Normal file
29
wrapper/javacord/src/test/java/net/tomatentum/marinara/test/InteractionCheckTest.java
Normal file
@ -0,0 +1,29 @@
|
||||
package net.tomatentum.marinara.test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
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.ButtonInteractionMock;
|
||||
import net.tomatentum.marinara.test.mocks.DiscordApiMock;
|
||||
import net.tomatentum.marinara.wrapper.LibraryWrapper;
|
||||
import net.tomatentum.marinara.wrapper.javacord.JavacordWrapper;
|
||||
|
||||
@TestInstance(Lifecycle.PER_CLASS)
|
||||
public class InteractionCheckTest {
|
||||
|
||||
@Test
|
||||
public void testInteractionCheck() {
|
||||
LibraryWrapper wrapper = new JavacordWrapper(new DiscordApiMock());
|
||||
Marinara marinara = Marinara.load(wrapper);
|
||||
marinara.getCheckRegistry().addCheck(new TestInteractionCheck());
|
||||
marinara.getRegistry().addInteractions(new TestButton());
|
||||
wrapper.handleInteraction(new ButtonInteractionMock());
|
||||
assertTrue(TestInteractionCheck.preExecuted);
|
||||
assertTrue(TestInteractionCheck.postExecuted);
|
||||
}
|
||||
|
||||
}
|
@ -10,12 +10,14 @@ import org.javacord.api.interaction.ButtonInteraction;
|
||||
|
||||
import net.tomatentum.marinara.interaction.InteractionHandler;
|
||||
import net.tomatentum.marinara.interaction.annotation.Button;
|
||||
import net.tomatentum.marinara.test.TestInteractionCheck.TestCheck;
|
||||
|
||||
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) {
|
||||
assertNotNull(interaction);
|
||||
assertNotNull(channel);
|
||||
|
38
wrapper/javacord/src/test/java/net/tomatentum/marinara/test/TestInteractionCheck.java
Normal file
38
wrapper/javacord/src/test/java/net/tomatentum/marinara/test/TestInteractionCheck.java
Normal file
@ -0,0 +1,38 @@
|
||||
package net.tomatentum.marinara.test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import net.tomatentum.marinara.checks.InteractionCheck;
|
||||
|
||||
public class TestInteractionCheck implements InteractionCheck<TestInteractionCheck.TestCheck> {
|
||||
|
||||
public static boolean preExecuted = false;
|
||||
public static boolean postExecuted = false;
|
||||
|
||||
@Target({ElementType.METHOD})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public static @interface TestCheck {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean preExec(Object context, TestCheck annotation) {
|
||||
assertNotNull(annotation);
|
||||
assertNotNull(context);
|
||||
preExecuted = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean postExec(Object context, TestCheck annotation) {
|
||||
assertNotNull(annotation);
|
||||
assertNotNull(context);
|
||||
postExecuted = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user