@@ -0,0 +1,3196 @@
+package jenkins.plugins.git;%0A%0Aimport hudson.model.TaskListener;%0Aimport hudson.util.StreamTaskListener;%0Aimport jenkins.plugins.git.traits.BranchDiscoveryTrait;%0Aimport jenkins.scm.api.trait.SCMSourceTrait;%0Aimport org.junit.Rule;%0Aimport org.junit.Test;%0Aimport org.jvnet.hudson.test.JenkinsRule;%0A%0Aimport java.util.Collections;%0A%0Aimport static org.hamcrest.MatcherAssert.assertThat;%0Aimport static org.hamcrest.Matchers.is;%0Aimport static org.junit.Assert.assertEquals;%0A%0A/**%0A * Currently the test aims to functionally validate estimation of size of .git repo from a cached directory%0A * TODO Test estimation with API extension point%0A */%0Apublic class GitRepoSizeEstimatorTest %7B%0A%0A    @Rule%0A    public JenkinsRule jenkins = new JenkinsRule();%0A%0A    @Rule%0A    public GitSampleRepoRule sampleRepo = new GitSampleRepoRule();%0A%0A    static final String GitBranchSCMHead_DEV_MASTER = %22%5BGitBranchSCMHead%7Bname='dev', ref='refs/heads/dev'%7D, GitBranchSCMHead%7Bname='master', ref='refs/heads/master'%7D%5D%22;%0A%0A    /*%0A    In the scenario of not having a cache or an implemented extension point, the estimation class should recommend%0A    NONE which means keep the impl as is.%0A     */%0A    @Test%0A    public void testSizeEstimationWithNoGitCache() throws Exception %7B%0A        GitSCMSource instance = new GitSCMSource(%22https://github.com/rishabhBudhouliya/git-plugin.git%22);%0A        GitRepoSizeEstimator repoSizeEstimator = new GitRepoSizeEstimator(instance);%0A        String tool = repoSizeEstimator.getGitTool();%0A%0A        // The class should make no recommendation since it can't find a .git cached directory%0A        assertThat(tool.equals(%22NONE%22), is(true));%0A    %7D%0A%0A    /*%0A    In the case of having a cached .git repository, the estimator class should estimate the size of the local checked%0A    out repository and ultimately provide a suggestion on the base of decided heuristic.%0A     */%0A    @Test%0A    public void testSizeEstimationWithGitCache() throws Exception %7B%0A        sampleRepo.init();%0A        sampleRepo.git(%22checkout%22, %22-b%22, %22dev%22);%0A        sampleRepo.write(%22file%22, %22modified%22);%0A        sampleRepo.git(%22commit%22, %22--all%22, %22--message=dev%22);%0A        sampleRepo.git(%22tag%22, %22lightweight%22);%0A        sampleRepo.write(%22file%22, %22modified2%22);%0A        sampleRepo.git(%22commit%22, %22--all%22, %22--message=dev2%22);%0A        sampleRepo.git(%22tag%22, %22-a%22, %22annotated%22, %22-m%22, %22annotated%22);%0A        sampleRepo.write(%22file%22, %22modified3%22);%0A        sampleRepo.git(%22commit%22, %22--all%22, %22--message=dev3%22);%0A        GitSCMSource source = new GitSCMSource(sampleRepo.toString());%0A        TaskListener listener = StreamTaskListener.fromStderr();%0A        // SCMHeadObserver.Collector.result is a TreeMap so order is predictable:%0A        assertEquals(%22%5B%5D%22, source.fetch(listener).toString());%0A        source.setTraits(Collections.%3CSCMSourceTrait%3EsingletonList(new BranchDiscoveryTrait()));%0A        assertEquals(GitBranchSCMHead_DEV_MASTER, source.fetch(listener).toString());%0A%0A        GitRepoSizeEstimator repoSizeEstimator = new GitRepoSizeEstimator(source);%0A        /*%0A        Since the size of repository is 21.785 KiBs, the estimator should suggest %22jgit%22 as an implementation%0A         */%0A        assertThat(repoSizeEstimator.getGitTool(), is(%22git%22));%0A    %7D%0A%0A%0A%7D%0A

Add two test cases for GitRepoSizeEstimator Note: The current test cases target only the scenario with heuristic 1, i.e the cache determination option.