@VisibleForTesting
  static DefaultIssue toDefaultIssue(IssueCache.Issue next) {
    DefaultIssue defaultIssue = new DefaultIssue();
    defaultIssue.setKey(next.getKey());
    defaultIssue.setType(RuleType.valueOf(next.getRuleType()));
    defaultIssue.setComponentUuid(next.hasComponentUuid() ? next.getComponentUuid() : null);
    defaultIssue.setComponentKey(next.getComponentKey());
    defaultIssue.setProjectUuid(next.getProjectUuid());
    defaultIssue.setProjectKey(next.getProjectKey());
    defaultIssue.setRuleKey(RuleKey.parse(next.getRuleKey()));
    defaultIssue.setLanguage(next.hasLanguage() ? next.getLanguage() : null);
    defaultIssue.setSeverity(next.hasSeverity() ? next.getSeverity() : null);
    defaultIssue.setManualSeverity(next.getManualSeverity());
    defaultIssue.setMessage(next.hasMessage() ? next.getMessage() : null);
    defaultIssue.setMessageFormattings(next.hasMessageFormattings() ? next.getMessageFormattings() : null);
    defaultIssue.setLine(next.hasLine() ? next.getLine() : null);
    defaultIssue.setGap(next.hasGap() ? next.getGap() : null);
    defaultIssue.setEffort(next.hasEffort() ? Duration.create(next.getEffort()) : null);
    defaultIssue.setStatus(next.getStatus());
    defaultIssue.setResolution(next.hasResolution() ? next.getResolution() : null);
    defaultIssue.setAssigneeUuid(next.hasAssigneeUuid() ? next.getAssigneeUuid() : null);
    defaultIssue.setAssigneeLogin(next.hasAssigneeLogin() ? next.getAssigneeLogin() : null);
    defaultIssue.setChecksum(next.hasChecksum() ? next.getChecksum() : null);
    defaultIssue.setAuthorLogin(next.hasAuthorLogin() ? next.getAuthorLogin() : null);
    next.getCommentsList().forEach(c -> defaultIssue.addComment(toDefaultIssueComment(c)));
    defaultIssue.setTags(ImmutableSet.copyOf(STRING_LIST_SPLITTER.split(next.getTags())));
    defaultIssue.setCodeVariants(ImmutableSet.copyOf(STRING_LIST_SPLITTER.split(next.getCodeVariants())));
    defaultIssue.setRuleDescriptionContextKey(next.hasRuleDescriptionContextKey() ? next.getRuleDescriptionContextKey() : null);
    defaultIssue.setLocations(next.hasLocations() ? next.getLocations() : null);
    defaultIssue.setIsFromExternalRuleEngine(next.getIsFromExternalRuleEngine());
    defaultIssue.setCreationDate(new Date(next.getCreationDate()));
    defaultIssue.setUpdateDate(next.hasUpdateDate() ? new Date(next.getUpdateDate()) : null);
    defaultIssue.setCloseDate(next.hasCloseDate() ? new Date(next.getCloseDate()) : null);
    defaultIssue.setCurrentChangeWithoutAddChange(next.hasCurrentChanges() ? toDefaultIssueChanges(next.getCurrentChanges()) : null);
    defaultIssue.setNew(next.getIsNew());
    defaultIssue.setIsOnChangedLine(next.getIsOnChangedLine());
    defaultIssue.setIsNewCodeReferenceIssue(next.getIsNewCodeReferenceIssue());
    defaultIssue.setCopied(next.getIsCopied());
    defaultIssue.setBeingClosed(next.getBeingClosed());
    defaultIssue.setOnDisabledRule(next.getOnDisabledRule());
    defaultIssue.setChanged(next.getIsChanged());
    defaultIssue.setSendNotifications(next.getSendNotifications());
    defaultIssue.setSelectedAt(next.hasSelectedAt() ? next.getSelectedAt() : null);
    defaultIssue.setQuickFixAvailable(next.getQuickFixAvailable());
    defaultIssue.setPrioritizedRule(next.getIsPrioritizedRule());
    defaultIssue.setIsNoLongerNewCodeReferenceIssue(next.getIsNoLongerNewCodeReferenceIssue());
    defaultIssue.setCleanCodeAttribute(next.hasCleanCodeAttribute() ? CleanCodeAttribute.valueOf(next.getCleanCodeAttribute()) : null);
    if (next.hasAnticipatedTransitionUuid()) {
      defaultIssue.setAnticipatedTransitionUuid(next.getAnticipatedTransitionUuid());
    }

    for (IssueCache.Impact impact : next.getImpactsList()) {
      defaultIssue.addImpact(SoftwareQuality.valueOf(impact.getSoftwareQuality()), Severity.valueOf(impact.getSeverity()));
    }
    for (IssueCache.FieldDiffs protoFieldDiffs : next.getChangesList()) {
      defaultIssue.addChange(toDefaultIssueChanges(protoFieldDiffs));
    }
    return defaultIssue;
  }
@Test
  public void toDefaultIssue_whenRuleDescriptionContextKeyPresent_shouldSetItInDefaultIssue() {
    IssueCache.Issue issue = prepareIssueWithCompulsoryFields()
      .setRuleDescriptionContextKey(TEST_CONTEXT_KEY)
      .build();

    DefaultIssue defaultIssue = ProtobufIssueDiskCache.toDefaultIssue(issue);

    assertThat(defaultIssue.getRuleDescriptionContextKey()).contains(TEST_CONTEXT_KEY);
  }