From 87fa224f4bb98ad0568a77c3ece3a7a30c9738fd Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Mon, 2 Oct 2023 00:48:39 +0200 Subject: [PATCH] Clean up XmlElementTest Use local variable type inference and text blocks. Change-Id: I471d99d11a493c46aba9a2e6fe868172edfc6a24 Signed-off-by: Robert Varga --- .../netconf/api/xml/XmlElementTest.java | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/protocol/netconf-api/src/test/java/org/opendaylight/netconf/api/xml/XmlElementTest.java b/protocol/netconf-api/src/test/java/org/opendaylight/netconf/api/xml/XmlElementTest.java index ea2dd98e2f..faa9f1610e 100644 --- a/protocol/netconf-api/src/test/java/org/opendaylight/netconf/api/xml/XmlElementTest.java +++ b/protocol/netconf-api/src/test/java/org/opendaylight/netconf/api/xml/XmlElementTest.java @@ -13,7 +13,6 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; -import java.util.Map.Entry; import java.util.Optional; import org.junit.Before; import org.junit.Test; @@ -22,26 +21,28 @@ import org.w3c.dom.Document; import org.w3c.dom.Element; public class XmlElementTest { - - private final String elementAsString = - "" - + "" + "deepValue" + "" - + "innerNamespaceValue" - + "b:valueWithPrefix" + ""; + private static final String ELEMENT_AS_STRING = """ + + + deepValue + + innerNamespaceValue + b:valueWithPrefix + """; private Document document; private Element element; private XmlElement xmlElement; @Before public void setUp() throws Exception { - document = XmlUtil.readXmlToDocument(elementAsString); + document = XmlUtil.readXmlToDocument(ELEMENT_AS_STRING); element = document.getDocumentElement(); xmlElement = XmlElement.fromDomElement(element); } @Test public void testConstruct() throws Exception { - final XmlElement fromString = XmlElement.fromString(elementAsString); + final XmlElement fromString = XmlElement.fromString(ELEMENT_AS_STRING); assertEquals(fromString, xmlElement); XmlElement.fromDomDocument(document); XmlElement.fromDomElement(element); @@ -79,13 +80,13 @@ public class XmlElementTest { assertTrue(xmlElement.getOnlyChildElementOptionally("innerNamespace", "innerNamespace").isPresent()); assertFalse(xmlElement.getOnlyChildElementOptionally("innerNamespace", "unknownNamespace").isPresent()); - final XmlElement noNamespaceElement = XmlElement.fromString(""); + final var noNamespaceElement = XmlElement.fromString(""); assertFalse(noNamespaceElement.hasNamespace()); assertThrows(MissingNameSpaceException.class, () -> noNamespaceElement.getNamespace()); - final XmlElement inner = xmlElement.getOnlyChildElement("inner"); - final XmlElement deepInner = inner.getOnlyChildElementWithSameNamespaceOptionally().orElseThrow(); + final var inner = xmlElement.getOnlyChildElement("inner"); + final var deepInner = inner.getOnlyChildElementWithSameNamespaceOptionally().orElseThrow(); assertEquals(deepInner, inner.getOnlyChildElementWithSameNamespace()); assertEquals(Optional.empty(), xmlElement.getOnlyChildElementOptionally("unknown")); assertEquals("deepValue", deepInner.getTextContent()); @@ -95,13 +96,13 @@ public class XmlElementTest { @Test public void testExtractNamespaces() throws Exception { - final XmlElement innerPrefixed = xmlElement.getOnlyChildElement("innerPrefixed"); - Entry namespaceOfTextContent = innerPrefixed.findNamespaceOfTextContent(); + final var innerPrefixed = xmlElement.getOnlyChildElement("innerPrefixed"); + var namespaceOfTextContent = innerPrefixed.findNamespaceOfTextContent(); assertNotNull(namespaceOfTextContent); assertEquals("b", namespaceOfTextContent.getKey()); assertEquals("prefixedValueNamespace", namespaceOfTextContent.getValue()); - final XmlElement innerNamespace = xmlElement.getOnlyChildElement("innerNamespace"); + final var innerNamespace = xmlElement.getOnlyChildElement("innerNamespace"); namespaceOfTextContent = innerNamespace.findNamespaceOfTextContent(); assertEquals("", namespaceOfTextContent.getKey()); -- 2.36.6