<commit_before>package org.innovateuk.ifs.project.status.security;

import org.innovateuk.ifs.sections.SectionAccess;
import org.innovateuk.ifs.user.resource.Role;
import org.innovateuk.ifs.user.resource.UserResource;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;

import java.util.List;
import java.util.function.Consumer;

import static java.util.Arrays.asList;
import static java.util.Arrays.stream;
import static java.util.Collections.singletonList;
import static org.innovateuk.ifs.project.constant.ProjectActivityStates.ACTION_REQUIRED;
import static org.innovateuk.ifs.sections.SectionAccess.ACCESSIBLE;
import static org.innovateuk.ifs.sections.SectionAccess.NOT_ACCESSIBLE;
import static org.innovateuk.ifs.user.builder.UserResourceBuilder.newUserResource;
import static org.innovateuk.ifs.user.resource.Role.*;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.*;

@RunWith(MockitoJUnitRunner.class)
public class SetupSectionsInternalUserTest {

    @Mock
    private SetupProgressChecker setupProgressChecker;

    @InjectMocks
    private SetupSectionInternalUser internalUser;

    @Test
    public void checkAccessToProjectDetailsSectionButProjectDetailsSectionIncomplete() {
        when(setupProgressChecker.isProjectDetailsSubmitted()).thenReturn(false);
        assertEquals(ACCESSIBLE, internalUser.canAccessProjectDetailsSection(null));
    }

    @Test
    public void checkAccessToMonitoringOfficerSectionHappyPath() {
        when(setupProgressChecker.canAccessMonitoringOfficer()).thenReturn(true);
        assertEquals(ACCESSIBLE, internalUser.canAccessMonitoringOfficerSection(newUserResource().withRoleGlobal(COMP_ADMIN).build()));

        verifyInteractions(
                SetupProgressChecker::canAccessMonitoringOfficer
        );
    }

    @Test
    public void supportUserCannotAccessIfMonitoringOfficerNotSubmitted() {

        when(setupProgressChecker.canAccessMonitoringOfficer()).thenReturn(true);
        when(setupProgressChecker.isMonitoringOfficerSubmitted()).thenReturn(false);
        assertEquals(NOT_ACCESSIBLE, internalUser.canAccessMonitoringOfficerSection(getSupportUser()));

        verifyInteractions(
                SetupProgressChecker::canAccessMonitoringOfficer,
                SetupProgressChecker::isMonitoringOfficerSubmitted<commit_msg>[IFS-11434] drop BaseUnitTest.java<commit_after>package org.innovateuk.ifs.project.status.security;

import org.innovateuk.ifs.sections.SectionAccess;
import org.innovateuk.ifs.user.resource.Role;
import org.innovateuk.ifs.user.resource.UserResource;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.MockitoJUnitRunner;

import java.util.List;
import java.util.function.Consumer;

import static java.util.Arrays.asList;
import static java.util.Arrays.stream;
import static java.util.Collections.singletonList;
import static org.innovateuk.ifs.project.constant.ProjectActivityStates.ACTION_REQUIRED;
import static org.innovateuk.ifs.sections.SectionAccess.ACCESSIBLE;
import static org.innovateuk.ifs.sections.SectionAccess.NOT_ACCESSIBLE;
import static org.innovateuk.ifs.user.builder.UserResourceBuilder.newUserResource;
import static org.innovateuk.ifs.user.resource.Role.*;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.*;

@RunWith(MockitoJUnitRunner.class)
public class SetupSectionsInternalUserTest {

    @Mock
    private SetupProgressChecker setupProgressChecker;

    @InjectMocks
    private SetupSectionInternalUser internalUser;

    @Before
    public void init() {
        MockitoAnnotations.initMocks(this);
    }

    @Test
    public void checkAccessToProjectDetailsSectionButProjectDetailsSectionIncomplete() {
        when(setupProgressChecker.isProjectDetailsSubmitted()).thenReturn(false);
        assertEquals(ACCESSIBLE, internalUser.canAccessProjectDetailsSection(null));
    }

    @Test
    public void checkAccessToMonitoringOfficerSectionHappyPath() {
        when(setupProgressChecker.canAccessMonitoringOfficer()).thenReturn(true);
        assertEquals(ACCESSIBLE, internalUser.canAccessMonitoringOfficerSection(newUserResource().withRoleGlobal(COMP_ADMIN).build()));

        verifyInteractions(
                SetupProgressChecker::canAccessMonitoringOfficer
        );
    }

    @Test
    public void supportUserCannotAccessIfMonitoringOfficerNotSubmitted() {

        when(setupProgressChecker.canAccessMonitoringOfficer()).thenReturn(true);
        when(setupProgressChecker.isMonitoringOfficerSubmitted()).thenReturn(false);
        assertEquals(NOT_ACCESSIBLE, internalUser.canAccessMonitoringOfficerSection(getSupportUser()));

        verifyInteractions(
                SetupProgressChecker::canAccessMonitoringOfficer,
                SetupProgressChecker::isMonitoringOfficerSubmitted
{'fraction_non_alphanumeric': 0.08539944903581267, 'fraction_numerical': 0.0009838646202282567, 'mean_word_length': 5.337905236907731, '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': '4561765', 'n_tokens_mistral': 1404, 'n_tokens_neox': 1384, 'n_words': 194}