@Test
public void testBegin() throws Exception {

  Build build = new Build();
  build.setId(3L);
  build.setLanguage(bi.getLang());
  build.setTravisBuildId(bi.getBuildId());
  build.setNumber(bi.getBuildNum());
  build.setBranch(branch);
  build.setNumSamples(bi.getNumSamples());
  when(projectRepository.findByAccountAndName(anyString(), anyString())).thenReturn(project);
    when(branchRepository.findByNameAndProject_Id(anyString(), anyLong())).thenReturn(null);
  when(branchRepository.save(any(Branch.class))).thenReturn(branch);
    when(buildRepository.findByTravisBuildId(anyLong())).thenReturn(null);
  when(buildRepository.save(any(Build.class))).thenReturn(build);
  travisRestService.begin(bi);
  verify(jandyWorker, times(1)).start(eq(bi.getBuildId()), any());
  verify(projectRepository, times(1)).findByAccountAndName(eq(bi.getOwnerName()), eq(bi.getRepoName()));
  verify(branchRepository, times(1)).findByNameAndProject_Id(eq(bi.getBranchName()), eq(project.getId()));
  verify(buildRepository, times(1)).findByTravisBuildId(eq(bi.getBuildId()));
  verify(branchRepository, times(1)).save(refEq(branch, "id"));
  verify(buildRepository, times(1)).save(refEq(build, "id"));
}