public void insertChanges(IssueChangeMapper mapper, DefaultIssue issue, UuidFactory uuidFactory) {
    for (DefaultIssueComment comment : issue.defaultIssueComments()) {
      if (comment.isNew()) {
        IssueChangeDto changeDto = IssueChangeDto.of(comment, issue.projectUuid());
        changeDto.setUuid(uuidFactory.create());
        changeDto.setProjectUuid(issue.projectUuid());
        mapper.insert(changeDto);
      }
    }
    FieldDiffs diffs = issue.currentChange();
    if (issue.isCopied()) {
      for (FieldDiffs d : issue.changes()) {
        IssueChangeDto changeDto = IssueChangeDto.of(issue.key(), d, issue.projectUuid());
        changeDto.setUuid(uuidFactory.create());
        changeDto.setProjectUuid(issue.projectUuid());
        mapper.insert(changeDto);
      }
    } else if ((!issue.isNew() || issue.getAnticipatedTransitionUuid().isPresent()) && diffs != null) {
      IssueChangeDto changeDto = IssueChangeDto.of(issue.key(), diffs, issue.projectUuid());
      changeDto.setUuid(uuidFactory.create());
      changeDto.setProjectUuid(issue.projectUuid());
      mapper.insert(changeDto);
    }
  }
@Test
  public void when_newIssueWithAnticipatedTransitionInserted_twoChangelogCreated() {
    when(uuidFactory.create()).thenReturn("uuid");

    String issueKey = "ABCDE";
    String commentText = "comment for new issue";
    DefaultIssueComment comment = DefaultIssueComment.create(issueKey, "user_uuid", commentText);
    comment.setKey("FGHIJ");
    Date date = DateUtils.parseDateTime("2013-05-18T12:00:00+0000");

    DefaultIssue issue = new DefaultIssue()
      .setKey(issueKey)
      .setType(RuleType.BUG)
      .setNew(true)
      .setRuleKey(RuleKey.of("keyRepo", "r:2145"))
      .setProjectUuid("projectUuid")
      .setComponentUuid("fileUuid")
      .setLine(5000)
      .setEffort(Duration.create(10L))
      .setResolution("wontfix")
      .setStatus("CLOSED")
      .setSeverity("BLOCKER")
      .addComment(comment)
      .setCreationDate(date)
      .setUpdateDate(date)
      .setCloseDate(date)
      .setCurrentChange(new FieldDiffs())
      .setAnticipatedTransitionUuid("anticipatedTransitionUuid");

    IssueChangeDto mockCreated = mock(IssueChangeDto.class);
    IssueChangeDto mockAnticipatedTransition = mock(IssueChangeDto.class);
    try (MockedStatic<IssueChangeDto> issueChangeDtoMockedStatic = mockStatic(IssueChangeDto.class)) {
      issueChangeDtoMockedStatic.when(() -> IssueChangeDto.of(any(DefaultIssueComment.class), anyString()))
        .thenReturn(mockCreated);
      issueChangeDtoMockedStatic.when(() -> IssueChangeDto.of(anyString(), any(FieldDiffs.class), anyString()))
        .thenReturn(mockAnticipatedTransition);
      underTest.insertChanges(issueChangeMapper, issue, uuidFactory);
    }
    verify(issueChangeMapper, times(2)).insert(any(IssueChangeDto.class));
    verify(issueChangeMapper).insert(mockCreated);
    verify(issueChangeMapper).insert(mockAnticipatedTransition);
  }