mbeckerle commented on code in PR #7:
URL: https://github.com/apache/xerces-j/pull/7#discussion_r2019386129


##########
tests/loc/XercesDOMLocationTest.java:
##########
@@ -0,0 +1,124 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 loc;
+
+import org.apache.xerces.impl.Constants;
+import org.apache.xerces.parsers.DOMParser;
+import junit.framework.*;
+
+import static 
org.apache.xerces.parsers.XML11Configuration.LOCATION_INFO_FEATURE;
+
+import org.w3c.dom.*;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+public class XercesDOMLocationTest extends TestCase {
+
+    private static final String TEST_XML_PATH = "tests/loc/test.xml";
+
+    public XercesDOMLocationTest(String testName) {
+        super(testName);
+    }
+
+    public static List<Element> getElementChildren(Element parent) {
+        List<Element> result = new ArrayList<>();
+        NodeList children = parent.getChildNodes();
+        for (int i = 0; i < children.getLength(); i++) {
+            Node node = children.item(i);
+            if (node.getNodeType() == Node.ELEMENT_NODE) {
+                result.add((Element) node);
+            }
+        }
+        return result;
+    }
+
+    public static TestSuite suite() {
+        return new TestSuite(XercesDOMLocationTest.class);
+    }
+
+    private Document parseXML(boolean enableLocationFeature) throws Exception {
+        DOMParser parser = new DOMParser();
+        parser.setFeature(LOCATION_INFO_FEATURE, enableLocationFeature);
+        parser.parse(new File(TEST_XML_PATH).toURI().toString());
+        Document doc = parser.getDocument();
+        // inspect structure a bit to make sure the parse worked.
+        Element root = doc.getDocumentElement();
+        String name = root.getTagName();
+        assertEquals("root", name);
+        List<Element> ec = getElementChildren(root);
+        assertEquals(2, ec.size());
+        Element n1 = ec.get(0);
+        Element n2 = ec.get(1);
+        assertEquals("child", n1.getTagName());
+        assertEquals("selfClosing", n2.getTagName());
+        return doc;
+    }
+
+    public void testFeatureDisabledByDefault() throws Exception {
+        Document doc = parseXML(false); // Feature disabled
+        Element root = doc.getDocumentElement();
+        Object locationData = root.getUserData(Constants.LOCATION_INFO);
+        assertNull("Location data should not be present when feature is 
disabled.", locationData);
+    }
+
+    public void testFeatureEnabledLocationPresent() throws Exception {
+        Document doc = parseXML(true); // Feature enabled
+
+        Element root = doc.getDocumentElement();
+        Object locationData = root.getUserData(Constants.LOCATION_INFO);
+
+        assertNotNull("Location data should be present when feature is 
enabled.", locationData);
+        assertTrue("Location data should be an instance of String.", 
locationData instanceof String);

Review Comment:
   Not available until junit 5.10. The junit jar in the tools is 3.8.1. I'd 
prefer to stay out of tool updates for now. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to