aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorGodin <mandrikov@gmail.com>2010-11-02 09:06:33 +0000
committerGodin <mandrikov@gmail.com>2010-11-02 09:06:33 +0000
commit87b8327cca62070ebfe00f80da634bcbe7e9d1ea (patch)
treeaa0fcaf1bcc8e42143255ec10fc5a1edd51ae067 /plugins
parent38958c1a36a57491d7298f917c3fb32899032947 (diff)
downloadsonarqube-87b8327cca62070ebfe00f80da634bcbe7e9d1ea.tar.gz
sonarqube-87b8327cca62070ebfe00f80da634bcbe7e9d1ea.zip
SONAR-1772: Add unit test for FindbugsDownloader
Diffstat (limited to 'plugins')
-rw-r--r--plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsDownloader.java33
-rw-r--r--plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsDownloaderTest.java59
2 files changed, 88 insertions, 4 deletions
diff --git a/plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsDownloader.java b/plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsDownloader.java
index 30d8ad238d5..03c53ef65c1 100644
--- a/plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsDownloader.java
+++ b/plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsDownloader.java
@@ -1,3 +1,22 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * 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.plugins.findbugs;
import java.io.File;
@@ -16,7 +35,7 @@ import org.sonar.api.utils.SonarException;
public class FindbugsDownloader implements BatchExtension {
- private static final String FINDBUGS_URL = "/deploy/plugins/findbugs/";
+ private static final String FINDBUGS_URL = "/deploy/plugins/findbugs";
private static List<File> libs;
@@ -35,15 +54,21 @@ public class FindbugsDownloader implements BatchExtension {
return libs;
}
- private String getUrlForAnnotationsJar() {
+ /**
+ * Visibility has been relaxed to make the code testable.
+ */
+ protected String getUrlForAnnotationsJar() {
return host + FINDBUGS_URL + "/annotations-" + FindbugsVersion.getVersion() + ".jar";
}
- private String getUrlForJsrJar() {
+ /**
+ * Visibility has been relaxed to make the code testable.
+ */
+ protected String getUrlForJsrJar() {
return host + FINDBUGS_URL + "/jsr305-" + FindbugsVersion.getVersion() + ".jar";
}
- private File downloadLib(String url) {
+ protected File downloadLib(String url) {
try {
URI uri = new URI(url);
File temp = File.createTempFile("findbugs", ".jar");
diff --git a/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsDownloaderTest.java b/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsDownloaderTest.java
new file mode 100644
index 00000000000..cfa1f085c76
--- /dev/null
+++ b/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsDownloaderTest.java
@@ -0,0 +1,59 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * 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.plugins.findbugs;
+
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.startsWith;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.mock;
+
+import java.io.File;
+
+import org.apache.commons.configuration.BaseConfiguration;
+import org.apache.commons.configuration.Configuration;
+import org.junit.Before;
+import org.junit.Test;
+import org.sonar.api.utils.HttpDownloader;
+
+public class FindbugsDownloaderTest {
+
+ private FindbugsDownloader downloader;
+
+ @Before
+ public void setUp() {
+ Configuration configuration = new BaseConfiguration();
+ configuration.setProperty("sonar.host.url", "http://sonar/");
+
+ HttpDownloader httpDownloader = mock(HttpDownloader.class);
+ downloader = new FindbugsDownloader(configuration, httpDownloader);
+ }
+
+ @Test
+ public void testUrls() {
+ assertThat(downloader.getUrlForAnnotationsJar(), startsWith("http://sonar/deploy/plugins/findbugs/annotations-"));
+ assertThat(downloader.getUrlForJsrJar(), startsWith("http://sonar/deploy/plugins/findbugs/jsr305-"));
+ }
+
+ @Test
+ public void shouldCreateTempFile() {
+ File file = downloader.downloadLib("http://sonar/test.jar");
+ assertThat(file.exists(), is(true));
+ }
+}