diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2014-10-08 15:13:54 +0200 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2014-10-08 15:30:46 +0200 |
commit | 99fa2be3429f1612edd016d1260c08d97ebc8404 (patch) | |
tree | d641ee3264379abf1e55eba2e5492122da473992 /sonar-core | |
parent | d5d20d0f777ba89b49575846c8f96afd316829f4 (diff) | |
download | sonarqube-99fa2be3429f1612edd016d1260c08d97ebc8404.tar.gz sonarqube-99fa2be3429f1612edd016d1260c08d97ebc8404.zip |
Fix quality flaws
Diffstat (limited to 'sonar-core')
7 files changed, 88 insertions, 10 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/source/db/SnapshotSourceDto.java b/sonar-core/src/main/java/org/sonar/core/source/db/SnapshotSourceDto.java index 34df236684d..012b0803843 100644 --- a/sonar-core/src/main/java/org/sonar/core/source/db/SnapshotSourceDto.java +++ b/sonar-core/src/main/java/org/sonar/core/source/db/SnapshotSourceDto.java @@ -28,23 +28,26 @@ public class SnapshotSourceDto { return id; } - public void setId(Long id) { + public SnapshotSourceDto setId(Long id) { this.id = id; + return this; } public Long getSnapshotId() { return snapshotId; } - public void setSnapshotId(Long snapshotId) { + public SnapshotSourceDto setSnapshotId(Long snapshotId) { this.snapshotId = snapshotId; + return this; } public String getData() { return data; } - public void setData(String data) { + public SnapshotSourceDto setData(String data) { this.data = data; + return this; } } diff --git a/sonar-core/src/main/java/org/sonar/core/user/UserDao.java b/sonar-core/src/main/java/org/sonar/core/user/UserDao.java index d4060795d3f..ef50b7cdd0a 100644 --- a/sonar-core/src/main/java/org/sonar/core/user/UserDao.java +++ b/sonar-core/src/main/java/org/sonar/core/user/UserDao.java @@ -78,13 +78,11 @@ public class UserDao implements BatchComponent, ServerComponent, DaoComponent { public List<UserDto> selectUsersByLogins(List<String> logins) { List<UserDto> users = Lists.newArrayList(); - if (!logins.isEmpty()) { - SqlSession session = mybatis.openSession(false); - try { - users.addAll(selectUsersByLogins(session, logins)); - } finally { - MyBatis.closeQuietly(session); - } + SqlSession session = mybatis.openSession(false); + try { + users.addAll(selectUsersByLogins(session, logins)); + } finally { + MyBatis.closeQuietly(session); } return users; } diff --git a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDtoTest.java b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDtoTest.java index 791c7125556..5b9abf13033 100644 --- a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDtoTest.java +++ b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDtoTest.java @@ -26,6 +26,7 @@ import org.junit.rules.ExpectedException; import org.sonar.api.issue.Issue; import org.sonar.api.issue.internal.DefaultIssue; import org.sonar.api.utils.Duration; +import org.sonar.core.rule.RuleDto; import java.util.Calendar; import java.util.Date; @@ -105,4 +106,18 @@ public class IssueDtoTest { assertThat(issue.isNew()).isFalse(); } + @Test + public void set_rule() { + IssueDto dto = new IssueDto() + .setKee("100") + .setRule(new RuleDto().setId(1).setRuleKey("AvoidCycle").setRepositoryKey("squid")) + .setLanguage("xoo"); + + assertThat(dto.getRuleId()).isEqualTo(1); + assertThat(dto.getRuleRepo()).isEqualTo("squid"); + assertThat(dto.getRule()).isEqualTo("AvoidCycle"); + assertThat(dto.getRuleKey().toString()).isEqualTo("squid:AvoidCycle"); + assertThat(dto.getLanguage()).isEqualTo("xoo"); + } + } diff --git a/sonar-core/src/test/java/org/sonar/core/resource/ResourceDaoTest.java b/sonar-core/src/test/java/org/sonar/core/resource/ResourceDaoTest.java index c287b65acf5..08bd833909b 100644 --- a/sonar-core/src/test/java/org/sonar/core/resource/ResourceDaoTest.java +++ b/sonar-core/src/test/java/org/sonar/core/resource/ResourceDaoTest.java @@ -251,6 +251,8 @@ public class ResourceDaoTest extends AbstractDaoTestCase { assertThat(dao.getRootProjectByComponentKey("org.struts:struts-core:src/org/struts").getKey()).isEqualTo("org.struts:struts"); assertThat(dao.getRootProjectByComponentKey("org.struts:struts-core").getKey()).isEqualTo("org.struts:struts"); assertThat(dao.getRootProjectByComponentKey("org.struts:struts").getKey()).isEqualTo("org.struts:struts"); + + assertThat(dao.getRootProjectByComponentKey("unknown")).isNull(); } @Test diff --git a/sonar-core/src/test/java/org/sonar/core/source/db/SnapshotSourceDaoTest.java b/sonar-core/src/test/java/org/sonar/core/source/db/SnapshotSourceDaoTest.java index 473c5fe9439..743edcb679e 100644 --- a/sonar-core/src/test/java/org/sonar/core/source/db/SnapshotSourceDaoTest.java +++ b/sonar-core/src/test/java/org/sonar/core/source/db/SnapshotSourceDaoTest.java @@ -49,4 +49,12 @@ public class SnapshotSourceDaoTest extends AbstractDaoTestCase { assertThat(snapshotSource).isEqualTo("public class Foo {public Foo(){}}"); } + + @Test + public void insert() throws Exception { + dao.insert(new SnapshotSourceDto().setId(102L).setData("bar").setSnapshotId(11L)); + + checkTable("insert", "snapshot_sources"); + } + } diff --git a/sonar-core/src/test/java/org/sonar/core/source/db/SnapshotSourceDtoTest.java b/sonar-core/src/test/java/org/sonar/core/source/db/SnapshotSourceDtoTest.java new file mode 100644 index 00000000000..6f11516b0b7 --- /dev/null +++ b/sonar-core/src/test/java/org/sonar/core/source/db/SnapshotSourceDtoTest.java @@ -0,0 +1,40 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +package org.sonar.core.source.db; + +import org.junit.Test; + +import static org.fest.assertions.Assertions.assertThat; + +public class SnapshotSourceDtoTest { + + @Test + public void test_setters_and_getters() throws Exception { + SnapshotSourceDto dto = new SnapshotSourceDto() + .setId(1L) + .setSnapshotId(10L) + .setData("data"); + + assertThat(dto.getId()).isEqualTo(1L); + assertThat(dto.getSnapshotId()).isEqualTo(10L); + assertThat(dto.getData()).isEqualTo("data"); + } +} diff --git a/sonar-core/src/test/resources/org/sonar/core/source/db/SnapshotSourceDaoTest/insert-result.xml b/sonar-core/src/test/resources/org/sonar/core/source/db/SnapshotSourceDaoTest/insert-result.xml new file mode 100644 index 00000000000..c7004b60f81 --- /dev/null +++ b/sonar-core/src/test/resources/org/sonar/core/source/db/SnapshotSourceDaoTest/insert-result.xml @@ -0,0 +1,12 @@ +<dataset> + + <projects id="1" kee="org.apache.struts:struts:Dispatcher" enabled="[true]"/> + + <snapshots id="10" project_id="1" islast="[false]"/> + <snapshots id="11" project_id="1" islast="[true]"/> + + <snapshot_sources id="101" snapshot_id="11" data="public class Foo {public Foo(){}}"/> + + <snapshot_sources id="102" snapshot_id="11" data="bar"/> + +</dataset> |