@Test
public void itUsesNewCommitWhenBranchBuildIsNotPartOfAInterProjectBuild() throws Exception {

  GitInfo branch = new GitInfo(Optional.of(1), "git.example.com", "example", "repository", 1, "master", true, 0L, 1L);
  String initialCommitSha = "0000000000000000000000000000000000000000";
  String secondCommitSha = "1111111111111111111111111111111111111111";
  Commit initialCommit = Commit.newBuilder().setId(initialCommitSha).build();
  Commit secondCommit = Commit.newBuilder().setId(secondCommitSha).build();
  CommitInfo previousCommitInfo = new CommitInfo(initialCommit, Optional.absent(), Collections.emptyList(), false);
  RepositoryBuild previousBuild = RepositoryBuild.newBuilder(1, 1, RepositoryBuild.State.SUCCEEDED, BuildTrigger.forCommit(initialCommitSha), BuildOptions.defaultOptions())
      .setCommitInfo(Optional.of(previousCommitInfo))
      .build();
  Optional<RepositoryBuild> previousBuildOptional = Optional.of(previousBuild);
  RepositoryBuild currentBuild = RepositoryBuild.queuedBuild(branch, BuildTrigger.forCommit(secondCommitSha), 2, BuildOptions.defaultOptions());
  RepositoryBuildLauncher launcher = new RepositoryBuildLauncher(repositoryBuildService, branchService, moduleService, dependenciesService, moduleDiscoveryService, moduleDiscoveryHandler, gitHubHelper);
  GHRepository repository = mock(GHRepository.class);
  when(gitHubHelper.shaFor(any(), any())).thenReturn(Optional.of(secondCommitSha));
  when(gitHubHelper.repositoryFor(any())).thenReturn(repository);
  doAnswer(invocation -> {
    String sha = (String) invocation.getArguments()[0];
    return new GHCommit() {
      @Override
      public String getSHA1() {
        return sha;
      }
    };
  }).when(repository).getCommit(anyString());
  doAnswer(invocation -> {
    GHCommit commit = (GHCommit) invocation.getArguments()[0];
    return Commit.newBuilder().setId(commit.getSHA1()).build();
  }).when(gitHubHelper).toCommit(any());
  // Test that the method was called with the expected arguments.
  doAnswer(invocation -> {
    Commit currentCommit = (Commit) invocation.getArguments()[1];
    Optional<Commit> previousCommit = (Optional<Commit>) invocation.getArguments()[2];
    return new CommitInfo(currentCommit, previousCommit, ImmutableList.of(currentCommit), false);
  }).when(gitHubHelper).commitInfoFor(any(), any(), any());
  CommitInfo result = launcher.calculateCommitInfoForBuild(branch, currentBuild, previousBuildOptional);
  assertThat(result.getCurrent().getId()).isEqualTo(secondCommitSha);
  assertThat(result.getPrevious().isPresent()).isTrue();
  assertThat(result.getPrevious().get().getId()).isEqualTo(initialCommitSha);
  assertThat(result.getNewCommits().isEmpty()).isFalse();
  assertThat(result.getNewCommits()).isEqualTo(ImmutableList.of(secondCommit));
}