<commit_before>package net.nemerosa.ontrack.extension.git

import net.nemerosa.ontrack.extension.api.ExtensionManager
import net.nemerosa.ontrack.extension.git.model.GitConfiguration
import net.nemerosa.ontrack.extension.git.service.GitService
import net.nemerosa.ontrack.model.structure.Branch
import net.nemerosa.ontrack.model.structure.Project
import org.junit.Before
import org.junit.Test

import static net.nemerosa.ontrack.model.structure.NameDescription.nd
import static org.mockito.Matchers.any
import static org.mockito.Mockito.mock
import static org.mockito.Mockito.when

class GitBranchesTemplateSynchronisationSourceTest {

    final GitExtensionFeature extensionFeature = new GitExtensionFeature()
    ExtensionManager extensionManager
    GitService gitService
    GitBranchesTemplateSynchronisationSource source
    Branch branch

    @Before
    void before() {
        branch = Branch.of(Project.of(nd('P', "Project")), nd('B', "Branch"))
        extensionManager = mock(ExtensionManager)
        gitService = mock(GitService)
        when(gitService.getRemoteBranches(any(GitConfiguration))).thenReturn(
                ['master', 'feature/ontrack-40-templating', 'feature/ontrack-111-project-manager', 'fix/ontrack-110']
        )
        source = new GitBranchesTemplateSynchronisationSource(
                extensionFeature,
                extensionManager,
                gitService
        )
    }

    @Test
    void 'Not applicable if feature not enabled'() {<commit_msg>#166 Correction of unit tests - the GitConfiguration is needed<commit_after>package net.nemerosa.ontrack.extension.git

import net.nemerosa.ontrack.extension.api.ExtensionManager
import net.nemerosa.ontrack.extension.git.model.GitConfiguration
import net.nemerosa.ontrack.extension.git.service.GitService
import net.nemerosa.ontrack.model.structure.Branch
import net.nemerosa.ontrack.model.structure.Project
import org.junit.Before
import org.junit.Test

import static net.nemerosa.ontrack.model.structure.NameDescription.nd
import static org.mockito.Matchers.any
import static org.mockito.Mockito.mock
import static org.mockito.Mockito.when

class GitBranchesTemplateSynchronisationSourceTest {

    final GitExtensionFeature extensionFeature = new GitExtensionFeature()
    ExtensionManager extensionManager
    GitService gitService
    GitBranchesTemplateSynchronisationSource source
    GitConfiguration gitConfiguration
    Branch branch

    @Before
    void before() {
        branch = Branch.of(Project.of(nd('P', "Project")), nd('B', "Branch"))
        gitConfiguration = GitConfiguration.empty().withBranch('${sourceName}')
        extensionManager = mock(ExtensionManager)
        gitService = mock(GitService)
        when(gitService.getBranchConfiguration(branch)).thenReturn(gitConfiguration)
        when(gitService.getRemoteBranches(any(GitConfiguration))).thenReturn(
                ['master', 'feature/ontrack-40-templating', 'feature/ontrack-111-project-manager', 'fix/ontrack-110']
        )
        source = new GitBranchesTemplateSynchronisationSource(
                extensionFeature,
                extensionManager,
                gitService
        )
    }

    @Test
    void 'Not applicable if feature not enabled'() {
{'fraction_non_alphanumeric': 0.08861538461538461, 'fraction_numerical': 0.005846153846153846, 'mean_word_length': 3.874062968515742, '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': '6726757', 'n_tokens_mistral': 896, 'n_tokens_neox': 866, 'n_words': 161}