aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvgeny Mandrikov <mandrikov@gmail.com>2011-10-13 10:37:49 +0400
committerEvgeny Mandrikov <mandrikov@gmail.com>2011-10-13 11:29:52 +0400
commitd9512997b317c7a01d480e9b9a81422996146c88 (patch)
tree9cf68ebb7b112439a4891f6a36cd88f299ff012d
parentf8d5c0849d003e8b62c2c06f03428c33fddf4a2a (diff)
downloadsonarqube-d9512997b317c7a01d480e9b9a81422996146c88.tar.gz
sonarqube-d9512997b317c7a01d480e9b9a81422996146c88.zip
Improve unit tests
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/bootstrap/JdbcDriverHolderTest.java (renamed from sonar-batch/src/test/java/org/sonar/batch/bootstrap/BootstrapClassLoaderTest.java)13
-rw-r--r--sonar-batch/src/test/resources/org/sonar/batch/bootstrap/JdbcDriverHolderTest/foo.jar (renamed from sonar-batch/src/test/resources/org/sonar/batch/bootstrap/BootstrapClassLoaderTest/foo.jar)bin537 -> 537 bytes
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/batch/bootstrap/ProjectDefinitionTest.java36
3 files changed, 37 insertions, 12 deletions
diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BootstrapClassLoaderTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/JdbcDriverHolderTest.java
index 81790aeb189..223842a08d4 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BootstrapClassLoaderTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/JdbcDriverHolderTest.java
@@ -19,26 +19,29 @@
*/
package org.sonar.batch.bootstrap;
-import org.junit.Test;
+import static junit.framework.Assert.assertNotNull;
+import static junit.framework.Assert.assertNull;
import java.io.File;
import java.net.URISyntaxException;
import java.net.URL;
-import static junit.framework.Assert.assertNotNull;
-import static junit.framework.Assert.assertNull;
+import org.junit.Test;
-public class BootstrapClassLoaderTest {
+public class JdbcDriverHolderTest {
@Test
public void testClassLoader() throws URISyntaxException {
/* foo.jar has just one file /foo/foo.txt */
assertNull(getClass().getClassLoader().getResource("foo/foo.txt"));
- URL url = getClass().getResource("/org/sonar/batch/bootstrap/BootstrapClassLoaderTest/foo.jar");
+ URL url = getClass().getResource("/org/sonar/batch/bootstrap/JdbcDriverHolderTest/foo.jar");
JdbcDriverHolder classloader = new JdbcDriverHolder(new File(url.toURI()));
assertNotNull(classloader.getClassLoader());
assertNotNull(classloader.getClassLoader().getResource("foo/foo.txt"));
+ classloader.stop();
+ assertNull(classloader.getClassLoader());
}
+
}
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/bootstrap/BootstrapClassLoaderTest/foo.jar b/sonar-batch/src/test/resources/org/sonar/batch/bootstrap/JdbcDriverHolderTest/foo.jar
index c2bde4e5fff..c2bde4e5fff 100644
--- a/sonar-batch/src/test/resources/org/sonar/batch/bootstrap/BootstrapClassLoaderTest/foo.jar
+++ b/sonar-batch/src/test/resources/org/sonar/batch/bootstrap/JdbcDriverHolderTest/foo.jar
Binary files differ
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/bootstrap/ProjectDefinitionTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/bootstrap/ProjectDefinitionTest.java
index 581e9ff3361..6c3d59a9452 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/bootstrap/ProjectDefinitionTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/bootstrap/ProjectDefinitionTest.java
@@ -19,17 +19,17 @@
*/
package org.sonar.api.batch.bootstrap;
-import org.hamcrest.CoreMatchers;
-import org.junit.Test;
-import org.sonar.api.CoreProperties;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
import java.io.File;
import java.util.List;
import java.util.Properties;
-import static org.hamcrest.CoreMatchers.nullValue;
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertThat;
+import org.hamcrest.CoreMatchers;
+import org.junit.Test;
+import org.sonar.api.CoreProperties;
public class ProjectDefinitionTest {
@@ -41,6 +41,27 @@ public class ProjectDefinitionTest {
}
@Test
+ public void shouldSetVersion() {
+ ProjectDefinition def = ProjectDefinition.create();
+ def.setVersion("2.0-SNAPSHOT");
+ assertThat(def.getVersion(), is("2.0-SNAPSHOT"));
+ }
+
+ /**
+ * Compatibility with Ant task.
+ */
+ @Test
+ public void shouldNotCloneProperties() {
+ Properties props = new Properties();
+
+ ProjectDefinition def = ProjectDefinition.create(props);
+ assertThat(def.getKey(), nullValue());
+
+ props.setProperty(CoreProperties.PROJECT_KEY_PROPERTY, "mykey");
+ assertThat(def.getKey(), is("mykey"));
+ }
+
+ @Test
public void shouldSetOptionalFields() {
ProjectDefinition def = ProjectDefinition.create();
def.setName("myname");
@@ -60,7 +81,8 @@ public class ProjectDefinitionTest {
public void shouldGetKeyFromProperties() {
Properties props = new Properties();
props.setProperty(CoreProperties.PROJECT_KEY_PROPERTY, "foo");
- ProjectDefinition def = ProjectDefinition.create(props);
+ ProjectDefinition def = ProjectDefinition.create();
+ def.setProperties(props);
assertThat(def.getKey(), is("foo"));
}