<commit_before>package com.imcode.imcms.domain.service.core;

import com.imcode.imcms.domain.exception.UserNotExistsException;
import com.imcode.imcms.domain.service.UserService;
import com.imcode.imcms.model.RestrictedPermission;
import com.imcode.imcms.persistence.entity.DocumentRoles;
import com.imcode.imcms.persistence.entity.Meta;
import com.imcode.imcms.persistence.entity.Meta.Permission;
import com.imcode.imcms.persistence.entity.RestrictedPermissionJPA;
import com.imcode.imcms.persistence.repository.DocumentRolesRepository;
import com.imcode.imcms.security.AccessType;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

import java.util.*;

import static org.hamcrest.core.Is.is;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;

@RunWith(MockitoJUnitRunner.class)
public class DefaultAccessServiceTest {

    private static final int userId = 1;
    private static final int documentId = 1001;

    @Mock
    private UserService userService;

    @Mock
    private DocumentRolesRepository documentRolesRepository;

    @InjectMocks
    private DefaultAccessService accessService;

    @Test
    public void hasUserEditAccess_When_DocumentNotExist_Expect_False() {
        testHasUserEditAccessWhenDocumentRolesListIsEmpty();
    }

    @Test
    public void hasUserEditAccess_When_UserHasNoRoleForEditAccess_Expect_False() {
        testHasUserEditAccessWhenDocumentRolesListIsEmpty();
    }

    @Test
    public void hasUserEditAccess_When_UserNotExist_Expect_False() {
        when(userService.getUser(userId)).thenThrow(new UserNotExistsException(userId));

        final boolean hasUserEditAccess = accessService.hasUserEditAccess(userId, documentId, AccessType.IMAGE);

        assertFalse(hasUserEditAccess);

        verify(userService, times(1)).getUser(userId);<commit_msg>IMCMS-233 - Apply new UI to the admin panel and editors: - Fixed tests.<commit_after>package com.imcode.imcms.domain.service.core;

import com.imcode.imcms.domain.exception.UserNotExistsException;
import com.imcode.imcms.domain.service.UserService;
import com.imcode.imcms.model.RestrictedPermission;
import com.imcode.imcms.persistence.entity.DocumentRoles;
import com.imcode.imcms.persistence.entity.Meta;
import com.imcode.imcms.persistence.entity.Meta.Permission;
import com.imcode.imcms.persistence.entity.RestrictedPermissionJPA;
import com.imcode.imcms.persistence.repository.DocumentRolesRepository;
import com.imcode.imcms.security.AccessType;
import imcode.server.Imcms;
import imcode.server.user.UserDomainObject;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

import java.util.*;

import static org.hamcrest.core.Is.is;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;

@RunWith(MockitoJUnitRunner.class)
public class DefaultAccessServiceTest {

    private static final int userId = 1;
    private static final int documentId = 1001;

    @Mock
    private UserService userService;

    @Mock
    private DocumentRolesRepository documentRolesRepository;

    @InjectMocks
    private DefaultAccessService accessService;

    @Before
    public void setUp() {
        final UserDomainObject user = new UserDomainObject();
        Imcms.setUser(user);
    }

    @After
    public void tearDown() {
        Imcms.removeUser();
    }

    @Test
    public void hasUserEditAccess_When_DocumentNotExist_Expect_False() {
        testHasUserEditAccessWhenDocumentRolesListIsEmpty();
    }

    @Test
    public void hasUserEditAccess_When_UserHasNoRoleForEditAccess_Expect_False() {
        testHasUserEditAccessWhenDocumentRolesListIsEmpty();
    }

    @Test
    public void hasUserEditAccess_When_UserNotExist_Expect_False() {
        when(userService.getUser(userId)).thenThrow(new UserNotExistsException(userId));

        final boolean hasUserEditAccess = accessService.hasUserEditAccess(userId, documentId, AccessType.IMAGE);

        assertFalse(hasUserEditAccess);

        verify(userService, times(1)).getUser(userId);
{'fraction_non_alphanumeric': 0.08658823529411765, 'fraction_numerical': 0.0035294117647058825, 'mean_word_length': 4.895977808599167, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4943595', 'n_tokens_mistral': 1294, 'n_tokens_neox': 1255, 'n_words': 221}