TravisRestService { @Transactional public void begin(BuildInfo bi) { Project project = projectRepository.findByAccountAndName(bi.getOwnerName(), bi.getRepoName()); Branch branch = branchRepository.findByNameAndProject_Id(bi.getBranchName(), project.getId()); if (branch == null) { branch = new Branch(); branch.setName(bi.getBranchName()); branch.setProject(project); branch = branchRepository.save(branch); } Build build = buildRepository.findByTravisBuildId(bi.getBuildId()); if (build != null) { profContextDumpRepository.delete(build.getProfiles()); sampleRepository.delete(build.getSamples()); buildRepository.delete(build); } build = new Build(); build.setLanguage(bi.getLang()); build.setTravisBuildId(bi.getBuildId()); build.setBranch(branch); build.setNumber(bi.getBuildNum()); build.setNumSamples(bi.getNumSamples()); build = buildRepository.save(build); jandyWorker.start(bi.getBuildId(), ProfService.class); logger.info("start build for profiling: {}/{} -> {}", bi.getOwnerName(), bi.getRepoName(), bi.getBuildId()); }  @Transactional void begin(BuildInfo bi); @Transactional Map<String, ?> createProf(ProfilingInfo profParams); void saveProf(ProfilingContext profilingContext); void updateTreeNodes(List<TreeNode> treeNodes); void finish(long buildId);  }
@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.save(any(Branch.class))).thenReturn(branch); 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")); }