summaryrefslogtreecommitdiffstats
path: root/sonar-java-api
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2011-01-21 18:45:45 +0100
committersimonbrandhof <simon.brandhof@gmail.com>2011-01-21 18:45:45 +0100
commit94ba62923b6070bfcead527deb9bb052b225f805 (patch)
treecf84995896029e9c5ae874e312063e49a62a2dfe /sonar-java-api
parent9eaac602f7f0759ce8f67bcbb20f22d14bf3cfd1 (diff)
downloadsonarqube-94ba62923b6070bfcead527deb9bb052b225f805.tar.gz
sonarqube-94ba62923b6070bfcead527deb9bb052b225f805.zip
SONAR-2130 add some unit tests
Diffstat (limited to 'sonar-java-api')
-rw-r--r--sonar-java-api/src/main/java/org/sonar/java/api/JavaClass.java5
-rw-r--r--sonar-java-api/src/test/java/org/sonar/java/api/JavaClassTest.java22
2 files changed, 26 insertions, 1 deletions
diff --git a/sonar-java-api/src/main/java/org/sonar/java/api/JavaClass.java b/sonar-java-api/src/main/java/org/sonar/java/api/JavaClass.java
index 8db9f241414..0e2bc281479 100644
--- a/sonar-java-api/src/main/java/org/sonar/java/api/JavaClass.java
+++ b/sonar-java-api/src/main/java/org/sonar/java/api/JavaClass.java
@@ -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);
}
diff --git a/sonar-java-api/src/test/java/org/sonar/java/api/JavaClassTest.java b/sonar-java-api/src/test/java/org/sonar/java/api/JavaClassTest.java
index a2972ac2bc3..869f60b3be5 100644
--- a/sonar-java-api/src/test/java/org/sonar/java/api/JavaClassTest.java
+++ b/sonar-java-api/src/test/java/org/sonar/java/api/JavaClassTest.java
@@ -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));
+ }
}