<commit_before><commit_msg>add XmlUtilsTest<commit_after>/*
 * Copyright(C)  2017 大前良介(OH<NAME>)
 *
 * This software is released under the MIT License.
 * http://opensource.org/licenses/MIT
 */

package net.mm2d.util;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;

/**
 * @author <a href="mailto:<EMAIL>">大前良介(OH<NAME>)</a>
 */
@RunWith(JUnit4.class)
public class XmlUtilsTest {
    @Test
    public void getDocumentBuilder_NS_not_aware() throws Exception {
        final String xml = TestUtils.getResourceAsString("propchange.xml");
        final Document document = XmlUtils.newDocument(false, xml);
        final Element root = document.getDocumentElement();
        assertThat(root.getTagName(), is("e:propertyset"));
        assertThat(root.getNamespaceURI(), is(nullValue()));
    }

    @Test
    public void getDocumentBuilder_NS_aware() throws Exception {
        final String xml = TestUtils.getResourceAsString("propchange.xml");
        final Document document = XmlUtils.newDocument(true, xml);
        final Element root = document.getDocumentElement();
        assertThat(root.getTagName(), is("e:propertyset"));
        assertThat(root.getNamespaceURI(), is("urn:schemas-upnp-org:event-1-0"));
    }

    @Test
    public void findChildElementByLocalName() throws Exception {
        final String xml = TestUtils.getResourceAsString("propchange.xml");
        final Document document = XmlUtils.newDocument(true, xml);
        final Element root = document.getDocumentElement();
        final Element element = XmlUtils.findChildElementByLocalName(root, "property");
        assertThat(element.getTagName(), is("e:property"));
    }

    @Test
    public void findChildElementByLocalName_not_found() throws Exception {
        final String xml = TestUtils.getResourceAsString("propchange.xml");
        final Document document = XmlUtils.newDocument(true, xml);
        final Element root = document.getDocumentElement();
        final Element element = XmlUtils.findChildElementByLocalName(root, "propertys");
        assertThat(element, is(nullValue()));
    }
}
{'fraction_non_alphanumeric': 0.12017738359201774, 'fraction_numerical': 0.004878048780487805, 'mean_word_length': 3.980132450331126, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 12}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6953830', 'n_tokens_mistral': 652, 'n_tokens_neox': 643, 'n_words': 137}