• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

hazendaz / httpunit / #155

20 Aug 2024 11:42PM UTC coverage: 80.622% (+0.004%) from 80.618%
#155

push

github

hazendaz
[ci] format the code

3231 of 4119 branches covered (78.44%)

Branch coverage included in aggregate %.

68 of 80 new or added lines in 21 files covered. (85.0%)

4 existing lines in 4 files now uncovered.

8285 of 10165 relevant lines covered (81.51%)

0.82 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

70.11
/src/main/java/com/meterware/httpunit/dom/DocumentImpl.java
1
/*
2
 * MIT License
3
 *
4
 * Copyright 2011-2024 Russell Gold
5
 *
6
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
7
 * documentation files (the "Software"), to deal in the Software without restriction, including without limitation
8
 * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
9
 * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
10
 *
11
 * The above copyright notice and this permission notice shall be included in all copies or substantial portions
12
 * of the Software.
13
 *
14
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
15
 * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
17
 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
18
 * DEALINGS IN THE SOFTWARE.
19
 */
20
package com.meterware.httpunit.dom;
21

22
import java.util.Iterator;
23

24
import org.w3c.dom.Attr;
25
import org.w3c.dom.CDATASection;
26
import org.w3c.dom.Comment;
27
import org.w3c.dom.DOMConfiguration;
28
import org.w3c.dom.DOMException;
29
import org.w3c.dom.DOMImplementation;
30
import org.w3c.dom.Document;
31
import org.w3c.dom.DocumentFragment;
32
import org.w3c.dom.DocumentType;
33
import org.w3c.dom.Element;
34
import org.w3c.dom.EntityReference;
35
import org.w3c.dom.Node;
36
import org.w3c.dom.NodeList;
37
import org.w3c.dom.ProcessingInstruction;
38
import org.w3c.dom.Text;
39
import org.w3c.dom.html.HTMLElement;
40

41
/**
42
 * @author <a href="mailto:russgold@httpunit.org">Russell Gold</a>
43
 **/
