From: Julien Lancelot Date: Thu, 15 Dec 2016 13:48:40 +0000 (+0100) Subject: SONAR-7292 Remove useless code in IssueChangeDao X-Git-Tag: 6.3-RC1~740 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=refs%2Fpull%2F1467%2Fhead;p=sonarqube.git SONAR-7292 Remove useless code in IssueChangeDao --- diff --git a/sonar-db/src/main/java/org/sonar/db/issue/IssueChangeDao.java b/sonar-db/src/main/java/org/sonar/db/issue/IssueChangeDao.java index 468e4bd7cfd..568fdf878ad 100644 --- a/sonar-db/src/main/java/org/sonar/db/issue/IssueChangeDao.java +++ b/sonar-db/src/main/java/org/sonar/db/issue/IssueChangeDao.java @@ -19,12 +19,9 @@ */ 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 selectCommentsByIssues(DbSession session, Collection issueKeys) { - List comments = Lists.newArrayList(); - for (IssueChangeDto dto : selectByTypeAndIssueKeys(session, issueKeys, IssueChangeDto.TYPE_COMMENT)) { - comments.add(dto.toComment()); - } - return comments; - } - public List 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 selectByTypeAndIssueKeys(DbSession session, Collection issueKeys, String changeType) { return executeLargeInputs(issueKeys, issueKeys1 -> mapper(session).selectByIssuesAndType(issueKeys1, changeType)); } diff --git a/sonar-db/src/test/java/org/sonar/db/issue/IssueChangeDaoTest.java b/sonar-db/src/test/java/org/sonar/db/issue/IssueChangeDaoTest.java index fbc29109f82..f3ed9d79d50 100644 --- a/sonar-db/src/test/java/org/sonar/db/issue/IssueChangeDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/issue/IssueChangeDaoTest.java @@ -19,22 +19,16 @@ */ 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 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 hugeNbOfIssues = newArrayList(); - for (int i = 0; i < 4500; i++) { - hugeNbOfIssues.add("ABCD" + i); - } - List 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 comments = underTest.selectCommentsByIssues(session, Collections.emptyList()); - - assertThat(comments).isEmpty(); - } - @Test public void select_comment_by_key() { IssueDto issueDto = db.issues().insertIssue();