aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-core
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2014-09-11 14:01:28 +0200
committerJulien Lancelot <julien.lancelot@sonarsource.com>2014-09-11 14:01:28 +0200
commit5de47b68afd4a58bc2da310f93b8e8b5b9730f1a (patch)
tree8a052289654387d1060fe7d9e0ab1be5a1b61361 /sonar-core
parent6fac8a53f051d2b3e6720a0c93dcd1a8fca704a4 (diff)
downloadsonarqube-5de47b68afd4a58bc2da310f93b8e8b5b9730f1a.tar.gz
sonarqube-5de47b68afd4a58bc2da310f93b8e8b5b9730f1a.zip
Add some unit tests
Diffstat (limited to 'sonar-core')
-rw-r--r--sonar-core/src/test/java/org/sonar/core/issue/db/IssueAuthorizationDtoTest.java74
-rw-r--r--sonar-core/src/test/java/org/sonar/core/user/GroupDtoTest.java42
2 files changed, 116 insertions, 0 deletions
diff --git a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueAuthorizationDtoTest.java b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueAuthorizationDtoTest.java
new file mode 100644
index 00000000000..ec21f118258
--- /dev/null
+++ b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueAuthorizationDtoTest.java
@@ -0,0 +1,74 @@
+/*
+ * 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.issue.db;
+
+import org.junit.Test;
+
+import static com.google.common.collect.Lists.newArrayList;
+import static org.fest.assertions.Assertions.assertThat;
+
+public class IssueAuthorizationDtoTest {
+
+ @Test
+ public void getter_and_setter() throws Exception {
+ IssueAuthorizationDto dto = new IssueAuthorizationDto()
+ .setProject("Sample")
+ .setPermission("user")
+ .setGroups(newArrayList("sonar-users"))
+ .setUsers(newArrayList("john"));
+
+ assertThat(dto.getKey()).isEqualTo("Sample");
+ assertThat(dto.getProject()).isEqualTo("Sample");
+ assertThat(dto.getPermission()).isEqualTo("user");
+ assertThat(dto.getGroups()).containsExactly("sonar-users");
+ assertThat(dto.getUsers()).containsExactly("john");
+ }
+
+ @Test
+ public void add_group() throws Exception {
+ IssueAuthorizationDto dto = new IssueAuthorizationDto()
+ .setProject("Sample")
+ .setPermission("user")
+ .setGroups(newArrayList("sonar-users"))
+ .setUsers(newArrayList("john"));
+
+ assertThat(dto.getGroups()).containsExactly("sonar-users");
+
+ dto.addGroup("sonar-admins");
+
+ assertThat(dto.getGroups()).containsExactly("sonar-users", "sonar-admins");
+ }
+
+ @Test
+ public void add_user() throws Exception {
+ IssueAuthorizationDto dto = new IssueAuthorizationDto()
+ .setProject("Sample")
+ .setPermission("user")
+ .setGroups(newArrayList("sonar-users"))
+ .setUsers(newArrayList("john"));
+
+ assertThat(dto.getUsers()).containsExactly("john");
+
+ dto.addUser("doe");
+
+ assertThat(dto.getUsers()).containsExactly("john", "doe");
+ }
+}
diff --git a/sonar-core/src/test/java/org/sonar/core/user/GroupDtoTest.java b/sonar-core/src/test/java/org/sonar/core/user/GroupDtoTest.java
new file mode 100644
index 00000000000..87b6db2ff52
--- /dev/null
+++ b/sonar-core/src/test/java/org/sonar/core/user/GroupDtoTest.java
@@ -0,0 +1,42 @@
+/*
+ * 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.user;
+
+import org.junit.Test;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class GroupDtoTest {
+
+ @Test
+ public void getter_and_setter() throws Exception {
+ GroupDto dto = new GroupDto()
+ .setId(1L)
+ .setName("sonar-users")
+ .setDescription("Sonar users");
+
+ assertThat(dto.getKey()).isEqualTo("sonar-users");
+ assertThat(dto.getName()).isEqualTo("sonar-users");
+ assertThat(dto.getId()).isEqualTo(1L);
+ assertThat(dto.getDescription()).isEqualTo("Sonar users");
+ }
+
+}