Source:
public void itUsesPreviousCommitWhenBuildIsPartOfInterProjectBuild() throws Exception { GitInfo branch = new GitInfo(Optional.of(1), "git.example.com", "example", "repository", 1, "master", true, 0L, 1L); String commitSha = "0000000000000000000000000000000000000000"; Commit commit = Commit.newBuilder().setId(commitSha).build(); CommitInfo commitInfo = new CommitInfo(commit, Optional.absent(), Collections.emptyList(), false); RepositoryBuild previousBuild = RepositoryBuild.newBuilder(1, 1, RepositoryBuild.State.SUCCEEDED, BuildTrigger.forCommit(commitSha), BuildOptions.defaultOptions()) .setCommitInfo(Optional.of(commitInfo)) .build(); Optional<RepositoryBuild> previousBuildOptional = Optional.of(previousBuild); BuildOptions ipbBuildOptions = new BuildOptions(ImmutableSet.of(1), BuildOptions.BuildDownstreams.NONE, false); RepositoryBuild currentBuild = RepositoryBuild.queuedBuild(branch, BuildTrigger.forInterProjectBuild(1), 2, ipbBuildOptions); RepositoryBuildLauncher launcher = new RepositoryBuildLauncher(repositoryBuildService, branchService, moduleService, dependenciesService, moduleDiscoveryService, moduleDiscovery, gitHubHelper); doAnswer(invocation -> { Commit currentCommit = (Commit) invocation.getArguments()[1]; Optional<Commit> previousCommit = (Optional<Commit>) invocation.getArguments()[2]; assertThat(currentCommit.getId()).isEqualTo(commitSha); assertThat(previousCommit.isPresent()).isTrue(); assertThat(previousCommit.get().getId()).isEqualTo(commitSha); return null; }).when(gitHubHelper).commitInfoFor(any(), any(), any()); when(gitHubHelper.shaFor(any(), any())).thenThrow(new IllegalStateException("Previous build is present this should not be called")); launcher.calculateCommitInfoForBuild(branch, currentBuild, previousBuildOptional); }

Target:
public void itUsesPreviousCommitWhenBuildIsPartOfInterProjectBuild() throws Exception { GitInfo branch = new GitInfo(Optional.of(1), "git.example.com", "example", "repository", 1, "master", true, 0L, 1L); String commitSha = "0000000000000000000000000000000000000000"; Commit commit = Commit.newBuilder().setId(commitSha).build(); CommitInfo commitInfo = new CommitInfo(commit, Optional.absent(), Collections.emptyList(), false); RepositoryBuild previousBuild = RepositoryBuild.newBuilder(1, 1, RepositoryBuild.State.SUCCEEDED, BuildTrigger.forCommit(commitSha), BuildOptions.defaultOptions()) .setCommitInfo(Optional.of(commitInfo)) .build(); Optional<RepositoryBuild> previousBuildOptional = Optional.of(previousBuild); BuildOptions ipbBuildOptions = new BuildOptions(ImmutableSet.of(1), BuildOptions.BuildDownstreams.NONE, false); RepositoryBuild currentBuild = RepositoryBuild.queuedBuild(branch, BuildTrigger.forInterProjectBuild(1), 2, ipbBuildOptions); RepositoryBuildLauncher launcher = new RepositoryBuildLauncher(repositoryBuildService, branchService, moduleService, dependenciesService, moduleDiscoveryService, moduleDiscovery, gitHubHelper); when(gitHubHelper.commitInfoFor(any(), any(), any())).thenThrow(new IllegalStateException("Previous build is present this should not be called")); when(gitHubHelper.shaFor(any(), any())).thenThrow(new IllegalStateException("Previous build is present this should not be called")); CommitInfo result = launcher.calculateCommitInfoForBuild(branch, currentBuild, previousBuildOptional); assertThat(result.getCurrent().getId()).isEqualTo(commitSha); assertThat(result.getPrevious().isPresent()).isTrue(); assertThat(result.getPrevious().get().getId()).isEqualTo(commitSha); }