[AB-271] fixing tests

This commit is contained in:
Sheldan
2021-06-27 19:57:38 +02:00
parent 5a35137132
commit 67121b318d
20 changed files with 34 additions and 6 deletions

View File

@@ -43,7 +43,7 @@ public class UnSetExpRole extends AbstractConditionableCommand {
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
ARole role = (ARole) commandContext.getParameters().getParameters().get(0);
ARole actualRole = roleManagementService.findRole(role.getId());
if(!role.getServer().getId().equals(commandContext.getGuild().getIdLong())) {
if(!actualRole.getServer().getId().equals(commandContext.getGuild().getIdLong())) {
throw new EntityGuildMismatchException();
}
// do not check for the existence of the role, because if the role was deleted, users should be able

View File

@@ -3,6 +3,7 @@ package dev.sheldan.abstracto.experience.command;
import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.models.database.ARole;
import dev.sheldan.abstracto.core.models.database.AServer;
import dev.sheldan.abstracto.core.service.management.RoleManagementService;
import dev.sheldan.abstracto.core.test.command.CommandConfigValidator;
import dev.sheldan.abstracto.core.test.command.CommandTestUtilities;
@@ -47,6 +48,8 @@ public class DisableExpForRoleTest {
ARole actualRole = Mockito.mock(ARole.class);
when(parameterRole.getId()).thenReturn(5L);
CommandContext context = CommandTestUtilities.getWithParameters(Arrays.asList(parameterRole));
AServer server = Mockito.mock(AServer.class);
when(actualRole.getServer()).thenReturn(server);
when(roleManagementService.findRole(parameterRole.getId())).thenReturn(actualRole);
when(disabledExpRoleManagementService.isExperienceDisabledForRole(actualRole)).thenReturn(value);
CommandResult result = testUnit.execute(context);

View File

@@ -36,6 +36,7 @@ public class DisableExpGainTest {
CommandContext noParameters = CommandTestUtilities.getNoParameters();
AUserInAServer parameterUser = Mockito.mock(AUserInAServer.class);
Member member = Mockito.mock(Member.class);
when(member.getGuild()).thenReturn(noParameters.getGuild());
CommandContext context = CommandTestUtilities.enhanceWithParameters(noParameters, Arrays.asList(member));
when(userInServerManagementService.loadOrCreateUser(member)).thenReturn(parameterUser);
CommandResult result = testUnit.execute(context);

View File

@@ -3,6 +3,7 @@ package dev.sheldan.abstracto.experience.command;
import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.models.database.ARole;
import dev.sheldan.abstracto.core.models.database.AServer;
import dev.sheldan.abstracto.core.service.management.RoleManagementService;
import dev.sheldan.abstracto.core.test.command.CommandConfigValidator;
import dev.sheldan.abstracto.core.test.command.CommandTestUtilities;
@@ -44,8 +45,10 @@ public class EnableExpForRoleTest {
ARole roleParameter = Mockito.mock(ARole.class);
CommandContext context = CommandTestUtilities.getWithParameters(Arrays.asList(roleParameter));
Long roleId = 8L;
when(roleParameter.getId()).thenReturn(roleId);
AServer server = Mockito.mock(AServer.class);
ARole actualRole = Mockito.mock(ARole.class);
when(actualRole.getServer()).thenReturn(server);
when(roleParameter.getId()).thenReturn(roleId);
when(roleManagementService.findRole(roleId)).thenReturn(actualRole);
when(disabledExpRoleManagementService.isExperienceDisabledForRole(actualRole)).thenReturn(value);
CommandResult result = testUnit.execute(context);

View File

@@ -36,6 +36,7 @@ public class EnableExpGainTest {
CommandContext noParameters = CommandTestUtilities.getNoParameters();
AUserInAServer parameterUser = Mockito.mock(AUserInAServer.class);
Member member = Mockito.mock(Member.class);
when(member.getGuild()).thenReturn(noParameters.getGuild());
CommandContext context = CommandTestUtilities.enhanceWithParameters(noParameters, Arrays.asList(member));
when(userInServerManagementService.loadOrCreateUser(member)).thenReturn(parameterUser);
CommandResult result = testUnit.execute(context);

View File

@@ -73,6 +73,7 @@ public class RankTest {
when(userInServerManagementService.loadOrCreateUser(context.getAuthor())).thenReturn(aUserInAServer);
when(userExperienceService.getRankOfUserInServer(aUserInAServer)).thenReturn(leaderBoardEntry);
LeaderBoardEntryModel leaderBoardEntryModel = Mockito.mock(LeaderBoardEntryModel.class);
when(context.getAuthor().getGuild()).thenReturn(context.getGuild());
when(converter.fromLeaderBoardEntry(Arrays.asList(leaderBoardEntry))).thenReturn(CompletableFuture.completedFuture(Arrays.asList(leaderBoardEntryModel)));
when(self.renderAndSendRank(eq(context), any(RankModel.class), eq(leaderBoardEntryModel))).thenReturn(CompletableFuture.completedFuture(null));
CompletableFuture<CommandResult> result = testUnit.executeAsync(context);

View File

@@ -3,6 +3,7 @@ package dev.sheldan.abstracto.experience.command;
import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.models.database.ARole;
import dev.sheldan.abstracto.core.models.database.AServer;
import dev.sheldan.abstracto.core.service.management.RoleManagementService;
import dev.sheldan.abstracto.core.test.command.CommandConfigValidator;
import dev.sheldan.abstracto.core.test.command.CommandTestUtilities;
@@ -46,6 +47,8 @@ public class UnSetExpRoleTest {
CommandContext context = CommandTestUtilities.enhanceWithParameters(noParameters, Arrays.asList(changedRole));
when(context.getChannel().getIdLong()).thenReturn(CHANNEL_ID);
ARole actualRole = Mockito.mock(ARole.class);
AServer server = Mockito.mock(AServer.class);
when(actualRole.getServer()).thenReturn(server);
when(roleManagementService.findRole(changedRole.getId())).thenReturn(actualRole);
when(experienceRoleManagementService.getRoleInServerOptional(actualRole)).thenReturn(Optional.of(Mockito.mock(AExperienceRole.class)));
when(experienceRoleService.unsetRoles(actualRole, CHANNEL_ID)).thenReturn(CompletableFuture.completedFuture(null));