@Test
public void testCreateProf() throws Exception {

  ProfilingInfo profParams = new Gson().fromJson(IOUtils.toString(ClassLoader.getSystemResource("java-profiler-result/begin.json")), ProfilingInfo.class);
  Build build = new Build();
  build.setId(3L);
  build.setLanguage(bi.getLang());
  build.setTravisBuildId(profParams.getBuildId());
  build.setNumber(bi.getBuildNum());
  build.setBranch(branch);
  build.setNumSamples(bi.getNumSamples());
  Sample sample = new Sample();
  sample.setId(4L);
  sample.getBuilds().add(build);
  build.getSamples().add(sample);
  ProfContextDump prof = new ProfContextDump();
  prof.setId(5L);
  prof.setBuild(build);
  prof.setSample(sample);
  prof.setState(ProfContextState.CREATED);
  when(buildRepository.findByTravisBuildId(eq(profParams.getBuildId()))).thenReturn(build);
  when(projectRepository.findByBuild(any(Build.class))).thenReturn(project);
    Sample sample = sampleRepository.findByNameAndProject_Id(profParams.getSampleName(), project.getId());
  when(sampleRepository.save(any(Sample.class))).thenReturn(sample);
  when(buildRepository.save(any(Build.class))).thenReturn(build);
  when(profContextDumpRepository.save(any(ProfContextDump.class))).thenReturn(prof);
  Map<String, ?> result = travisRestService.createProf(profParams);
  assertEquals(result.get("profId"), prof.getId());
  verify(buildRepository, times(1)).findByTravisBuildId(eq(profParams.getBuildId()));
  verify(projectRepository, times(1)).findByBuild(refEq(build, "id"));
  verify(sampleRepository, times(1)).save(refEq(sample));
  verify(sampleRepository, times(1)).findByNameAndProject_Id(eq(profParams.getSampleName()), eq(profParams.getBuildId()));
  verify(buildRepository, times(1)).save(refEq(build, "id"));
  verify(profContextDumpRepository, times(1)).save(refEq(prof, "id"));
}