]> source.dussan.org Git - sonarqube.git/commitdiff
Improve unit tests
authorEvgeny Mandrikov <mandrikov@gmail.com>
Thu, 13 Oct 2011 06:37:49 +0000 (10:37 +0400)
committerEvgeny Mandrikov <mandrikov@gmail.com>
Thu, 13 Oct 2011 07:29:52 +0000 (11:29 +0400)
sonar-batch/src/test/java/org/sonar/batch/bootstrap/BootstrapClassLoaderTest.java [deleted file]
sonar-batch/src/test/java/org/sonar/batch/bootstrap/JdbcDriverHolderTest.java [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/bootstrap/BootstrapClassLoaderTest/foo.jar [deleted file]
sonar-batch/src/test/resources/org/sonar/batch/bootstrap/JdbcDriverHolderTest/foo.jar [new file with mode: 0644]
sonar-plugin-api/src/test/java/org/sonar/api/batch/bootstrap/ProjectDefinitionTest.java

diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BootstrapClassLoaderTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BootstrapClassLoaderTest.java
deleted file mode 100644 (file)
index 81790ae..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2011 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.bootstrap;
-
-import org.junit.Test;
-
-import java.io.File;
-import java.net.URISyntaxException;
-import java.net.URL;
-
-import static junit.framework.Assert.assertNotNull;
-import static junit.framework.Assert.assertNull;
-
-public class BootstrapClassLoaderTest {
-
-  @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");
-    JdbcDriverHolder classloader = new JdbcDriverHolder(new File(url.toURI()));
-    assertNotNull(classloader.getClassLoader());
-    assertNotNull(classloader.getClassLoader().getResource("foo/foo.txt"));
-
-  }
-}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/JdbcDriverHolderTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/JdbcDriverHolderTest.java
new file mode 100644 (file)
index 0000000..223842a
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2011 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.bootstrap;
+
+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 org.junit.Test;
+
+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/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/BootstrapClassLoaderTest/foo.jar
deleted file mode 100644 (file)
index c2bde4e..0000000
Binary files a/sonar-batch/src/test/resources/org/sonar/batch/bootstrap/BootstrapClassLoaderTest/foo.jar and /dev/null differ
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/bootstrap/JdbcDriverHolderTest/foo.jar b/sonar-batch/src/test/resources/org/sonar/batch/bootstrap/JdbcDriverHolderTest/foo.jar
new file mode 100644 (file)
index 0000000..c2bde4e
Binary files /dev/null and b/sonar-batch/src/test/resources/org/sonar/batch/bootstrap/JdbcDriverHolderTest/foo.jar differ
index 581e9ff3361b6d44fa7ca4797924e6d329338e85..6c3d59a9452dd5f0b05b98a6aadc407fda407ff2 100644 (file)
  */
 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 {
 
@@ -40,6 +40,27 @@ public class ProjectDefinitionTest {
     assertThat(def.getKey(), is("mykey"));
   }
 
+  @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();
@@ -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"));
   }