This is an automated email from the ASF dual-hosted git repository.
radu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-whiteboard.git
The following commit(s) were added to refs/heads/master by this push:
new 28c5766 SLING-8570 - Extract a generic Content Parser API from
org.apache.sling.jcr.contentparser with pluggable implementations
28c5766 is described below
commit 28c5766921a7c0ec3e10af06073871045315247d
Author: Radu Cotescu <[email protected]>
AuthorDate: Thu Jul 11 15:07:22 2019 +0200
SLING-8570 - Extract a generic Content Parser API from
org.apache.sling.jcr.contentparser with pluggable implementations
* corrected some typos
* added more unit tests
---
.../org-apache-sling-contentparser-api/pom.xml | 2 +-
.../sling/contentparser/api/ParserHelper.java | 4 +-
.../sling/contentparser/api/ParserHelperTest.java | 47 +++++++++++++++++++++-
3 files changed, 49 insertions(+), 4 deletions(-)
diff --git a/contentparser/org-apache-sling-contentparser-api/pom.xml
b/contentparser/org-apache-sling-contentparser-api/pom.xml
index 799b201..bdb4bab 100644
--- a/contentparser/org-apache-sling-contentparser-api/pom.xml
+++ b/contentparser/org-apache-sling-contentparser-api/pom.xml
@@ -31,7 +31,7 @@
<name>Apache Sling Content Parser API</name>
<description>
- Parser API Apache Sling Resource trees stored in files (e.g. JSON,
FileVault XML, etc.).
+ API for parsing Apache Sling Resource trees stored in files (e.g.
JSON, FileVault XML, etc.).
</description>
<scm>
diff --git
a/contentparser/org-apache-sling-contentparser-api/src/main/java/org/apache/sling/contentparser/api/ParserHelper.java
b/contentparser/org-apache-sling-contentparser-api/src/main/java/org/apache/sling/contentparser/api/ParserHelper.java
index 7cb1196..ca7f2ca 100644
---
a/contentparser/org-apache-sling-contentparser-api/src/main/java/org/apache/sling/contentparser/api/ParserHelper.java
+++
b/contentparser/org-apache-sling-contentparser-api/src/main/java/org/apache/sling/contentparser/api/ParserHelper.java
@@ -74,6 +74,8 @@ public final class ParserHelper {
*
* @param values the multi-value property's values
* @return an object representation of the multi-value property
+ * @throws ParseException when the provided {@code values} array contains
null values, {@link Map} values, or the values are not of the
+ * same type
*/
public static Object convertSingleTypeArray(Object[] values) {
if (values.length == 0) {
@@ -90,7 +92,7 @@ public final class ParserHelper {
if (itemType == null) {
itemType = value.getClass();
} else if (itemType != value.getClass()) {
- throw new ParseException("Multivalue array must not contain
values with different types "
+ throw new ParseException("Multi-value array must not contain
values with different types "
+ "(" + itemType.getName() + ", " +
value.getClass().getName() + ").");
}
}
diff --git
a/contentparser/org-apache-sling-contentparser-api/src/test/java/org/apache/sling/contentparser/api/ParserHelperTest.java
b/contentparser/org-apache-sling-contentparser-api/src/test/java/org/apache/sling/contentparser/api/ParserHelperTest.java
index 2b2da48..7f57ff3 100644
---
a/contentparser/org-apache-sling-contentparser-api/src/test/java/org/apache/sling/contentparser/api/ParserHelperTest.java
+++
b/contentparser/org-apache-sling-contentparser-api/src/test/java/org/apache/sling/contentparser/api/ParserHelperTest.java
@@ -19,13 +19,17 @@
package org.apache.sling.contentparser.api;
import java.util.Calendar;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
-import static junit.framework.TestCase.assertEquals;
-import static junit.framework.TestCase.assertNull;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
public class ParserHelperTest {
@@ -54,4 +58,43 @@ public class ParserHelperTest {
}
}
}
+
+ @Test
+ public void convertSingleTypeArray() {
+ Object[] empty = new Object[]{};
+ assertEquals(empty, ParserHelper.convertSingleTypeArray(empty));
+
+ Object[] nullValues = new Object[] {"string", null};
+ ParseException nullValuesException = null;
+ try {
+ ParserHelper.convertSingleTypeArray(nullValues);
+ } catch (ParseException e) {
+ nullValuesException = e;
+ }
+ assertNotNull("Expected a ParseException when the Object array
contains multiple types.", nullValuesException);
+
+ Object[] maps = new Object[] {Collections.emptyMap()};
+ ParseException mapsException = null;
+ try {
+ ParserHelper.convertSingleTypeArray(maps);
+ } catch (ParseException e) {
+ mapsException = e;
+ }
+ assertNotNull("Expected a ParseException when the Object array
contains Map objects.", mapsException);
+
+ Object[] differentTypes = new Object[] {"string", 1, 1L, 1F,
Boolean.TRUE};
+ ParseException differentTypesException = null;
+ try {
+ ParserHelper.convertSingleTypeArray(differentTypes);
+ } catch (ParseException e) {
+ differentTypesException = e;
+ }
+ assertNotNull("Expected a ParseException when the Object array
contains multiple types.", differentTypesException);
+
+ Object[] values = new Object[] {1, 2, 3, 4, 5};
+ Object result = ParserHelper.convertSingleTypeArray(values);
+ assertTrue("Expected the resulting object to be an Integer array.",
result instanceof Integer[]);
+ Integer[] typedResult = (Integer[]) result;
+ assertArrayEquals("Expected the arrays to be equal.", new Integer[]
{1, 2, 3, 4, 5}, typedResult);
+ }
}