]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7292 Remove useless code in IssueChangeDao 1467/head
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 15 Dec 2016 13:48:40 +0000 (14:48 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 15 Dec 2016 13:48:40 +0000 (14:48 +0100)
sonar-db/src/main/java/org/sonar/db/issue/IssueChangeDao.java
sonar-db/src/test/java/org/sonar/db/issue/IssueChangeDaoTest.java

index 468e4bd7cfd31ec5ab56416647e67fd9e01c4218..568fdf878adedf082f294eea598cd660fe7d8552 100644 (file)
  */
 package org.sonar.db.issue;
 
-import com.google.common.collect.Lists;
 import java.util.Collection;
 import java.util.List;
 import java.util.Optional;
-import javax.annotation.CheckForNull;
-import org.sonar.core.issue.DefaultIssueComment;
 import org.sonar.core.issue.FieldDiffs;
 import org.sonar.core.util.stream.Collectors;
 import org.sonar.db.Dao;
@@ -42,14 +39,6 @@ public class IssueChangeDao implements Dao {
     this.mybatis = mybatis;
   }
 
-  public List<DefaultIssueComment> selectCommentsByIssues(DbSession session, Collection<String> issueKeys) {
-    List<DefaultIssueComment> comments = Lists.newArrayList();
-    for (IssueChangeDto dto : selectByTypeAndIssueKeys(session, issueKeys, IssueChangeDto.TYPE_COMMENT)) {
-      comments.add(dto.toComment());
-    }
-    return comments;
-  }
-
   public List<FieldDiffs> selectChangelogByIssue(DbSession session, String issueKey) {
     return selectByTypeAndIssueKeys(session, singletonList(issueKey), IssueChangeDto.TYPE_FIELD_CHANGE)
       .stream()
@@ -68,19 +57,6 @@ public class IssueChangeDao implements Dao {
     }
   }
 
-  @CheckForNull
-  public DefaultIssueComment selectDefaultCommentByKey(String commentKey) {
-    DbSession session = mybatis.openSession(false);
-    try {
-      IssueChangeMapper mapper = mapper(session);
-      IssueChangeDto dto = mapper.selectByKeyAndType(commentKey, IssueChangeDto.TYPE_COMMENT);
-      return dto != null ? dto.toComment() : null;
-
-    } finally {
-      MyBatis.closeQuietly(session);
-    }
-  }
-
   public List<IssueChangeDto> selectByTypeAndIssueKeys(DbSession session, Collection<String> issueKeys, String changeType) {
     return executeLargeInputs(issueKeys, issueKeys1 -> mapper(session).selectByIssuesAndType(issueKeys1, changeType));
   }
index fbc29109f821eb7c6cc1a94b4a7d09afdb78470c..f3ed9d79d50f3162b2b231d50ef5672e3aaea299 100644 (file)
  */
 package org.sonar.db.issue;
 
-import java.util.Arrays;
-import java.util.Collections;
 import java.util.List;
 import java.util.Optional;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.utils.DateUtils;
 import org.sonar.api.utils.System2;
-import org.sonar.core.issue.DefaultIssueComment;
 import org.sonar.core.issue.FieldDiffs;
-import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
 
-import static com.google.common.collect.Lists.newArrayList;
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
 
 public class IssueChangeDaoTest {
 
@@ -43,50 +37,6 @@ public class IssueChangeDaoTest {
 
   private IssueChangeDao underTest = db.getDbClient().issueChangeDao();
 
-  @Test
-  public void select_comments_by_issues() {
-    db.prepareDbUnit(getClass(), "shared.xml");
-
-    List<DefaultIssueComment> comments = underTest.selectCommentsByIssues(db.getSession(), Arrays.asList("1000"));
-    assertThat(comments).hasSize(2);
-
-    // chronological order
-    DefaultIssueComment first = comments.get(0);
-    assertThat(first.markdownText()).isEqualTo("old comment");
-
-    DefaultIssueComment second = comments.get(1);
-    assertThat(second.userLogin()).isEqualTo("arthur");
-    assertThat(second.key()).isEqualTo("FGHIJ");
-    assertThat(second.markdownText()).isEqualTo("recent comment");
-  }
-
-  @Test
-  public void select_comments_by_issues_on_huge_number_of_issues() {
-    db.prepareDbUnit(getClass(), "shared.xml");
-
-    List<String> hugeNbOfIssues = newArrayList();
-    for (int i = 0; i < 4500; i++) {
-      hugeNbOfIssues.add("ABCD" + i);
-    }
-    List<DefaultIssueComment> comments = underTest.selectCommentsByIssues(db.getSession(), hugeNbOfIssues);
-
-    // The goal of this test is only to check that the query do no fail, not to check the number of results
-    assertThat(comments).isEmpty();
-  }
-
-  @Test
-  public void select_default_comment_by_key() {
-    db.prepareDbUnit(getClass(), "shared.xml");
-
-    DefaultIssueComment comment = underTest.selectDefaultCommentByKey("FGHIJ");
-    assertThat(comment).isNotNull();
-    assertThat(comment.key()).isEqualTo("FGHIJ");
-    assertThat(comment.key()).isEqualTo("FGHIJ");
-    assertThat(comment.userLogin()).isEqualTo("arthur");
-
-    assertThat(underTest.selectDefaultCommentByKey("UNKNOWN")).isNull();
-  }
-
   @Test
   public void select_issue_changelog_from_issue_key() {
     db.prepareDbUnit(getClass(), "shared.xml");
@@ -107,15 +57,6 @@ public class IssueChangeDaoTest {
     assertThat(dtos).extracting("id").containsOnly(100L, 103L);
   }
 
-  @Test
-  public void select_comments_by_issues_empty_input() {
-    // no need to connect to db
-    DbSession session = mock(DbSession.class);
-    List<DefaultIssueComment> comments = underTest.selectCommentsByIssues(session, Collections.<String>emptyList());
-
-    assertThat(comments).isEmpty();
-  }
-
   @Test
   public void select_comment_by_key() {
     IssueDto issueDto = db.issues().insertIssue();