@Override
  public void onIssue(Component component, DefaultIssue issue) {
    if (component.getType() != Component.Type.FILE || component.getUuid().equals(issue.componentUuid())) {
      return;
    }
    Optional<OriginalFile> originalFileOptional = movedFilesRepository.getOriginalFile(component);
    checkState(originalFileOptional.isPresent(),
      "Issue %s for component %s has a different component key but no original file exist in MovedFilesRepository",
      issue, component);
    OriginalFile originalFile = originalFileOptional.get();
    String fileUuid = originalFile.uuid();
    checkState(fileUuid.equals(issue.componentUuid()),
      "Issue %s doesn't belong to file %s registered as original file of current file %s",
      issue, fileUuid, component);

    // changes the issue's component uuid, and set issue as changed, to enforce it is persisted to DB
    issueUpdater.setIssueComponent(issue, component.getUuid(), component.getKey(), new Date(analysisMetadataHolder.getAnalysisDate()));
  }
@Test
  public void onIssue_throws_ISE_if_issue_has_different_component_uuid_from_component_but_it_is_not_the_one_of_original_file() {
    DefaultIssue issue = mockIssue("other component uuid");
    when(issue.toString()).thenReturn("[bad issue, bad!]");
    when(movedFilesRepository.getOriginalFile(FILE))
      .thenReturn(Optional.of(new MovedFilesRepository.OriginalFile("original uuid", "original key")));

    assertThatThrownBy(() -> underTest.onIssue(FILE, issue))
      .isInstanceOf(IllegalStateException.class)
      .hasMessage("Issue [bad issue, bad!] doesn't belong to file original uuid registered as original " +
        "file of current file ReportComponent{ref=1, key='key_1', type=FILE}");
  }