44
public class DocumentImpl extends NodeImpl implements Document {
1✔
45

46
    private static final long serialVersionUID = 1L;
47
    protected Element _documentElement;
48

49
    static DocumentImpl createDocument() {
50
        DocumentImpl document = new DocumentImpl();
1✔
51
        document.initialize();
1✔
52
        return document;
1✔
53
    }
54

55
    protected void initialize() {
56
    }
1✔
57

58
    @Override
59
    public String getNodeName() {
60
        return "#document";
1✔
61
    }
62

63
    @Override
64
    public String getNodeValue() throws DOMException {
65
        return null;
1✔
66
    }
67

68
    @Override
69
    public void setNodeValue(String nodeValue) throws DOMException {
70
    }
1✔
71

72
    @Override
73
    public short getNodeType() {
74
        return DOCUMENT_NODE;
1✔
75
    }
76

77
    @Override
78
    public Document getOwnerDocument() {
79
        return this;
1✔
80
    }
81

82
    @Override
83
    public DocumentType getDoctype() {
84
        return null;
×
85
    }
86

87
    @Override
88
    public DOMImplementation getImplementation() {
89
        return null;
×
90
    }
91

92
    @Override
93
    public Element getDocumentElement() {
94
        return _documentElement;
1✔
95
    }
96

97
    void setDocumentElement(Element documentElement) {
98
        if (_documentElement != null) {
1✔
99
            throw new IllegalStateException("A document may have only one root");
1✔
100
        }
101
        _documentElement = documentElement;
1✔
102
        appendChild(documentElement);
1✔
103
    }
1✔
104

105
    @Override
106
    public Element createElement(String tagName) throws DOMException {
107
        return ElementImpl.createElement(this, tagName);
1✔
108
    }
109

110
    @Override
111
    public DocumentFragment createDocumentFragment() {
112
        throw new UnsupportedOperationException("DocumentFragment creation not supported ");
×
113
    }
114

115
    @Override
116
    public Text createTextNode(String data) {
117
        return TextImpl.createText(this, data);
1✔
118
    }
119

120
    @Override
121
    public Comment createComment(String data) {
122
        return CommentImpl.createComment(this, data);
1✔
123
    }
124

125
    @Override
126
    public CDATASection createCDATASection(String data) throws DOMException {
127
        return CDATASectionImpl.createCDATASection(this, data);
1✔
128
    }
129

130
    @Override
131
    public ProcessingInstruction createProcessingInstruction(String target, String data) throws DOMException {
132
        return ProcessingInstructionImpl.createProcessingImpl(this, target, data);
1✔
133
    }
134

135
    @Override
136
    public Attr createAttribute(String name) throws DOMException {
137
        return AttrImpl.createAttribute(this, name);
1✔
138
    }
139

140
    @Override
141
    public EntityReference createEntityReference(String name) throws DOMException {
142
        throw new UnsupportedOperationException("EntityReference creation not supported ");
×
143
    }
144

145
    @Override
146
    public Node importNode(Node importedNode, boolean deep) throws DOMException {
147
        switch (importedNode.getNodeType()) {
1!
148
            case Node.ATTRIBUTE_NODE:
149
                return AttrImpl.importNode(this, (Attr) importedNode);
1✔
150
            case Node.CDATA_SECTION_NODE:
151
                return CDATASectionImpl.importNode(this, (CDATASection) importedNode);
1✔
152
            case Node.COMMENT_NODE:
153
                return CommentImpl.importNode(this, (Comment) importedNode);
1✔
154
            case Node.ELEMENT_NODE:
155
                return ElementImpl.importNode(this, (Element) importedNode, deep);
1✔
156
            case Node.PROCESSING_INSTRUCTION_NODE:
157
                return ProcessingInstructionImpl.importNode(this, (ProcessingInstruction) importedNode);
1✔
158
            case Node.TEXT_NODE:
159
                return TextImpl.importNode(this, (Text) importedNode);
1✔
160
            default:
NEW
161
                throw new DOMException(DOMException.NOT_SUPPORTED_ERR,
×
NEW
162
                        "Cannot import node type " + importedNode.getNodeType());
×
163
        }
164
    }
165

166
    @Override
167
    public Element getElementById(String elementId) {
168
        for (Iterator each = preOrderIterator(); each.hasNext();) {
1✔
169
            Node node = (Node) each.next();
1✔
170
            if (!(node instanceof HTMLElement)) {
1✔
171
                continue;
1✔
172
            }
173
            HTMLElement element = (HTMLElement) node;
1✔
174
            if (elementId.equals(element.getId())) {
1✔
175
                return element;
1✔
176
            }
177
        }
1✔
178
        return null;
1✔
179
    }
180

181
    @Override
182
    public Element createElementNS(String namespaceURI, String qualifiedName) throws DOMException {
183
        return ElementImpl.createElement(this, namespaceURI, qualifiedName);
1✔
184
    }
185

186
    @Override
187
    public Attr createAttributeNS(String namespaceURI, String qualifiedName) throws DOMException {
188
        return AttrImpl.createAttribute(this, namespaceURI, qualifiedName);
1✔
189
    }
190

191
    @Override
192
    public NodeList getElementsByTagNameNS(String namespaceURI, String localName) {
193
        if (namespaceURI != null) {
×
194
            throw new UnsupportedOperationException("Namespaces are not supported");
×
195
        }
196
        return getElementsByTagName(localName);
×
197
    }
198

199
    /**
200
     * import the children
201
     *
202
     * @param original
203
     * @param copy
204
     */
205
    void importChildren(Node original, Node copy) {
206
        NodeList children = original.getChildNodes();
1✔
207
        for (int i = 0; i < children.getLength(); i++) {
1✔
208
            Node childCopy = importNode(children.item(i), /* deep */ true);
1✔
209
            copy.appendChild(childCopy);
1✔
210
        }
211
    }
1✔
212

213
    // ------------------------------------- DOM level 3 methods
214
    // ------------------------------------------------------------
215

216
    @Override
217
    public String getInputEncoding() {
218
        return null;
×
219
    }
220

221
    @Override
222
    public String getXmlEncoding() {
223
        return null;
×
224
    }
225

226
    @Override
227
    public Node renameNode(Node n, String namespaceURI, String qualifiedName) throws DOMException {
228
        return null;
×
229
    }
230

231
    @Override
232
    public boolean getXmlStandalone() {
233
        return false;
×
234
    }
235

236
    @Override
237
    public void setXmlStandalone(boolean xmlStandalone) throws DOMException {
238
    }
×
239

240
    @Override
241
    public String getXmlVersion() {
242
        return null;
×
243
    }
244

245
    @Override
246
    public void setXmlVersion(String xmlVersion) throws DOMException {
247
    }
×
248

249
    @Override
250
    public boolean getStrictErrorChecking() {
251
        return false;
×
252
    }
253

254
    @Override
255
    public void setStrictErrorChecking(boolean strictErrorChecking) {
256
    }
×
257

258
    @Override
259
    public String getDocumentURI() {
260
        return null;
×
261
    }
262

263
    @Override
264
    public void setDocumentURI(String documentURI) {
265
    }
×
266

267
    @Override
268
    public Node adoptNode(Node source) throws DOMException {
269
        return null;
×
270
    }
271

272
    @Override
273
    public DOMConfiguration getDomConfig() {
274
        return null;
×
275
    }
276

277
    @Override
278
    public void normalizeDocument() {
279
    }
×
280

281
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc