]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-2130 add some unit tests
authorsimonbrandhof <simon.brandhof@gmail.com>
Fri, 21 Jan 2011 17:45:45 +0000 (18:45 +0100)
committersimonbrandhof <simon.brandhof@gmail.com>
Fri, 21 Jan 2011 17:45:45 +0000 (18:45 +0100)
sonar-java-api/src/main/java/org/sonar/java/api/JavaClass.java
sonar-java-api/src/test/java/org/sonar/java/api/JavaClassTest.java

index 8db9f241414b279bfb72fce9e7623280258582b0..0e2bc2814793cb0243e8e152db3ba0c8e0c06380 100644 (file)
@@ -105,6 +105,11 @@ public final class JavaClass extends Resource {
     return false;
   }
 
+  @Override
+  public String toString() {
+    return getName();
+  }
+
   public static JavaClass createRef(String name) {
     return new JavaClass(name);
   }
index a2972ac2bc3741a1d8c75e4cf7a0ad141aee5459..869f60b3be5e4bfcf139b393336b983660b1d09a 100644 (file)
@@ -17,7 +17,6 @@
  * License along with Sonar; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
  */
-
 package org.sonar.java.api;
 
 import org.junit.Test;
@@ -66,4 +65,25 @@ public class JavaClassTest {
     javaClass = JavaClass.createRef("Bar");
     assertThat(javaClass.getClassName(), is("Bar"));
   }
+
+  @Test
+  public void shouldOverrideToString() {
+    JavaClass javaClass = JavaClass.createRef("org.foo.Bar");
+    assertThat(javaClass.toString(), is("org.foo.Bar"));
+  }
+
+  @Test
+  public void shouldBuild() {
+    JavaClass javaClass = new JavaClass.Builder().setName("org.foo", "Bar").setFromLine(30).create();
+    assertThat(javaClass.getName(), is("org.foo.Bar"));
+    assertThat(javaClass.getFromLine(), is(30));
+    assertThat(javaClass.getToLine(), is(JavaClass.UNKNOWN_LINE));
+  }
+
+  @Test
+  public void shouldNotBuildWithNegativeNumberOfLine() {
+    JavaClass javaClass = new JavaClass.Builder().setName("org.foo", "Bar").setFromLine(-30).setToLine(0).create();
+    assertThat(javaClass.getFromLine(), is(JavaClass.UNKNOWN_LINE));
+    assertThat(javaClass.getToLine(), is(0));
+  }
 }