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:
Sheldan
2020-05-30 09:27:41 +02:00
parent 62de5c2255
commit 563564aabe
69 changed files with 2825 additions and 136 deletions

View File

@@ -1,5 +1,9 @@
package dev.sheldan.abstracto.core.command.condition;
import dev.sheldan.abstracto.core.command.config.Parameter;
import dev.sheldan.abstracto.core.command.exception.IncorrectParameter;
import dev.sheldan.abstracto.core.command.exception.InsufficientParameters;
import dev.sheldan.abstracto.core.command.execution.CommandContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -30,4 +34,35 @@ public abstract class AbstractConditionableCommand implements ConditionalCommand
public List<CommandCondition> getConditions() {
return new ArrayList<>(Arrays.asList(featureEnabledCondition, commandDisabledCondition, commandDisallowedCondition, featureModeCondition));
}
protected void checkParameters(CommandContext context) {
List<Parameter> parameters = getConfiguration().getParameters();
for (int i = 0; i < parameters.size(); i++) {
Parameter parameter = parameters.get(i);
Class desiredType = parameter.getType();
if(!parameter.isOptional()) {
checkMandatoryExp(context, i, parameter, desiredType);
} else {
checkOptionalParameter(context, i, parameter, desiredType);
}
}
}
private void checkOptionalParameter(CommandContext context, int i, Parameter parameter, Class desiredType) {
if(context.getParameters() != null && context.getParameters().getParameters() != null && context.getParameters().getParameters().size() >= i) {
boolean parameterIsPresent = i < context.getParameters().getParameters().size();
if(parameterIsPresent && !desiredType.isInstance(context.getParameters().getParameters().get(i))) {
throw new IncorrectParameter(this, desiredType, parameter.getName());
}
}
}
private void checkMandatoryExp(CommandContext context, int i, Parameter parameter, Class desiredType) {
if(context.getParameters() == null || context.getParameters().getParameters() == null || context.getParameters().getParameters().isEmpty() || i >= context.getParameters().getParameters().size()) {
throw new InsufficientParameters(this, parameter.getName());
}
if(!desiredType.isInstance(context.getParameters().getParameters().get(i))) {
throw new IncorrectParameter(this, desiredType, parameter.getName());
}
}
}

View File

@@ -12,8 +12,8 @@ public class IncorrectParameter extends AbstractoRunTimeException implements Tem
private final String parameterName;
private final Class clazz;
public IncorrectParameter(String s, Command command, Class expected, String parameterName) {
super(s);
public IncorrectParameter(Command command, Class expected, String parameterName) {
super("");
this.command = command;
this.parameterName = parameterName;
this.clazz = expected;

View File

@@ -13,8 +13,8 @@ public class InsufficientParameters extends AbstractoRunTimeException implements
private final transient Command command;
private final String parameterName;
public InsufficientParameters(String s, Command command, String parameterName) {
super(s);
public InsufficientParameters(Command command, String parameterName) {
super("");
this.command = command;
this.parameterName = parameterName;
}

View File

@@ -4,6 +4,7 @@ import dev.sheldan.abstracto.core.command.config.Parameters;
import dev.sheldan.abstracto.core.models.context.UserInitiatedServerContext;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
@@ -12,6 +13,7 @@ import net.dv8tion.jda.api.entities.TextChannel;
@Builder
@Getter
@Setter
public class CommandContext {
private TextChannel channel;
private Guild guild;

View File

@@ -94,16 +94,11 @@ public class AServer implements SnowFlake, Serializable {
if (o == null || getClass() != o.getClass()) return false;
AServer aServer = (AServer) o;
return Objects.equals(id, aServer.id) &&
Objects.equals(name, aServer.name) &&
Objects.equals(roles, aServer.roles) &&
Objects.equals(channels, aServer.channels) &&
Objects.equals(channelGroups, aServer.channelGroups) &&
Objects.equals(users, aServer.users) &&
Objects.equals(emotes, aServer.emotes);
Objects.equals(name, aServer.name);
}
@Override
public int hashCode() {
return Objects.hash(id, name, roles, channels, channelGroups, users, emotes);
return Objects.hash(id, name);
}
}