<commit_before>package com.github.blindpirate.gogradle.core.dependency.external.godep

import com.github.blindpirate.gogradle.GogradleRunner
import com.github.blindpirate.gogradle.WithResource
import com.github.blindpirate.gogradle.core.GolangPackageModule
import com.github.blindpirate.gogradle.core.dependency.GolangDependency
import com.github.blindpirate.gogradle.core.dependency.parse.MapNotationParser
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.InjectMocks
import org.mockito.Mock
import org.mockito.Mockito

import static org.mockito.Matchers.any
import static org.mockito.Matchers.argThat
import static org.mockito.Mockito.*
import static org.mockito.Mockito.mock
import static org.mockito.Mockito.when

@RunWith(GogradleRunner)
class GodepDependencyFactoryTest {
    File resource

    @InjectMocks
    GodepDependencyFactory godepDependencyFactory
    @Mock
    GolangPackageModule module
    @Mock
    MapNotationParser mapNotationParser

    @WithResource('')
    @Test
    public void 'package with Godeps/Godeps.json should be rejected'() {
        // given:
        when(module.getRootDir()).thenReturn(resource.toPath())

        // then:
        assert !godepDependencyFactory.accept(module)
    }

    @Test
    @WithResource('godep-test.zip')
    public void 'package with Godeps/Godeps.json should be analyzed properly'() {
        // given:
        GolangDependency github_com_kr_fs = mock(GolangDependency)
        GolangDependency github_com_kr_pretty = mock(GolangDependency)

        when(github_com_kr_fs.getName()).thenReturn('github.com/kr/fs')
        when(github_com_kr_pretty.getName()).thenReturn('github.com/kr/pretty')

        when(module.getRootDir()).thenReturn(resource.toPath())
        when(mapNotationParser.accept(any())).thenReturn(true)
        when(mapNotationParser.produce(eq([name: "github.com/kr/fs", commit: '2788f0dbd16903de03cb8186e5c7d97b69ad387b'])))
                .thenReturn(github_com_kr_fs)
        when(mapNotationParser.produce(eq([name  : "github.com/kr/pretty",
                                           commit: 'f31442d60e51465c69811e2107ae978868dbea5c'])))
                .thenReturn(github_com_kr_pretty)
        // when:
        def result = godepDependencyFactory.produce(module)
        // then:
        assert result.size() == 2

    }
}<commit_msg>simplify GodepsDependencyFactoryTest<commit_after>package com.github.blindpirate.gogradle.core.dependency.external.godep

import com.github.blindpirate.gogradle.GogradleRunner
import com.github.blindpirate.gogradle.WithResource
import com.github.blindpirate.gogradle.core.GolangPackageModule
import com.github.blindpirate.gogradle.core.dependency.GolangDependency
import com.github.blindpirate.gogradle.core.dependency.parse.MapNotationParser
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.InjectMocks
import org.mockito.Mock
import org.mockito.Mockito

import static org.mockito.Matchers.any
import static org.mockito.Matchers.argThat
import static org.mockito.Mockito.*
import static org.mockito.Mockito.mock
import static org.mockito.Mockito.when

@RunWith(GogradleRunner)
class GodepDependencyFactoryTest {
    File resource

    @InjectMocks
    GodepDependencyFactory godepDependencyFactory
    @Mock
    GolangPackageModule module
    @Mock
    MapNotationParser mapNotationParser
    @Mock
    GolangDependency dependency

    @WithResource('')
    @Test
    public void 'package with Godeps/Godeps.json should be rejected'() {
        // given:
        when(module.getRootDir()).thenReturn(resource.toPath())

        // then:
        assert !godepDependencyFactory.accept(module)
    }

    @Test
    @WithResource('godep-test.zip')
    public void 'package with Godeps/Godeps.json should be analyzed properly'() {
        // given:
        when(module.getRootDir()).thenReturn(resource.toPath())
        when(mapNotationParser.accept(any())).thenReturn(true)
        when(mapNotationParser.produce(anyMap())).thenReturn(dependency)
        when(dependency.getName()).thenReturn('name')

        // when:
        def result = godepDependencyFactory.produce(module)
        // then:
        verify(mapNotationParser).produce(eq([name: "github.com/kr/fs", commit: '<PASSWORD>']))
        verify(mapNotationParser).produce(eq([name  : "github.com/kr/pretty",
                                              commit: '<PASSWORD>']))

    }
}
{'fraction_non_alphanumeric': 0.10312075983717775, 'fraction_numerical': 0.012211668928086838, 'mean_word_length': 3.6362683438155137, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '146506', 'n_tokens_mistral': 1446, 'n_tokens_neox': 1346, 'n_words': 205}