mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-04-07 17:44:34 +00:00
added tests for experience tracking module
refactored some things in experience tracking changed the paging behaviour for leader board and added check for negative numbers fixed rank not being correct for further pages added test-common module to have some common code für tests fixed command creation
This commit is contained in:
41
abstracto-application/test-commons/pom.xml
Normal file
41
abstracto-application/test-commons/pom.xml
Normal file
@@ -0,0 +1,41 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>abstracto-application</artifactId>
|
||||
<groupId>dev.sheldan.abstracto</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>test-commons</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>test-jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>dev.sheldan.abstracto.core</groupId>
|
||||
<artifactId>core-impl</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,65 @@
|
||||
package dev.sheldan.abstracto.test;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.database.*;
|
||||
import net.dv8tion.jda.api.entities.MessageType;
|
||||
import net.dv8tion.jda.api.entities.User;
|
||||
import net.dv8tion.jda.internal.JDAImpl;
|
||||
import net.dv8tion.jda.internal.entities.*;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class MockUtils {
|
||||
|
||||
private MockUtils() {
|
||||
|
||||
}
|
||||
|
||||
public static AUserInAServer getUserObject(Long id, AServer server) {
|
||||
AUser user = AUser.builder().id(id).build();
|
||||
AUserInAServer createdUser = AUserInAServer.builder().userReference(user).serverReference(server).build();
|
||||
server.getUsers().add(createdUser);
|
||||
return createdUser;
|
||||
}
|
||||
|
||||
public static AServer getServer(Long id){
|
||||
return AServer.builder().id(id).build();
|
||||
}
|
||||
|
||||
public static AServer getServer() {
|
||||
return getServer(2L);
|
||||
}
|
||||
|
||||
public static GuildImpl getGuild(AServer serverToUse, JDAImpl jda) {
|
||||
return new GuildImpl(jda, serverToUse.getId());
|
||||
}
|
||||
|
||||
public static MemberImpl getMockedMember(AServer serverToUse, AUserInAServer user, JDAImpl jda) {
|
||||
UserImpl jdaUser = new UserImpl(user.getUserReference().getId(), jda);
|
||||
GuildImpl jdaGuild = new GuildImpl(jda, serverToUse.getId());
|
||||
return new MemberImpl(jdaGuild, jdaUser);
|
||||
}
|
||||
|
||||
public static AChannel getTextChannel(AServer server, Long id) {
|
||||
return AChannel.builder().id(id).server(server).deleted(false).type(AChannelType.TEXT).build();
|
||||
}
|
||||
|
||||
public static TextChannelImpl getMockedTextChannel(Long id, GuildImpl guild) {
|
||||
return new TextChannelImpl(id, guild);
|
||||
}
|
||||
|
||||
public static ARole getRole(Long id, AServer server) {
|
||||
return ARole.builder().server(server).id(id).build();
|
||||
}
|
||||
|
||||
public static ReceivedMessage buildMockedMessage(long messageId, String text, MemberImpl member) {
|
||||
Instant dateObj = Instant.ofEpochSecond(1590615937);
|
||||
OffsetDateTime messageDate = OffsetDateTime.ofInstant(dateObj, ZoneId.systemDefault());
|
||||
User user = member != null ? member.getUser() : null;
|
||||
return new ReceivedMessage(messageId, null, MessageType.DEFAULT, false, false
|
||||
, null, null, false, false, text, "nonce", user, member, null, messageDate,
|
||||
new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), 0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
package dev.sheldan.abstracto.test.command;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.Command;
|
||||
import dev.sheldan.abstracto.core.command.config.Parameters;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.core.command.execution.ResultState;
|
||||
import dev.sheldan.abstracto.core.models.context.UserInitiatedServerContext;
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
||||
import dev.sheldan.abstracto.test.MockUtils;
|
||||
import net.dv8tion.jda.internal.JDAImpl;
|
||||
import net.dv8tion.jda.internal.entities.GuildImpl;
|
||||
import net.dv8tion.jda.internal.entities.MemberImpl;
|
||||
import net.dv8tion.jda.internal.entities.TextChannelImpl;
|
||||
import org.junit.Assert;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandTestUtilities {
|
||||
|
||||
private CommandTestUtilities() {
|
||||
|
||||
}
|
||||
|
||||
public static void executeNoParametersTest(Command com, JDAImpl jda) {
|
||||
CommandContext context = CommandTestUtilities.getNoParameters(jda);
|
||||
com.execute(context);
|
||||
}
|
||||
|
||||
public static void executeWrongParametersTest(Command com, JDAImpl jda) {
|
||||
executeWrongParametersTest(com, jda, "");
|
||||
}
|
||||
|
||||
public static void executeWrongParametersTest(Command com, JDAImpl jda, Object value) {
|
||||
CommandContext context = CommandTestUtilities.getWithParameters(jda, Arrays.asList(value));
|
||||
com.execute(context);
|
||||
}
|
||||
|
||||
public static CommandContext getNoParameters(JDAImpl jda) {
|
||||
AServer server = MockUtils.getServer();
|
||||
AUserInAServer author = MockUtils.getUserObject(3L, server);
|
||||
CommandContext context = CommandContext
|
||||
.builder()
|
||||
.build();
|
||||
GuildImpl guild = MockUtils.getGuild(server, jda);
|
||||
context.setGuild(guild);
|
||||
MemberImpl member = MockUtils.getMockedMember(server, author, jda);
|
||||
context.setAuthor(member);
|
||||
long channelId = 4L;
|
||||
TextChannelImpl mockedTextChannel = MockUtils.getMockedTextChannel(channelId, guild);
|
||||
UserInitiatedServerContext userInitiatedContext = UserInitiatedServerContext
|
||||
.builder()
|
||||
.server(server)
|
||||
.guild(guild)
|
||||
.aUserInAServer(author)
|
||||
.member(member)
|
||||
.user(author.getUserReference())
|
||||
.channel(MockUtils.getTextChannel(server, channelId))
|
||||
.messageChannel(mockedTextChannel)
|
||||
.build();
|
||||
context.setUserInitiatedContext(userInitiatedContext);
|
||||
context.setJda(jda);
|
||||
context.setChannel(mockedTextChannel);
|
||||
context.setParameters(Parameters.builder().parameters(new ArrayList<>()).build());
|
||||
context.setMessage(MockUtils.buildMockedMessage(3L, "text", member));
|
||||
return context;
|
||||
}
|
||||
|
||||
public static CommandContext getWithParameters(JDAImpl jda, List<Object> parameters) {
|
||||
CommandContext context = getNoParameters(jda);
|
||||
context.getParameters().getParameters().addAll(parameters);
|
||||
return context;
|
||||
}
|
||||
|
||||
public static CommandContext enhanceWithParameters(CommandContext context, List<Object> parameters) {
|
||||
context.getParameters().getParameters().addAll(parameters);
|
||||
return context;
|
||||
}
|
||||
|
||||
public static void checkSuccessfulCompletion(CommandResult result){
|
||||
Assert.assertEquals(ResultState.SUCCESSFUL, result.getResult());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user