@Test
public void itEnqueuesModuleBuildsAndUpdatesRepositoryBuildToLaunching() throws Exception {

  when(malformedFileService.getMalformedFiles(anyInt())).thenReturn(ImmutableSet.of());
  when(moduleService.getByBranch(1)).thenReturn(ImmutableSet.of(activeModule, inactiveModule));

  doThrow(new RuntimeException("Build should not have been failed")).when(repositoryBuildService).fail(any());

  RepositoryBuild[] savedRepositoryBuild = {null};
  doAnswer(invocation -> {
    savedRepositoryBuild[0] = (RepositoryBuild) invocation.getArguments()[0];
    return null;
  }).when(repositoryBuildService).update(anyObject());

  List<Module> modulesThatWereEnqueued = new ArrayList<>();
  doAnswer(invocation -> {
    modulesThatWereEnqueued.add((Module) invocation.getArguments()[1]);
    return null;
  }).when(moduleBuildService).enqueue(anyObject(), anyObject(), anyObject(), anyObject());

  RepositoryBuild expectedRepositoryBuild = launchingBuild.toBuilder().setState(RepositoryBuild.State.IN_PROGRESS).build();

  buildVisitor.visitLaunching(launchingBuild);

  assertThat(savedRepositoryBuild).isNotNull();
  assertThat(savedRepositoryBuild[0]).isEqualTo(expectedRepositoryBuild);

  assertThat(modulesThatWereEnqueued).doesNotContain(inactiveModule);
  assertThat(modulesThatWereEnqueued).isEqualTo(ImmutableList.of(activeModule));
}