diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2016-02-25 23:31:28 +0100 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2016-02-26 16:27:24 +0100 |
commit | 8dd5740bdeb71b8fcabbfb7d428f2e73b2e0d727 (patch) | |
tree | 2d50de1b3b52af8cb9371fa62f0c76e8a670edae /sonar-core | |
parent | 41c79688c9760806fb15cf2a6b97cf98d852f18c (diff) | |
download | sonarqube-8dd5740bdeb71b8fcabbfb7d428f2e73b2e0d727.tar.gz sonarqube-8dd5740bdeb71b8fcabbfb7d428f2e73b2e0d727.zip |
SONAR-7333 DB migration to set ISSUES.ISSUE_TYPE
Diffstat (limited to 'sonar-core')
-rw-r--r-- | sonar-core/src/main/java/org/sonar/core/issue/IssueType.java | 6 | ||||
-rw-r--r-- | sonar-core/src/test/java/org/sonar/core/issue/IssueTypeTest.java | 50 |
2 files changed, 56 insertions, 0 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/issue/IssueType.java b/sonar-core/src/main/java/org/sonar/core/issue/IssueType.java index 2ce73537adb..32a20a80891 100644 --- a/sonar-core/src/main/java/org/sonar/core/issue/IssueType.java +++ b/sonar-core/src/main/java/org/sonar/core/issue/IssueType.java @@ -19,6 +19,10 @@ */ package org.sonar.core.issue; +import com.google.common.base.Enums; +import com.google.common.collect.Lists; +import java.util.List; + import static java.lang.String.format; public enum IssueType { @@ -46,4 +50,6 @@ public enum IssueType { } throw new IllegalArgumentException(format("Unsupported value for db column ISSUES.ISSUE_TYPE: %d", dbConstant)); } + + public static List<String> ALL_NAMES = Lists.transform(Lists.newArrayList(values()), Enums.stringConverter(IssueType.class).reverse()); } diff --git a/sonar-core/src/test/java/org/sonar/core/issue/IssueTypeTest.java b/sonar-core/src/test/java/org/sonar/core/issue/IssueTypeTest.java new file mode 100644 index 00000000000..57bd07483e6 --- /dev/null +++ b/sonar-core/src/test/java/org/sonar/core/issue/IssueTypeTest.java @@ -0,0 +1,50 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * This program 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. + * + * This program 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; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +import static org.assertj.core.api.Assertions.assertThat; + +public class IssueTypeTest { + + @Rule + public ExpectedException expectedException = ExpectedException.none(); + + @Test + public void test_valueOf_db_constant() { + assertThat(IssueType.valueOf(1)).isEqualTo(IssueType.CODE_SMELL); + assertThat(IssueType.valueOf(2)).isEqualTo(IssueType.BUG); + } + + @Test + public void valueOf_throws_ISE_if_unsupported_db_constant() { + expectedException.expect(IllegalArgumentException.class); + expectedException.expectMessage("Unsupported value for db column ISSUES.ISSUE_TYPE: 4"); + IssueType.valueOf(4); + } + + @Test + public void test_ALL_NAMES() { + assertThat(IssueType.ALL_NAMES).containsOnly("BUG", "VULNERABILITY", "CODE_SMELL"); + } +} |