From 35cbb0144ccff8b3ba34ef1cb69d7d0cf3ef1b90 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Thu, 30 May 2013 13:48:46 +0200 Subject: [PATCH] Improve unit test --- .../org/sonar/core/issue/db/IssueDaoTest.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDaoTest.java b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDaoTest.java index 41089436f81..51002a5ed45 100644 --- a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDaoTest.java +++ b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDaoTest.java @@ -20,6 +20,8 @@ package org.sonar.core.issue.db; +import com.google.common.base.Function; +import com.google.common.collect.Iterables; import org.junit.Before; import org.junit.Test; import org.sonar.api.issue.IssueQuery; @@ -142,14 +144,12 @@ public class IssueDaoTest extends AbstractDaoTestCase { IssueQuery query = IssueQuery.builder().componentRoots(newArrayList("struts")).requiredRole("user").build(); List issues = newArrayList(dao.selectIssues(query)); assertThat(issues).hasSize(2); - assertThat(issues.get(0).getId()).isEqualTo(100); - assertThat(issues.get(1).getId()).isEqualTo(101); + assertThat(getIssueIds(issues)).containsOnly(100l, 101l); query = IssueQuery.builder().componentRoots(newArrayList("struts-core")).requiredRole("user").build(); issues = newArrayList(dao.selectIssues(query)); assertThat(issues).hasSize(2); - assertThat(issues.get(0).getId()).isEqualTo(100); - assertThat(issues.get(1).getId()).isEqualTo(101); + assertThat(getIssueIds(issues)).containsOnly(100l, 101l); query = IssueQuery.builder().componentRoots(newArrayList("Filter.java")).requiredRole("user").build(); issues = newArrayList(dao.selectIssues(query)); @@ -296,4 +296,14 @@ public class IssueDaoTest extends AbstractDaoTestCase { List results = newArrayList(dao.selectByIds(newArrayList(100l, 101l, 102l))); assertThat(results).hasSize(3); } + + + private List getIssueIds(List issues){ + return newArrayList(Iterables.transform(issues, new Function() { + @Override + public Long apply(IssueDto input) { + return input.getId(); + } + })); + } } -- 2.39.5