@Test
  public void auto_assign_new_issues() {
    inputIssue.setIsNew(true);
    inputIssue.setAuthorLogin("charlie");
    when(scmAccountCache.getNullable("charlie")).thenReturn("char.lie");

    process();

    assertThat(Iterators.getOnlyElement(outputIssues.traverse()).assignee()).isEqualTo("char.lie");
  }
  @Test
  public void do_not_auto_assign_existing_issues() {
    inputIssue.setIsNew(false);
    inputIssue.setAuthorLogin("charlie");
    when(scmAccountCache.getNullable("charlie")).thenReturn("char.lie");

    process();

    assertThat(Iterators.getOnlyElement(outputIssues.traverse()).assignee()).isNull();
  }
  @Test
  public void do_not_guess_author_of_existing_issues() {
    inputIssue.setIsNew(false);
    inputIssue.setLine(3);
    when(lineCache.lineAuthor(3)).thenReturn("charlie");

    process();

    assertThat(Iterators.getOnlyElement(outputIssues.traverse()).authorLogin()).isNull();
  }
  @Test
  public void do_not_fail_if_missing_author_for_new_issues() {
    inputIssue.setIsNew(true);
    inputIssue.setLine(3);
    when(lineCache.lineAuthor(3)).thenReturn(null);

    process();

    assertThat(Iterators.getOnlyElement(outputIssues.traverse()).authorLogin()).isNull();
  }
  @Test
  public void guess_author_of_new_issues() {
    inputIssue.setIsNew(true);
    inputIssue.setLine(3);
    when(lineCache.lineAuthor(3)).thenReturn("charlie");

    process();

    assertThat(Iterators.getOnlyElement(outputIssues.traverse()).authorLogin())
        .isEqualTo("charlie");
  }
  @Test
  public void do_not_override_author_and_assignee_set_by_old_batch_plugins() {
    inputIssue.setIsNew(true);

    // these fields were provided during project analysis, for instance
    // by developer cockpit or issue-assign plugins
    inputIssue.setAuthorLogin("charlie");
    inputIssue.setAssignee("cabu");

    process();

    // keep the values, without trying to update them
    DefaultIssue cachedIssue = Iterators.getOnlyElement(outputIssues.traverse());
    assertThat(cachedIssue.assignee()).isEqualTo("cabu");
    assertThat(cachedIssue.authorLogin()).isEqualTo("charlie");
    verifyZeroInteractions(scmAccountCache);
  }
  @Test
  public void do_not_copy_rule_tags_on_existing_issues() {
    inputIssue.setIsNew(false);
    rule.setTags(ImmutableSet.of("bug", "performance"));
    rule.setSystemTags(ImmutableSet.of("blocker"));

    process();

    assertThat(Iterators.getOnlyElement(outputIssues.traverse()).tags()).isEmpty();
  }
  @Test
  public void copy_rule_tags_on_new_issues() {
    inputIssue.setIsNew(true);
    rule.setTags(ImmutableSet.of("bug", "performance"));
    rule.setSystemTags(ImmutableSet.of("blocker"));

    process();

    assertThat(Iterators.getOnlyElement(outputIssues.traverse()).tags())
        .containsOnly("blocker", "bug", "performance");
  }
  @Test
  public void do_not_assign_default_assignee_when_not_found_in_index() {
    inputIssue.setIsNew(true);
    String wolinski = "wolinski";
    projectSettings.setProperty(CoreProperties.DEFAULT_ISSUE_ASSIGNEE, wolinski);
    when(userIndex.getNullableByLogin(wolinski)).thenReturn(null);

    process();

    assertThat(Iterators.getOnlyElement(outputIssues.traverse()).assignee()).isNull();
    assertThat(logTester.logs())
        .contains(
            String.format(
                "the %s property was set with an unknown login: %s",
                CoreProperties.DEFAULT_ISSUE_ASSIGNEE, wolinski));
  }
 private void process() {
   sut.processComponentIssues(
       Arrays.asList(inputIssue.build()), "FILE_A", 1, PROJECT_KEY, "PROJECT_UUID");
 }