@Test
  public void doNotCreateJobIfAlreadyExists() throws Exception {
    String repoName = givenSchedulerWithOneRunningJob();

    RepoMetadataGeneratorJob jobBeforeSecondUpdate = schedulerJob.getRepoJobs().get(repoName);
    schedulerJob.update();

    RepoMetadataGeneratorJob jobAfterSecondUpdate = schedulerJob.getRepoJobs().get(repoName);

    assertThat(jobBeforeSecondUpdate, sameInstance(jobAfterSecondUpdate));
  }
  @Test
  public void removeJobAfterRemovedFromDB() throws Exception {
    String repoName = givenSchedulerWithOneRunningJob();
    context
        .repoEntriesRepository()
        .delete(context.repoEntriesRepository().findFirstByName(repoName).getId());

    RepoMetadataGeneratorJob existingJob = schedulerJob.getRepoJobs().get(repoName);
    assertThat(existingJob.isActive(), is(true));

    schedulerJob.update();
    assertThat(schedulerJob.getRepoJobs().get(repoName), nullValue());
    assertThat(existingJob.isActive(), is(false));
  }
 private String givenSchedulerWithOneRunningJob() {
   String repoName = uniqueRepoName();
   RepoEntry entry = new RepoEntry();
   entry.setName(repoName);
   entry.setType(SCHEDULED);
   context.repoEntriesRepository().save(entry);
   schedulerJob.update();
   return repoName;
 }
 @Test
 public void createNewJobForConfiguredRepos() throws Exception {
   String repoName = givenSchedulerWithOneRunningJob();
   RepoMetadataGeneratorJob job = schedulerJob.getRepoJobs().get(repoName);
   assertThat(job, notNullValue());
 }