Merge pull request #1547 from hapifhir/do-20240118-fix-null-ex-on-xhtml-tostring

Handle toString for XhtmlNode when nodeType == null
This commit is contained in:
Grahame Grieve 2024-01-19 12:52:57 +11:00 committed by GitHub
commit 8a3f1037b3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 0 deletions

View File

@ -626,6 +626,9 @@ public class XhtmlNode extends XhtmlFluent implements IBaseXhtml {
@Override @Override
public String toString() { public String toString() {
if (nodeType == null) {
return super.toString();
}
switch (nodeType) { switch (nodeType) {
case Document: case Document:
case Element: case Element:

View File

@ -0,0 +1,16 @@
package org.hl7.fhir.utilities.xhtml;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class XhtmlTests {
@Test
public void testToStringOnNullType()
{
XhtmlNode node = new XhtmlNode(null, "Blah");
String actual = node.toString();
assertTrue(actual.startsWith("org.hl7.fhir.utilities.xhtml.XhtmlNode@"), "toString() should return java the toString default method for objects, which starts with the full class name");
}
}