Skip to content

Commit

Permalink
Move PrivilegeHelper mocks to final class
Browse files Browse the repository at this point in the history
As its utilities cause unwanted interactions
  • Loading branch information
freya022 committed Nov 15, 2024
1 parent 6ca350a commit a9e5f22
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public abstract class AbstractPrivilegeConfigTest extends IntegrationTest
@Mock
protected PrivilegeConfig config;

protected MockedStatic<PrivilegeHelper> privilegeHelperMock;
protected MockedStatic<CommandLevelChannelPermissionChecks> commandLevelChannelMock;
protected MockedStatic<AppLevelChannelPermissionChecks> appLevelChannelMock;
protected MockedStatic<CommandLevelUserOrRolePermissionChecks> commandLevelUserRoleMock;
Expand All @@ -79,7 +78,6 @@ void setupMocks()
when(member.getIdLong()).thenReturn(Constants.MINN_USER_ID);
when(member.getRoles()).thenReturn(Collections.singletonList(memberRole));

privilegeHelperMock = mockStatic(PrivilegeHelper.class);
commandLevelChannelMock = mockStatic(CommandLevelChannelPermissionChecks.class);
appLevelChannelMock = mockStatic(AppLevelChannelPermissionChecks.class);
commandLevelUserRoleMock = mockStatic(CommandLevelUserOrRolePermissionChecks.class);
Expand All @@ -93,7 +91,6 @@ void teardownMocks()
try
{
// Make sure all interactions were checked by the test subclasses
privilegeHelperMock.verifyNoMoreInteractions();
commandLevelChannelMock.verifyNoMoreInteractions();
appLevelChannelMock.verifyNoMoreInteractions();
commandLevelUserRoleMock.verifyNoMoreInteractions();
Expand All @@ -102,7 +99,6 @@ void teardownMocks()
}
finally
{
privilegeHelperMock.close();
commandLevelChannelMock.close();
appLevelChannelMock.close();
commandLevelUserRoleMock.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,37 @@
import net.dv8tion.jda.api.interactions.commands.DefaultMemberPermissions;
import net.dv8tion.jda.internal.utils.interactions.commands.CommandLevelChannelPermissionChecks;
import net.dv8tion.jda.internal.utils.interactions.commands.PrivilegeHelper;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.mockito.MockedStatic;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.*;

public class PrivilegeHelperPrivilegeTests extends AbstractPrivilegeConfigTest
{
protected MockedStatic<PrivilegeHelper> privilegeHelperMock;

@BeforeEach
void setupPrivilegeHelper()
{
privilegeHelperMock = mockStatic(PrivilegeHelper.class);
}

@AfterEach
void teardownPrivilegeHelper()
{
try
{
privilegeHelperMock.verifyNoMoreInteractions();
}
finally
{
privilegeHelperMock.close();
}
}

@Test
@DisplayName("Requires no permissions, forward to command level permission checks")
Expand Down

0 comments on commit a9e5f22

Please sign in to comment.