aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2010-09-21 21:46:25 +0000
committersimonbrandhof <simon.brandhof@gmail.com>2010-09-21 21:46:25 +0000
commit6db980c1ca3375ac8bf81267c4266204d32b072f (patch)
tree03061906a42441e9c021e48f7710467660b1b1d4
parentd46e081eacea3680bae90faa5df1ae43157d1e87 (diff)
downloadsonarqube-6db980c1ca3375ac8bf81267c4266204d32b072f.tar.gz
sonarqube-6db980c1ca3375ac8bf81267c4266204d32b072f.zip
add unit test to CharacteristicProperty
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/qualitymodel/CharacteristicPropertyTest.java72
1 files changed, 72 insertions, 0 deletions
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/qualitymodel/CharacteristicPropertyTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/qualitymodel/CharacteristicPropertyTest.java
new file mode 100644
index 00000000000..a7b4d7365de
--- /dev/null
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/qualitymodel/CharacteristicPropertyTest.java
@@ -0,0 +1,72 @@
+/*
+ * 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.api.qualitymodel;
+
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+
+public class CharacteristicPropertyTest {
+
+ @Test
+ public void testNullValue() {
+ CharacteristicProperty property = CharacteristicProperty.create("foo");
+ assertThat(property.getValue(), nullValue());
+ assertThat(property.getValueAsDouble(), nullValue());
+ assertThat(property.getValueAsBoolean(), nullValue());
+ assertThat(property.getValueAsLong(), nullValue());
+ }
+
+ @Test
+ public void testBooleanValue() {
+ CharacteristicProperty property = CharacteristicProperty.create("foo");
+ property.setValue(true);
+ assertThat(property.getValue(), is("true"));//stored in the text_value column
+ assertThat(property.getValueAsDouble(), nullValue());
+ assertThat(property.getValueAsBoolean(), is(true));
+ assertThat(property.getValueAsLong(), nullValue());
+
+ property.setValue(false);
+ assertThat(property.getValue(), is("false"));
+ assertThat(property.getValueAsBoolean(), is(false));
+ }
+
+ @Test
+ public void testNumericValue() {
+ CharacteristicProperty property = CharacteristicProperty.create("foo");
+ property.setValue(3.14);
+ assertThat(property.getValueAsDouble(), is(3.14));//stored in the value column
+ assertThat(property.getValueAsLong(), is(3L));
+ assertThat(property.getValue(), nullValue());
+ assertThat(property.getValueAsBoolean(), nullValue());
+ }
+
+ @Test
+ public void testStringValue() {
+ CharacteristicProperty property = CharacteristicProperty.create("foo");
+ property.setValue("bar");
+ assertThat(property.getValue(), is("bar"));
+ assertThat(property.getValueAsDouble(), nullValue());
+ assertThat(property.getValueAsBoolean(), is(false));
+ assertThat(property.getValueAsLong(), nullValue());
+ }
+}