diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2016-03-24 15:53:36 +0100 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2016-03-30 11:42:16 +0200 |
commit | 10955ec396a053d596a40ac3fdf7ca73dd911327 (patch) | |
tree | c390cd08b8b44656206306c94213204baeec737c /sonar-plugin-api/src/test | |
parent | 946a448c08ccc10ad1c0af778ae5d9f179655ef8 (diff) | |
download | sonarqube-10955ec396a053d596a40ac3fdf7ca73dd911327.tar.gz sonarqube-10955ec396a053d596a40ac3fdf7ca73dd911327.zip |
SONAR-7458 Expose SQ Version in SensorContext
Diffstat (limited to 'sonar-plugin-api/src/test')
-rw-r--r-- | sonar-plugin-api/src/test/java/org/sonar/api/SonarQubeVersionTest.java | 6 | ||||
-rw-r--r-- | sonar-plugin-api/src/test/java/org/sonar/api/internal/SonarQubeVersionFactoryTest.java | 56 |
2 files changed, 62 insertions, 0 deletions
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/SonarQubeVersionTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/SonarQubeVersionTest.java index 0cc786c3ba4..50bc4b1c2ec 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/SonarQubeVersionTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/SonarQubeVersionTest.java @@ -19,13 +19,18 @@ */ package org.sonar.api; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import org.sonar.api.utils.Version; import static org.assertj.core.api.Assertions.assertThat; public class SonarQubeVersionTest { + @Rule + public ExpectedException expectedException = ExpectedException.none(); + @Test public void isGte() { Version version = Version.parse("1.2.3"); @@ -35,4 +40,5 @@ public class SonarQubeVersionTest { assertThat(qubeVersion.isGreaterThanOrEqual(Version.parse("1.1"))).isTrue(); assertThat(qubeVersion.isGreaterThanOrEqual(Version.parse("1.3"))).isFalse(); } + } diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/internal/SonarQubeVersionFactoryTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/internal/SonarQubeVersionFactoryTest.java new file mode 100644 index 00000000000..d37f7693d10 --- /dev/null +++ b/sonar-plugin-api/src/test/java/org/sonar/api/internal/SonarQubeVersionFactoryTest.java @@ -0,0 +1,56 @@ +/* + * 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.api.internal; + +import java.io.File; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.sonar.api.SonarQubeVersion; +import org.sonar.api.utils.System2; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Matchers.anyString; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.when; + +public class SonarQubeVersionFactoryTest { + + @Rule + public ExpectedException expectedException = ExpectedException.none(); + + @Test + public void create() { + SonarQubeVersion version = SonarQubeVersionFactory.create(System2.INSTANCE); + assertThat(version).isNotNull(); + assertThat(version.get().major()).isGreaterThanOrEqualTo(5); + } + + @Test + public void throw_ISE_if_fail_to_load_version() throws Exception { + expectedException.expect(IllegalStateException.class); + expectedException.expectMessage("Can not load /sq-version.txt from classpath"); + + System2 system = spy(System2.class); + when(system.getResource(anyString())).thenReturn(new File("target/unknown").toURI().toURL()); + SonarQubeVersionFactory.create(system); + } + +} |