Unico Hommes pushed to branch master at cms-community / hippo-repository

Commits:
898ab0c7 by Woonsan Ko at 2016-02-09T14:00:37-05:00
REPO-1428: to avoid NPE, assume it's string type if type cannot be inferred by 
the empty value array.

- - - - -
71fec3e0 by Unico Hommes at 2016-05-30T11:14:53+02:00
Merge branch 'bugfix/REPO-1428' into 'master'

REPO-1428: to avoid NPE, assume it's string type if type cannot be inferred by 
the empty value array.



See merge request !1
- - - - -


2 changed files:

- testutils/src/main/java/org/onehippo/repository/mock/MockNode.java
- testutils/src/test/java/org/onehippo/repository/mock/MockNodeTest.java


Changes:

=====================================
testutils/src/main/java/org/onehippo/repository/mock/MockNode.java
=====================================
--- a/testutils/src/main/java/org/onehippo/repository/mock/MockNode.java
+++ b/testutils/src/main/java/org/onehippo/repository/mock/MockNode.java
@@ -275,9 +275,12 @@ public class MockNode extends MockItem implements 
HippoNode {
 
     @Override
     public Property setProperty(final String name, final Value[] values) 
throws RepositoryException {
-        Property p = getPropertyOrAddNew(name, values[0].getType());
-        p.setValue(values);
-        return p;
+        if (values.length > 0) {
+            return setProperty(name, values, values[0].getType());
+        } else {
+            // If type cannot be inferred by the given value, then let's 
assume it as string in mock utils..
+            return setProperty(name, values, PropertyType.STRING);
+        }
     }
 
     @Override


=====================================
testutils/src/test/java/org/onehippo/repository/mock/MockNodeTest.java
=====================================
--- a/testutils/src/test/java/org/onehippo/repository/mock/MockNodeTest.java
+++ b/testutils/src/test/java/org/onehippo/repository/mock/MockNodeTest.java
@@ -15,6 +15,16 @@
  */
 package org.onehippo.repository.mock;
 
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.math.BigDecimal;
@@ -46,20 +56,9 @@ import javax.jcr.version.VersionManager;
 
 import org.apache.commons.io.IOUtils;
 import org.apache.jackrabbit.util.ISO8601;
-import org.junit.Ignore;
 import org.junit.Test;
 import org.onehippo.repository.util.JcrConstants;
 
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
 public class MockNodeTest {
 
     @Test
@@ -611,6 +610,8 @@ public class MockNodeTest {
         node.setProperty("datearray1", new MockValue[] { new 
MockValue(PropertyType.DATE, "2013-10-30T00:00:00.000Z"), new 
MockValue(PropertyType.DATE, "2013-10-31T00:00:00.000Z") });
         node.setProperty("doublearray1", new MockValue[] { new 
MockValue(PropertyType.DOUBLE, "1.23"), new MockValue(PropertyType.DOUBLE, 
"4.56") });
         node.setProperty("bigdecimalarray1", new MockValue[] { new 
MockValue(PropertyType.DECIMAL, "1.23E3"), new MockValue(PropertyType.DECIMAL, 
"4.56E3") });
+        node.setProperty("emtpystringarray1", new MockValue[0], 
PropertyType.STRING);
+        node.setProperty("emtpystringarray2", new MockValue[0]);
 
         Value [] values = node.getProperty("stringarray1").getValues();
         assertEquals(2, values.length);
@@ -641,6 +642,11 @@ public class MockNodeTest {
         assertEquals(2, values.length);
         assertEquals(new BigDecimal("1.23E3"), values[0].getDecimal());
         assertEquals(new BigDecimal("4.56E3"), values[1].getDecimal());
+
+        values = node.getProperty("emtpystringarray1").getValues();
+        assertEquals(0, values.length);
+        values = node.getProperty("emtpystringarray2").getValues();
+        assertEquals(0, values.length);
     }
 
     @Test



View it on GitLab: 
https://code.onehippo.org/cms-community/hippo-repository/compare/a5b8eb2eba2e012feeffeba39bbcf9e4eef6d1c7...71fec3e0aa50b196a66b58d8006f8da0e89d771f
_______________________________________________
Hippocms-svn mailing list
Hippocms-svn@lists.onehippo.org
https://lists.onehippo.org/mailman/listinfo/hippocms-svn

Reply via email to