<commit_before>package io.corbel.iam.service;

import static org.fest.assertions.api.Assertions.assertThat;
import static org.mockito.Mockito.*;

import java.util.*;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.dao.DataIntegrityViolationException;

import io.corbel.iam.exception.GroupAlreadyExistsException;
import io.corbel.iam.exception.NotExistentScopeException;
import io.corbel.iam.model.Group;
import io.corbel.iam.model.Scope;
import io.corbel.iam.repository.GroupRepository;
import io.corbel.iam.repository.ScopeRepository;
import io.corbel.lib.queries.request.ResourceQuery;

@RunWith(MockitoJUnitRunner.class) public class DefaultGroupServiceTest {

    private static final String ID = "id";
    private static final String NEW_ID = "newId";
    private static final String NAME = "name";
    private static final String DOMAIN = "domain";

    public static final String SCOPE_1 = "scope1";
    public static final String SCOPE_2 = "scope2";
    public static final String SCOPE_3 = "scope3";

    private static final Set<String> SCOPES = new HashSet<>(Arrays.asList(SCOPE_1, SCOPE_2));

    @Mock private GroupRepository groupRepositoryMock;
    @Mock
    private ScopeRepository scopeRepositoryMock;

    private GroupService groupService;

    @Before
    public void setUp() {
        groupService = new DefaultGroupService(groupRepositoryMock, scopeRepositoryMock);
    }

    @Test
    public void getAllGroupsTest() {
        Group group = getGroup();

        List<ResourceQuery> resourceQueries = Collections.emptyList();

        when(groupRepositoryMock.findByDomain(DOMAIN, resourceQueries, null, null)).thenReturn(Collections.singletonList(group));

        List<Group> groups = groupService.getAll(DOMAIN, resourceQueries, null, null);

        assertThat(groups).hasSize(1);
        assertThat(groups).contains(group);

        verify(groupRepositoryMock).findByDomain(DOMAIN, resourceQueries, null, null);
        verifyNoMoreInteractions(groupRepositoryMock);
    }

    @Test
    public void getGroupTest() {
        Group expectedGroup = getGroup();

        when(groupRepositoryMock.findByNameAndDomain(ID, DOMAIN)).thenReturn(expectedGroup);

        Optional<Group> group = groupService.getById(ID, DOMAIN);

        assertThat(group.isPresent()).isTrue();

        assertThat(group.get()).isEqualTo(expectedGroup);

        verify(groupRepositoryMock).findByNameAndDomain(ID, DOMAIN);
        verifyNoMoreInteractions(groupRepositoryMock);
    }

    @Test
    public void getNullGroupTest() {
        Optional<Group> group = groupService.getById(ID, DOMAIN);

        assertThat(group.isPresent()).isFalse();

        verify(groupRepositoryMock).findByNameAndDomain(ID, DOMAIN);
        verifyNoMoreInteractions(groupRepositoryMock);
    }

    @Test
    public void getGroupWithoutDomainTest() {
        Group expectedGroup = getGroup();
<commit_msg>fix test<commit_after>package io.corbel.iam.service;

import static org.fest.assertions.api.Assertions.assertThat;
import static org.mockito.Mockito.*;

import java.util.*;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.dao.DataIntegrityViolationException;

import io.corbel.iam.exception.GroupAlreadyExistsException;
import io.corbel.iam.exception.NotExistentScopeException;
import io.corbel.iam.model.Group;
import io.corbel.iam.model.Scope;
import io.corbel.iam.repository.GroupRepository;
import io.corbel.iam.repository.ScopeRepository;
import io.corbel.lib.queries.request.ResourceQuery;

@RunWith(MockitoJUnitRunner.class) public class DefaultGroupServiceTest {

    private static final String ID = "id";
    private static final String NEW_ID = "newId";
    private static final String NAME = "name";
    private static final String DOMAIN = "domain";

    public static final String SCOPE_1 = "scope1";
    public static final String SCOPE_2 = "scope2";
    public static final String SCOPE_3 = "scope3";

    private static final Set<String> SCOPES = new HashSet<>(Arrays.asList(SCOPE_1, SCOPE_2));

    @Mock private GroupRepository groupRepositoryMock;
    @Mock
    private ScopeRepository scopeRepositoryMock;

    private GroupService groupService;

    @Before
    public void setUp() {
        groupService = new DefaultGroupService(groupRepositoryMock, scopeRepositoryMock);
    }

    @Test
    public void getAllGroupsTest() {
        Group group = getGroup();

        List<ResourceQuery> resourceQueries = Collections.emptyList();

        when(groupRepositoryMock.findByDomain(DOMAIN, resourceQueries, null, null)).thenReturn(Collections.singletonList(group));

        List<Group> groups = groupService.getAll(DOMAIN, resourceQueries, null, null);

        assertThat(groups).hasSize(1);
        assertThat(groups).contains(group);

        verify(groupRepositoryMock).findByDomain(DOMAIN, resourceQueries, null, null);
        verifyNoMoreInteractions(groupRepositoryMock);
    }

    @Test
    public void getGroupTest() {
        Group expectedGroup = getGroup();

        when(groupRepositoryMock.findByIdAndDomain(ID, DOMAIN)).thenReturn(expectedGroup);

        Optional<Group> group = groupService.getById(ID, DOMAIN);

        assertThat(group.isPresent()).isTrue();

        assertThat(group.get()).isEqualTo(expectedGroup);

        verify(groupRepositoryMock).findByIdAndDomain(ID, DOMAIN);
        verifyNoMoreInteractions(groupRepositoryMock);
    }

    @Test
    public void getNullGroupTest() {
        Optional<Group> group = groupService.getById(ID, DOMAIN);

        assertThat(group.isPresent()).isFalse();

        verify(groupRepositoryMock).findByIdAndDomain(ID, DOMAIN);
        verifyNoMoreInteractions(groupRepositoryMock);
    }

    @Test
    public void getGroupWithoutDomainTest() {
        Group expectedGroup = getGroup();

{'fraction_non_alphanumeric': 0.0989456609894566, 'fraction_numerical': 0.00291970802919708, 'mean_word_length': 4.261092150170649, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '6744382', 'n_tokens_mistral': 1752, 'n_tokens_neox': 1712, 'n_words': 355}