[jboss-svn-commits] JBL Code SVN: r24509 - in labs/jbossrules/trunk/drools-verifier/src: test/java/org/drools/verifier and 1 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Dec 31 06:48:16 EST 2008
Author: Rikkola
Date: 2008-12-31 06:48:13 -0500 (Wed, 31 Dec 2008)
New Revision: 24509
Added:
labs/jbossrules/trunk/drools-verifier/src/test/java/org/drools/verifier/components/
labs/jbossrules/trunk/drools-verifier/src/test/java/org/drools/verifier/components/LiteralRestrictionTest.java
Modified:
labs/jbossrules/trunk/drools-verifier/src/main/java/org/drools/verifier/components/Field.java
labs/jbossrules/trunk/drools-verifier/src/main/java/org/drools/verifier/components/LiteralRestriction.java
Log:
JBRULES-1906: NPE when LiteralRestriction value is set to null
Modified: labs/jbossrules/trunk/drools-verifier/src/main/java/org/drools/verifier/components/Field.java
===================================================================
--- labs/jbossrules/trunk/drools-verifier/src/main/java/org/drools/verifier/components/Field.java 2008-12-30 14:14:37 UTC (rev 24508)
+++ labs/jbossrules/trunk/drools-verifier/src/main/java/org/drools/verifier/components/Field.java 2008-12-31 11:48:13 UTC (rev 24509)
@@ -18,6 +18,7 @@
public static final FieldType VARIABLE = new FieldType("Variable");
public static final FieldType OBJECT = new FieldType("Object");
public static final FieldType ENUM = new FieldType("Enum");
+ public static final FieldType UNKNOWN = new FieldType("Unknown");
private final String string;
Modified: labs/jbossrules/trunk/drools-verifier/src/main/java/org/drools/verifier/components/LiteralRestriction.java
===================================================================
--- labs/jbossrules/trunk/drools-verifier/src/main/java/org/drools/verifier/components/LiteralRestriction.java 2008-12-30 14:14:37 UTC (rev 24508)
+++ labs/jbossrules/trunk/drools-verifier/src/main/java/org/drools/verifier/components/LiteralRestriction.java 2008-12-31 11:48:13 UTC (rev 24509)
@@ -8,7 +8,7 @@
import org.drools.verifier.report.components.Cause;
/**
- *
+ *
* @author Toni Rikkola
*/
public class LiteralRestriction extends Restriction implements Cause {
@@ -31,7 +31,7 @@
/**
* Compares two LiteralRestrictions by value.
- *
+ *
* @param restriction
* Restriction that this object is compared to.
* @return a negative integer, zero, or a positive integer as this object is
@@ -68,6 +68,8 @@
}
} else if (valueType == Field.FieldType.STRING) {
return stringValue.compareTo(restriction.getValueAsString());
+ } else if (valueType == Field.FieldType.UNKNOWN) {
+ return 0;
}
throw new DataFormatException("Value types did not match. Value type "
@@ -109,6 +111,15 @@
public void setValue(String value) {
+ if (value == null) {
+ stringValue = null;
+ valueType = Field.FieldType.UNKNOWN;
+ return;
+ }
+
+ stringValue = value;
+ valueType = Field.FieldType.STRING;
+
if ("true".equals(value) || "false".equals(value)) {
booleanValue = value.equals("true");
valueType = Field.FieldType.BOOLEAN;
@@ -147,11 +158,9 @@
// Not a date.
}
- stringValue = value;
- valueType = Field.FieldType.STRING;
}
- public boolean isBooleanValue() {
+ public boolean getBooleanValue() {
return booleanValue;
}
Added: labs/jbossrules/trunk/drools-verifier/src/test/java/org/drools/verifier/components/LiteralRestrictionTest.java
===================================================================
--- labs/jbossrules/trunk/drools-verifier/src/test/java/org/drools/verifier/components/LiteralRestrictionTest.java (rev 0)
+++ labs/jbossrules/trunk/drools-verifier/src/test/java/org/drools/verifier/components/LiteralRestrictionTest.java 2008-12-31 11:48:13 UTC (rev 24509)
@@ -0,0 +1,44 @@
+package org.drools.verifier.components;
+
+import junit.framework.TestCase;
+
+public class LiteralRestrictionTest extends TestCase {
+
+ public void testSetValue() {
+ LiteralRestriction booleanRestriction = new LiteralRestriction();
+ booleanRestriction.setValue("true");
+
+ assertEquals(Field.FieldType.BOOLEAN, booleanRestriction.getValueType());
+ assertEquals(true, booleanRestriction.getBooleanValue());
+
+ LiteralRestriction intRestriction = new LiteralRestriction();
+ intRestriction.setValue("1");
+
+ assertEquals(Field.FieldType.INT, intRestriction.getValueType());
+ assertEquals(1, intRestriction.getIntValue());
+
+ LiteralRestriction doubleRestriction = new LiteralRestriction();
+ doubleRestriction.setValue("1.0");
+
+ assertEquals(Field.FieldType.DOUBLE, doubleRestriction.getValueType());
+ assertEquals(1.0, doubleRestriction.getDoubleValue());
+
+ LiteralRestriction dateRestriction = new LiteralRestriction();
+ dateRestriction.setValue("11-jan-2008");
+
+ assertEquals(Field.FieldType.DATE, dateRestriction.getValueType());
+
+ LiteralRestriction stringRestriction = new LiteralRestriction();
+ stringRestriction.setValue("test test");
+
+ assertEquals(Field.FieldType.STRING, stringRestriction.getValueType());
+ assertEquals("test test", stringRestriction.getValueAsString());
+
+ LiteralRestriction nullRestriction = new LiteralRestriction();
+ nullRestriction.setValue(null);
+
+ assertEquals(Field.FieldType.UNKNOWN, nullRestriction.getValueType());
+ assertEquals(null, nullRestriction.getValueAsString());
+ assertEquals(null, nullRestriction.getValueAsObject());
+ }
+}
More information about the jboss-svn-commits
mailing list