Author: scottbw
Date: Fri Apr 9 13:35:49 2010
New Revision: 932407
URL: http://svn.apache.org/viewvc?rev=932407&view=rev
Log:
Added check for null elements to XmlUtils, and added test cases to 100% coverage
Added:
incubator/wookie/trunk/parser/java/src-test/org/apache/wookie/w3c/test/XmlUtilsTest.java
Modified:
incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/util/XmlUtils.java
Added:
incubator/wookie/trunk/parser/java/src-test/org/apache/wookie/w3c/test/XmlUtilsTest.java
URL:
http://svn.apache.org/viewvc/incubator/wookie/trunk/parser/java/src-test/org/apache/wookie/w3c/test/XmlUtilsTest.java?rev=932407&view=auto
==============================================================================
---
incubator/wookie/trunk/parser/java/src-test/org/apache/wookie/w3c/test/XmlUtilsTest.java
(added)
+++
incubator/wookie/trunk/parser/java/src-test/org/apache/wookie/w3c/test/XmlUtilsTest.java
Fri Apr 9 13:35:49 2010
@@ -0,0 +1,69 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.wookie.w3c.test;
+
+import static org.junit.Assert.assertEquals;
+
+import org.jdom.Element;
+import org.junit.Test;
+import org.apache.wookie.w3c.util.XmlUtils;
+
+public class XmlUtilsTest {
+
+ @Test
+ public void testClass(){
+ @SuppressWarnings("unused")
+ XmlUtils utils = new XmlUtils();
+ }
+
+ @Test
+ public void nullContent(){
+ assertEquals("",XmlUtils.getTextContent(null));
+ }
+
+ @Test
+ public void singleElement(){
+ Element element = new Element("test");
+ assertEquals("",XmlUtils.getTextContent(element));
+ }
+
+ @Test
+ public void nestedElements(){
+ Element element = new Element("test");
+ Element child = new Element("test2");
+ element.addContent(child);
+ assertEquals("",XmlUtils.getTextContent(element));
+ }
+
+ @Test
+ public void singleElementWithContent(){
+ Element element = new Element("test");
+ element.setText("pass");
+ assertEquals("pass",XmlUtils.getTextContent(element));
+ }
+
+ @Test
+ public void nestedElementsWithContent(){
+ Element element = new Element("test");
+ element.setText("pa");
+ Element child = new Element("test2");
+ child.setText("ss");
+ element.addContent(child);
+ assertEquals("pass",XmlUtils.getTextContent(element));
+ }
+
+
+
+}
Modified:
incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/util/XmlUtils.java
URL:
http://svn.apache.org/viewvc/incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/util/XmlUtils.java?rev=932407&r1=932406&r2=932407&view=diff
==============================================================================
---
incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/util/XmlUtils.java
(original)
+++
incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/util/XmlUtils.java
Fri Apr 9 13:35:49 2010
@@ -30,6 +30,7 @@ public class XmlUtils {
* @return a string
*/
public static String getTextContent(Element element){
+ if (element == null) return "";
String content = "";
for (Object node:element.getContent()){
if (node instanceof Element){