aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2013-02-19 10:27:40 +0100
committerSimon Brandhof <simon.brandhof@gmail.com>2013-02-19 10:27:40 +0100
commite7aabcfba880d8c4f03feb2d4e10934e304a257e (patch)
tree89608ade8566a47321517d7e1638f5fe4ab8260c /sonar-batch
parentb25a614a7d6f86663966cabb0e1ee668646ad6c1 (diff)
downloadsonarqube-e7aabcfba880d8c4f03feb2d4e10934e304a257e.tar.gz
sonarqube-e7aabcfba880d8c4f03feb2d4e10934e304a257e.zip
Add missing unit tests
Diffstat (limited to 'sonar-batch')
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/scan/LastSnapshotsTest.java31
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/DeprecatedFileSystemAdapterTest.java51
2 files changed, 82 insertions, 0 deletions
diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/LastSnapshotsTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/LastSnapshotsTest.java
index 62e756b8c7d..aea6772bc69 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/scan/LastSnapshotsTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/scan/LastSnapshotsTest.java
@@ -19,11 +19,14 @@
*/
package org.sonar.batch.scan;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.ExpectedException;
import org.sonar.api.CoreProperties;
import org.sonar.api.config.Settings;
import org.sonar.api.database.model.RuleFailureModel;
import org.sonar.api.resources.File;
+import org.sonar.api.resources.Project;
import org.sonar.api.utils.HttpDownloader;
import org.sonar.batch.bootstrap.ServerClient;
import org.sonar.jpa.test.AbstractDbUnitTestCase;
@@ -42,6 +45,9 @@ import static org.mockito.Mockito.when;
public class LastSnapshotsTest extends AbstractDbUnitTestCase {
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
@Test
public void should_return_null_violations_if_no_last_snapshot() {
setupData("no_last_snapshot");
@@ -104,6 +110,20 @@ public class LastSnapshotsTest extends AbstractDbUnitTestCase {
}
@Test
+ public void should_fail_to_download_source_from_ws() throws URISyntaxException {
+ setupData("last_snapshot");
+ ServerClient server = mock(ServerClient.class);
+ when(server.request(anyString(), eq(false))).thenThrow(new HttpDownloader.HttpException(new URI(""), 500));
+
+ Settings settings = new Settings();
+ settings.setProperty(CoreProperties.DRY_RUN, true);
+ LastSnapshots lastSnapshots = new LastSnapshots(settings, getSession(), server);
+
+ thrown.expect(HttpDownloader.HttpException.class);
+ lastSnapshots.getSource(newFile());
+ }
+
+ @Test
public void should_return_empty_source_if_dry_run_and_no_last_snapshot() throws URISyntaxException {
setupData("last_snapshot");
ServerClient server = mock(ServerClient.class);
@@ -118,6 +138,17 @@ public class LastSnapshotsTest extends AbstractDbUnitTestCase {
verify(server).request("/api/sources?resource=myproject:org/foo/Bar.c&format=txt", false);
}
+ @Test
+ public void should_not_load_source_of_non_files() throws URISyntaxException {
+ setupData("last_snapshot");
+ ServerClient server = mock(ServerClient.class);
+
+ LastSnapshots lastSnapshots = new LastSnapshots(new Settings(), getSession(), server);
+
+ String source = lastSnapshots.getSource(new Project("my-project"));
+ assertThat(source).isEqualTo("");
+ }
+
private File newFile() {
File file = new File("org/foo", "Bar.c");
file.setEffectiveKey("myproject:org/foo/Bar.c");
diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/DeprecatedFileSystemAdapterTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/DeprecatedFileSystemAdapterTest.java
new file mode 100644
index 00000000000..fae9adc1b79
--- /dev/null
+++ b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/DeprecatedFileSystemAdapterTest.java
@@ -0,0 +1,51 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.batch.scan.filesystem;
+
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.sonar.api.resources.Project;
+
+import static org.fest.assertions.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+public class DeprecatedFileSystemAdapterTest {
+ @Test
+ public void should_wrap_module_file_system() {
+ DefaultModuleFileSystem target = mock(DefaultModuleFileSystem.class, Mockito.RETURNS_SMART_NULLS);
+ DeprecatedFileSystemAdapter adapter = new DeprecatedFileSystemAdapter(target, new Project("my-project"));
+
+ assertThat(adapter.getBasedir()).isNotNull();
+ verify(target).baseDir();
+
+ assertThat(adapter.getSourceDirs()).isNotNull();
+ verify(target).sourceDirs();
+
+ assertThat(adapter.getTestDirs()).isNotNull();
+ verify(target).testDirs();
+
+ assertThat(adapter.getSourceCharset()).isNotNull();
+ verify(target).sourceCharset();
+
+ assertThat(adapter.getBuildDir()).isNotNull();
+ verify(target).buildDir();
+ }
+}