コード例 #1
0
  private List<String> getFilteredTestCandidates(Integer maxAgeInDays, String ancestorCommitSha1)
      throws Exception {
    GitSCM gitSCM = new GitSCM("foo");
    AncestryBuildChooser chooser = new AncestryBuildChooser(maxAgeInDays, ancestorCommitSha1);
    gitSCM.getExtensions().add(new BuildChooserSetting(chooser));
    assertEquals(maxAgeInDays, chooser.getMaximumAgeInDays());
    assertEquals(ancestorCommitSha1, chooser.getAncestorCommitSha1());

    // mock necessary objects
    GitClient git = Mockito.spy(this.testGitClient);
    Mockito.when(git.getRemoteBranches()).thenReturn(this.testGitClient.getBranches());

    BuildData buildData = Mockito.mock(BuildData.class);
    Mockito.when(buildData.hasBeenBuilt(git.revParse(rootCommit))).thenReturn(false);

    BuildChooserContext context = Mockito.mock(BuildChooserContext.class);
    Mockito.when(context.getEnvironment()).thenReturn(new EnvVars());

    TaskListener listener = TaskListener.NULL;

    // get filtered candidates
    Collection<Revision> candidateRevisions =
        gitSCM
            .getBuildChooser()
            .getCandidateRevisions(true, "**-days-old-branch", git, listener, buildData, context);

    // transform revision candidates to sha1 strings
    List<String> candidateSha1s =
        Lists.newArrayList(
            Iterables.transform(
                candidateRevisions,
                new Function<Revision, String>() {
                  public String apply(Revision rev) {
                    return rev.getSha1String();
                  }
                }));

    return candidateSha1s;
  }