SLING-5250 MockProperty getValues does not comply with JCR 2.0 API

git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1712653 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/main/java/org/apache/sling/testing/mock/jcr/MockProperty.java b/src/main/java/org/apache/sling/testing/mock/jcr/MockProperty.java
index 3eaa9ce..3e10fda 100644
--- a/src/main/java/org/apache/sling/testing/mock/jcr/MockProperty.java
+++ b/src/main/java/org/apache/sling/testing/mock/jcr/MockProperty.java
@@ -53,7 +53,7 @@
     }
 
     private Value internalGetValue() throws RepositoryException {
-        if (this.itemData.getValues().length > 1) {
+        if (this.itemData.isMultiple()) {
             throw new ValueFormatException(this
                     + " is a multi-valued property, so it's values can only be retrieved as an array");
         } else {
@@ -68,6 +68,9 @@
 
     @Override
     public Value[] getValues() throws RepositoryException {
+        if (!this.itemData.isMultiple()) {
+            throw new ValueFormatException("Property is single-valued.");
+        }
         Value[] valuesCopy = new Value[this.itemData.getValues().length];
         for (int i = 0; i < this.itemData.getValues().length; i++) {
             valuesCopy[i] = this.itemData.getValues()[i];
@@ -213,6 +216,9 @@
 
     @Override
     public long[] getLengths() throws RepositoryException {
+        if (!this.itemData.isMultiple()) {
+            throw new ValueFormatException("Property is single-valued.");
+        }
         long[] lengths = new long[this.itemData.getValues().length];
         for (int i = 0; i < this.itemData.getValues().length; i++) {
             lengths[i] = this.itemData.getValues()[i].getString().length();
diff --git a/src/test/java/org/apache/sling/testing/mock/jcr/MockPropertyTest.java b/src/test/java/org/apache/sling/testing/mock/jcr/MockPropertyTest.java
index 14d59af..81eee32 100644
--- a/src/test/java/org/apache/sling/testing/mock/jcr/MockPropertyTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/jcr/MockPropertyTest.java
@@ -34,6 +34,7 @@
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 import javax.jcr.Value;
+import javax.jcr.ValueFormatException;
 
 import org.apache.commons.io.IOUtils;
 import org.apache.jackrabbit.value.BinaryValue;
@@ -246,4 +247,12 @@
         assertEquals(PropertyType.UNDEFINED, prop1.getType());
     }
     
+    @Test(expected=ValueFormatException.class)
+    public void testSingleValueAsValueArray() throws RepositoryException {
+        this.node1.setProperty("prop1", this.session.getValueFactory().createValue("value1"));
+        Property prop1 = this.node1.getProperty("prop1");
+        assertFalse(prop1.isMultiple());
+        assertEquals("value1", prop1.getValues()[0].getString());
+    }
+    
 }