Modified: xmlbeans/trunk/src/test/java/dom/common/CharacterDataTest.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/dom/common/CharacterDataTest.java?rev=1897795&r1=1897794&r2=1897795&view=diff ============================================================================== --- xmlbeans/trunk/src/test/java/dom/common/CharacterDataTest.java (original) +++ xmlbeans/trunk/src/test/java/dom/common/CharacterDataTest.java Sun Feb 6 01:51:55 2022 @@ -16,19 +16,21 @@ package dom.common; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.w3c.dom.CharacterData; import org.w3c.dom.DOMException; import org.w3c.dom.Node; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; -@Ignore +@Disabled public abstract class CharacterDataTest extends NodeTest { @Test - public void testAppendChild() { + void testAppendChild() { Node newChild = m_doc.createElement("foo"); try { m_node.appendChild(newChild); @@ -39,7 +41,7 @@ public abstract class CharacterDataTest //super method not relevant @Test - public void testInsertBefore() { + void testInsertBefore() { Node newChild = m_doc.createElement("foo"); assertFalse(m_node.hasChildNodes()); Node nullNode = m_node.getFirstChild(); @@ -51,12 +53,12 @@ public abstract class CharacterDataTest } @Test - public void testRemoveChild() { + void testRemoveChild() { assertFalse(m_node.hasChildNodes()); } @Test - public void testReplaceChild() { + void testReplaceChild() { Node newChild = m_doc.createElement("foo"); assertFalse(m_node.hasChildNodes()); if (m_node.getFirstChild() != null) @@ -70,17 +72,17 @@ public abstract class CharacterDataTest } @Test - public void testAppendData() { + void testAppendData() { String sOrig = ((CharacterData) m_node).getData(); String sNewData = "some new data"; ((CharacterData) m_node).appendData(sNewData); String sExpected = sOrig + sNewData; if (!(sExpected.equals(((CharacterData) m_node).getData()))) - fail(" Expected " + sExpected + " but got " + ((CharacterData) m_node).getData()); + Assertions.fail(" Expected " + sExpected + " but got " + ((CharacterData) m_node).getData()); } @Test - public void testAppendDataNull() { + void testAppendDataNull() { String sOrig = ((CharacterData) m_node).getData(); ((CharacterData) m_node).appendData(""); assertEquals(sOrig, ((CharacterData) m_node).getData()); @@ -90,31 +92,31 @@ public abstract class CharacterDataTest } @Test - public void testDeleteDataNegOff() { + void testDeleteDataNegOff() { _testDeleteData(-1, 10); } @Test - public void testDeleteDataNegLen() { + void testDeleteDataNegLen() { _testDeleteData(1, -10); } @Test - public void testDeleteDataLargeOff() { + void testDeleteDataLargeOff() { String sData = ((CharacterData) m_node).getData(); int nDataLen = sData.length(); _testDeleteData(nDataLen + 1, 10); } @Test - public void testDeleteDataLargeLen() { + void testDeleteDataLargeLen() { String sData = ((CharacterData) m_node).getData(); int nDataLen = sData.length(); _testDeleteData(0, nDataLen + 30); } @Test - public void testDeleteDataAverage() { + void testDeleteDataAverage() { String sData = ((CharacterData) m_node).getData(); int nDataLen = sData.length(); _testDeleteData(0, nDataLen / 2); @@ -126,7 +128,7 @@ public abstract class CharacterDataTest if (offset < 0 || offset > nDataLen || count < 0) try { ((CharacterData) m_node).deleteData(offset, count); - fail("Deleting OOB chars"); + Assertions.fail("Deleting OOB chars"); } catch (DOMException de) { assertEquals(de.code, DOMException.INDEX_SIZE_ERR); } @@ -145,7 +147,7 @@ public abstract class CharacterDataTest } @Test - public void testGetData() { + void testGetData() { char[] buff = new char[200]; java.util.Arrays.fill(buff, 'a'); ((CharacterData) m_node).setData(new String(buff)); @@ -158,30 +160,30 @@ public abstract class CharacterDataTest } @Test - public void testGetLength() { + void testGetLength() { int nDataLen = ((CharacterData) m_node).getData().length(); assertEquals(((CharacterData) m_node).getLength(), nDataLen); } @Test - public void testInsertNull() { + void testInsertNull() { _testInsertData(0, null); } @Test - public void testInsertNeg() { + void testInsertNeg() { _testInsertData(-1, "foo"); } @Test - public void testInsertOOB() { + void testInsertOOB() { String sData = ((CharacterData) m_node).getData(); int nDataLen = sData.length(); _testInsertData(nDataLen + 2, "foo"); } @Test - public void testInsertAverage() { + void testInsertAverage() { String sData = ((CharacterData) m_node).getData(); int nDataLen = sData.length(); _testInsertData(nDataLen / 2, "foobar"); @@ -193,7 +195,7 @@ public abstract class CharacterDataTest if (offset < 0 || offset > nDataLen) try { ((CharacterData) m_node).insertData(offset, toInsert); - fail("Inserting OOB chars"); + Assertions.fail("Inserting OOB chars"); } catch (DOMException de) { assertEquals(de.code, DOMException.INDEX_SIZE_ERR); } @@ -209,57 +211,56 @@ public abstract class CharacterDataTest System.out.println(offset + toInsert.length()); String s1 = sData.substring(0, offset); String s2 = sData.substring(offset, nDataLen); - assertEquals(s1 + toInsert + s2 - , ((CharacterData) m_node).getData()); + assertEquals(s1 + toInsert + s2, ((CharacterData) m_node).getData()); } } } @Test - public void testReplaceDataNull() { + void testReplaceDataNull() { String sData = ((CharacterData) m_node).getData(); int nDataLen = sData.length(); _testReplaceData(0, nDataLen, null); } @Test - public void testReplaceDataNegOff() { + void testReplaceDataNegOff() { _testReplaceData(-1, 3, "foo"); } @Test - public void testReplaceDataNegCount() { + void testReplaceDataNegCount() { _testReplaceData(1, -3, "foo"); } @Test - public void testReplaceDataZeroCount() { + void testReplaceDataZeroCount() { _testReplaceData(1, 0, "foo"); } @Test - public void testReplaceDataLargeOff() { + void testReplaceDataLargeOff() { String sData = ((CharacterData) m_node).getData(); int nDataLen = sData.length(); _testReplaceData(nDataLen + 1, 2, "foo"); } @Test - public void testReplaceDataLargeCount() { + void testReplaceDataLargeCount() { String sData = ((CharacterData) m_node).getData(); int nDataLen = sData.length(); _testReplaceData(0, nDataLen + 2, "foo"); } @Test - public void testReplaceDataLarge() { + void testReplaceDataLarge() { String sData = ((CharacterData) m_node).getData(); int nDataLen = sData.length(); _testReplaceData(nDataLen / 2, nDataLen / 2 + 1, "foo"); } @Test - public void testReplaceDataAverage() { + void testReplaceDataAverage() { String sData = ((CharacterData) m_node).getData(); int nDataLen = sData.length(); _testReplaceData(nDataLen / 2, nDataLen / 2, "foobar"); @@ -272,7 +273,7 @@ public abstract class CharacterDataTest if (offset < 0 || offset > nDataLen || count < 0) try { ((CharacterData) m_node).replaceData(offset, count, newStr); - fail("Deleting OOB chars"); + Assertions.fail("Deleting OOB chars"); } catch (DOMException de) { assertEquals(de.code, DOMException.INDEX_SIZE_ERR); } @@ -289,44 +290,43 @@ public abstract class CharacterDataTest } else if (offset == 0) assertEquals(sData.substring(count, sData.length() - count) + newStr, ((CharacterData) m_node).getData()); else - assertEquals(sData.substring(0, offset) + newStr + sData.substring(offset + count), - ((CharacterData) m_node).getData()); + assertEquals(sData.substring(0, offset) + newStr + sData.substring(offset + count), ((CharacterData) m_node).getData()); } } @Test - public void testSetDataNull() { + void testSetDataNull() { ((CharacterData) m_node).setData(null); assertEquals("", ((CharacterData) m_node).getData()); } @Test - public void testSubstringDataNegOff() { + void testSubstringDataNegOff() { _testSubstringData(-1, 10); } @Test - public void testSubstringDataNegLen() { + void testSubstringDataNegLen() { _testSubstringData(1, -10); } @Test - public void testSubstringDataLargeOff() { + void testSubstringDataLargeOff() { String sData = ((CharacterData) m_node).getData(); int nDataLen = sData.length(); _testSubstringData(nDataLen + 1, 10); } @Test - public void testSubstringDataLargeLen() { + void testSubstringDataLargeLen() { String sData = ((CharacterData) m_node).getData(); int nDataLen = sData.length(); _testSubstringData(0, nDataLen + 30); } @Test - public void testSubstringDataAverage() { + void testSubstringDataAverage() { String sData = ((CharacterData) m_node).getData(); int nDataLen = sData.length(); _testSubstringData(0, nDataLen / 2); @@ -339,7 +339,7 @@ public abstract class CharacterDataTest if (offset < 0 || offset > nDataLen || count < 0) try { ((CharacterData) m_node).substringData(offset, count); - fail("Deleting OOB chars"); + Assertions.fail("Deleting OOB chars"); } catch (DOMException de) { assertEquals(de.code, DOMException.INDEX_SIZE_ERR); } @@ -355,10 +355,10 @@ public abstract class CharacterDataTest } @Test - public void testSetPrefix() { + protected void testSetPrefix() { try { m_node.setPrefix("foobar"); - fail("Can't set prefix on node other than Element or Attribute"); + Assertions.fail("Can't set prefix on node other than Element or Attribute"); } catch (DOMException de) { assertEquals(DOMException.NAMESPACE_ERR, de.code); }
Modified: xmlbeans/trunk/src/test/java/dom/common/DomUtils.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/dom/common/DomUtils.java?rev=1897795&r1=1897794&r2=1897795&view=diff ============================================================================== --- xmlbeans/trunk/src/test/java/dom/common/DomUtils.java (original) +++ xmlbeans/trunk/src/test/java/dom/common/DomUtils.java Sun Feb 6 01:51:55 2022 @@ -20,6 +20,8 @@ import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import org.w3c.dom.NodeList; +import java.util.Objects; + public class DomUtils { @@ -91,10 +93,10 @@ public class DomUtils { if (pre1 == null && pre2 == null) return true; if (pre1 == null && pre2.equals("")) return true; - if (pre1.equals("") && pre2 == null) + if ("".equals(pre1) && pre2 == null) return true; else - return pre1.equals(pre2); + return Objects.equals(pre1,pre2); } @@ -107,7 +109,7 @@ public class DomUtils throws IllegalStateException { if (n1 == n2 && n1 == null) return true; - if (n1 == null && n2 != null || n2 == null && n1 != null) return false; + if (n1 == null || n2 == null) return false; if (!(n1.getNodeName().equals(n2.getNodeName()) && compareNull(n1.getNamespaceURI(), n2.getNamespaceURI()) && compareNull(n1.getPrefix(), n2.getPrefix())) @@ -143,22 +145,6 @@ public class DomUtils return true; } - /** - * the two node lists really are the same list - */ - public static boolean compareNodeTreePtr(NodeList lst1, NodeList lst2) - { - if (lst1.getLength() != lst2.getLength()) - return false; - - for (int i = 0; i < lst1.getLength(); i++) - { - if (lst1.item(i) != lst2.item(i)) - return false; - } - return true; - } - public static boolean compareNodeTreeValue(NodeList lst1, NodeList lst2) { if (lst1.getLength() != lst2.getLength()) Modified: xmlbeans/trunk/src/test/java/dom/common/NodeTest.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/dom/common/NodeTest.java?rev=1897795&r1=1897794&r2=1897795&view=diff ============================================================================== --- xmlbeans/trunk/src/test/java/dom/common/NodeTest.java (original) +++ xmlbeans/trunk/src/test/java/dom/common/NodeTest.java Sun Feb 6 01:51:55 2022 @@ -15,9 +15,10 @@ package dom.common; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.w3c.dom.DOMException; import org.w3c.dom.Document; import org.w3c.dom.Node; @@ -26,9 +27,9 @@ import org.xml.sax.InputSource; import java.io.StringReader; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -@Ignore +@Disabled public abstract class NodeTest implements TestSetup { protected Node m_node; @@ -40,44 +41,44 @@ public abstract class NodeTest implement //attributes @Test - public void testOwnerDocument() { + protected void testOwnerDocument() { assertEquals(m_doc, m_node.getOwnerDocument()); } @Test - public void testPrefix() { + protected void testPrefix() { assertNotNull(m_node); assertNull(m_node.getPrefix()); - // assertEquals("", m_node.getPrefix()); + // assertEquals("", m_node.getPrefix()); } @Test - public void testNamespaceUri() { + protected void testNamespaceUri() { assertNotNull(m_node); assertNull(m_node.getNamespaceURI()); //assertEquals("", m_node.getNamespaceURI()); } @Test - public void testLocalName() { + protected void testLocalName() { assertNotNull(m_node); assertNull(m_node.getLocalName()); - // assertEquals("", m_node.getLocalName()); + // assertEquals("", m_node.getLocalName()); } //0 length list as of API @Test - public void testGetChildNodes() { + protected void testGetChildNodes() { assertEquals(0, m_node.getChildNodes().getLength()); } @Test - public void testFirstChild() { + protected void testFirstChild() { assertNull(m_node.getFirstChild()); } @Test - public void testLastChild() { + protected void testLastChild() { assertNull(m_node.getLastChild()); } @@ -88,12 +89,13 @@ public abstract class NodeTest implement */ protected void testAppendChild(Node newChild) { Node inserted = m_node.appendChild(newChild); - if (newChild.getNodeType() == Node.DOCUMENT_FRAGMENT_NODE) + if (newChild.getNodeType() == Node.DOCUMENT_FRAGMENT_NODE) { assertTrue(compareNodeListPrefix(newChild.getChildNodes(), m_node.getChildNodes())); - else + } else { assertEquals(inserted, m_node.getLastChild()); + } if (isInTree(m_node, newChild)) //new child is in the tree - //$NOTE: assert the child is removed first + //$NOTE: assert the child is removed first ; } @@ -104,10 +106,10 @@ public abstract class NodeTest implement * $TODO: ER results in a mutable copy */ @Test - public void testCloneNode() { + protected void testCloneNode() { Node m_clone; - m_clone=m_node.cloneNode(false); + m_clone = m_node.cloneNode(false); assertTrue(DomUtils.compareNodesShallow(m_node, m_clone)); // assertEquals(true, DomUtils.compareNodeTreePtr(m_clone.getChildNodes(),m_node.getChildNodes())); //ptr eq for ch. assertNotSame(m_clone, m_node); @@ -125,33 +127,32 @@ public abstract class NodeTest implement int newChPos = getChildPos(m_node, newChild); int pos = getChildPos(m_node, refChild); Node prevParent = null; - if (newChPos > -1) + if (newChPos > -1) { prevParent = newChild.getParentNode(); + } NodeList childNodes = m_node.getChildNodes(); int nOrigChildNum = childNodes.getLength(); //get it now, List is live if (newChild == null) { - try { - m_node.insertBefore(newChild, refChild); - fail("Inserting null"); - } catch (IllegalArgumentException e) { - return; - } + assertThrows(IllegalArgumentException.class, () -> m_node.insertBefore(newChild, refChild), "Inserting null"); + return; } Node inserted = m_node.insertBefore(newChild, refChild); - if (refChild == null) + if (refChild == null) { assertEquals(inserted, m_node.getLastChild()); - else if (pos == -1)//would have thrown exc - fail("Inserting after fake child"); - else if (newChild.getNodeType() == Node.DOCUMENT_FRAGMENT_NODE) + } else if (pos == -1) { + //would have thrown exc + Assertions.fail("Inserting after fake child"); + } else if (newChild.getNodeType() == Node.DOCUMENT_FRAGMENT_NODE) { assertTrue(compareNodeListPrefix(newChild.getChildNodes(), m_node.getChildNodes())); - else if (newChPos != -1) //new child is in the tree - //assert the child is removed first + } else if (newChPos != -1) { + //new child is in the tree + //assert the child is removed first assertNotEquals(inserted.getParentNode(), prevParent); - else { + } else { assertEquals(newChild, childNodes.item(pos)); assertEquals(nOrigChildNum + 1, m_node.getChildNodes().getLength()); } @@ -162,35 +163,33 @@ public abstract class NodeTest implement * $NOTE: override for element */ @Test - public void testGetAttributes() { + protected void testGetAttributes() { assertNull(m_node.getAttributes()); } @Test - public void testHasChildNodes() { + protected void testHasChildNodes() { int i = m_node.getChildNodes().getLength(); - if (i > 0) + if (i > 0) { assertTrue(m_node.hasChildNodes()); - else + } else { assertFalse(m_node.hasChildNodes()); + } } //Override for Element @Test - public void testHasAttributes() { + protected void testHasAttributes() { assertFalse(m_node.hasAttributes()); } @Test - public void testIsSupported() { - String[] features=new String[]{ - "Core","XML","Events","MutationEvents","Range","Traversal","HTML","Views","StyleSheets","CSS","CSS2","UIEvents","HTMLEvents" + protected void testIsSupported() { + String[] features = new String[]{ + "Core", "XML", "Events", "MutationEvents", "Range", "Traversal", "HTML", "Views", "StyleSheets", "CSS", "CSS2", "UIEvents", "HTMLEvents" }; - boolean bResult=true; - for (int i=0;i<features.length;i++){ - if (i>1) bResult=false; - System.out.println("============== "+features[i]+" ============="+bResult); - assertEquals(bResult,m_node.isSupported(features[i],"2.0")); + for (String feature : features) { + assertEquals("Core,XML".contains(feature) , m_node.isSupported(feature, "2.0")); } } @@ -198,25 +197,14 @@ public abstract class NodeTest implement void testRemoveChild(Node removed) { int pos = getChildPos(m_node, removed); int len = m_node.getChildNodes().getLength(); - if (removed == null) - try { - m_node.removeChild(removed); - fail("Should not be Removing non-existing node"); - } catch (DOMException de) { - assertEquals(DOMException.NOT_FOUND_ERR, de.code); - } - else if (pos == -1) - try { - m_node.removeChild(removed); - fail("Removing non-existing node"); - } catch (DOMException de) { - throw de; - } - else { + if (removed == null) { + DOMException de = assertThrows(DOMException.class, () -> m_node.removeChild(removed), "Should not be Removing non-existing node"); + } else if (pos == -1) { + throw assertThrows(DOMException.class, () -> m_node.removeChild(removed), "Removing non-existing node"); + } else { m_node.removeChild(removed); assertEquals(len - 1, m_node.getChildNodes().getLength()); } - } /** @@ -232,18 +220,11 @@ public abstract class NodeTest implement if (newChild == null) { - try { - m_node.replaceChild(newChild, oldChild); - fail("Inserting null"); - } catch (IllegalArgumentException e) { - } + assertThrows(IllegalArgumentException.class, () -> m_node.replaceChild(newChild, oldChild), "Inserting null"); } else if (pos == -1) { - try { - m_node.replaceChild(newChild, oldChild); - fail("Replacing non-existing node"); - } catch (DOMException de) { - if (DOMException.NOT_FOUND_ERR != de.code) - throw de; + DOMException de = assertThrows(DOMException.class, () -> m_node.replaceChild(newChild, oldChild), "Replacing non-existing node"); + if (DOMException.NOT_FOUND_ERR != de.code) { + throw de; } } else if (existing) { Node oldParent = newChild.getParentNode(); @@ -254,110 +235,130 @@ public abstract class NodeTest implement int new_len = newChild.getChildNodes().getLength(); assertEquals(oldChild, m_node.replaceChild(newChild, oldChild)); assertEquals(new_len + len - 1, m_node.getChildNodes().getLength());//new+old-one replaced - } else + } else { m_node.replaceChild(newChild, oldChild); + } } //$NOTE:override for element and attribute @Test - public void testSetPrefix() - { + protected void testSetPrefix() { //any prefix here is invalid - String val = null; - val = "blah"; //Eric's default - try - { - m_node.setPrefix(val); - fail(" set prefix only works for at/elt"); - } - catch (DOMException de) - { - assertEquals(DOMException.NAMESPACE_ERR, de.code); - } + String val = "blah"; //Eric's default + DOMException de = assertThrows(DOMException.class, () -> m_node.setPrefix(val), "set prefix only works for at/elt"); + assertEquals(DOMException.NAMESPACE_ERR, de.code); } private static int getChildPos(Node node, Node child) { - if (child == null) return -1; + if (child == null) { + return -1; + } NodeList ch = node.getChildNodes(); - for (int i = 0; i < ch.getLength(); i++) - if (ch.item(i) == child) + for (int i = 0; i < ch.getLength(); i++) { + if (ch.item(i) == child) { return i; + } + } return -1; } private static boolean isInTree(Node root, Node find) { - if (find == null) return false; - if (root == null) return false; - if (root == find) return true; + if (find == null) { + return false; + } + if (root == null) { + return false; + } + if (root == find) { + return true; + } NodeList ch = root.getChildNodes(); boolean temp_res = false; - for (int i = 0; i < ch.getLength(); i++) + for (int i = 0; i < ch.getLength(); i++) { temp_res = temp_res || isInTree(ch.item(i), find); + } return temp_res; } protected static boolean compareNodeList(NodeList l1, NodeList l2) { - if (l1.getLength() != l2.getLength()) return false; - for (int i = 0; i < l1.getLength(); i++) - if (l1.item(i) != l2.item(i)) //pointer eq + if (l1.getLength() != l2.getLength()) { + return false; + } + for (int i = 0; i < l1.getLength(); i++) { + //pointer eq + if (l1.item(i) != l2.item(i)) { return false; + } + } return true; } //l1 is a prefix of l2 private static boolean compareNodeListPrefix(NodeList l1, NodeList l2) { - if (l1.getLength() > l2.getLength()) return false; - for (int i = 0; i < l1.getLength(); i++) - if (l1.item(i) != l2.item(i)) //pointer eq + if (l1.getLength() > l2.getLength()) { + return false; + } + for (int i = 0; i < l1.getLength(); i++) { + //pointer eq + if (l1.item(i) != l2.item(i)) { return false; + } + } return true; } public void loadSync() { _loader = Loader.getLoader(); - if (sXml == null && sXmlNS == null) throw new IllegalArgumentException("Test bug : Initialize xml strings"); - m_doc = (org.w3c.dom.Document) _loader.loadSync(sXml); - if (sXmlNS != null && sXmlNS.length() > 0) - m_docNS = (org.w3c.dom.Document) _loader.loadSync(sXmlNS); + if (sXml == null && sXmlNS == null) { + throw new IllegalArgumentException("Test bug : Initialize xml strings"); + } + m_doc = _loader.loadSync(sXml); + if (sXmlNS != null && sXmlNS.length() > 0) { + m_docNS = _loader.loadSync(sXmlNS); + } } - - public static Node getApacheNode(String sXml,boolean namespace,char type) - throws Exception{ + + public static Node getApacheNode(String sXml, boolean namespace, char type) + throws Exception { org.apache.xerces.parsers.DOMParser parser = new org.apache.xerces.parsers.DOMParser(); parser.parse(new InputSource(new StringReader(sXml))); - Document doc = parser.getDocument(); + Document doc = parser.getDocument(); - String name="apache_node"; - String nsname="pre:apache_node"; - String uri="uri:apache:test"; - - switch(type){ - case 'A': - if (namespace) - return doc.createAttributeNS(uri,nsname); - else - return doc.createAttribute(name); - case 'E': - if (namespace) - return doc.createElementNS(uri,nsname); - else return doc.createElement(name); - default: return doc.createTextNode(name); + String name = "apache_node"; + String nsname = "pre:apache_node"; + String uri = "uri:apache:test"; + + switch (type) { + case 'A': + if (namespace) { + return doc.createAttributeNS(uri, nsname); + } else { + return doc.createAttribute(name); + } + case 'E': + if (namespace) { + return doc.createElementNS(uri, nsname); + } else { + return doc.createElement(name); + } + default: + return doc.createTextNode(name); } - + } //exposing a node for other tests...saver in particular - public Node getNode(){ + public Node getNode() { return m_node; } - @Before + @BeforeEach public void setUp() throws Exception { //m_doc=(org.w3c.dom.Document)org.apache.xmlbeans.XmlObject.Factory.parse(xml).newDomNode(); _loader = Loader.getLoader(); @@ -366,8 +367,9 @@ public abstract class NodeTest implement throw new IllegalArgumentException("Test bug : Initialize xml strings"); } m_doc = _loader.load(sXml); - if (sXmlNS != null && sXmlNS.length() > 0) + if (sXmlNS != null && sXmlNS.length() > 0) { m_docNS = _loader.load(sXmlNS); + } } private Loader _loader; Modified: xmlbeans/trunk/src/test/java/dom/common/NodeWithChildrenTest.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/dom/common/NodeWithChildrenTest.java?rev=1897795&r1=1897794&r2=1897795&view=diff ============================================================================== --- xmlbeans/trunk/src/test/java/dom/common/NodeWithChildrenTest.java (original) +++ xmlbeans/trunk/src/test/java/dom/common/NodeWithChildrenTest.java Sun Feb 6 01:51:55 2022 @@ -15,23 +15,23 @@ package dom.common; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.w3c.dom.CharacterData; import org.w3c.dom.*; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -public abstract class NodeWithChildrenTest extends NodeTest { +public abstract class NodeWithChildrenTest extends NodeTest { @Test - public void testRemoveChildEnd() { + void testRemoveChildEnd() { Node node = m_node.getLastChild(); super.testRemoveChild(node); } @Test - public void testRemoveChild() { + void testRemoveChild() { NodeList children = m_node.getChildNodes(); int pos = children.getLength() / 2; Node node = children.item(pos); @@ -40,35 +40,35 @@ public abstract class NodeWithChildrenTe } @Test - public void testRemoveChildDiffImpl() throws Exception { + void testRemoveChildDiffImpl() throws Exception { Node toRemove = NodeTest.getApacheNode(sXml,true,'E'); - DOMException de = assertThrows("Removing node from a different impl", - DOMException.class, () -> super.testRemoveChild(toRemove)); + DOMException de = assertThrows(DOMException.class, () -> super.testRemoveChild(toRemove), + "Removing node from a different impl"); assertEquals(de.code, DOMException.WRONG_DOCUMENT_ERR); } @Test - public void testRemoveChildDiffDoc() throws Exception { + void testRemoveChildDiffDoc() { Node toRemove = m_docNS.getDocumentElement(); - DOMException de = assertThrows("Removing node from a different doc", - DOMException.class, () -> super.testRemoveChild(toRemove)); + DOMException de = assertThrows(DOMException.class, + () -> super.testRemoveChild(toRemove), "Removing node from a different doc"); assertEquals(de.code, DOMException.WRONG_DOCUMENT_ERR); } @Test - public void testRemoveChildFront() { + void testRemoveChildFront() { Node node = m_node.getFirstChild(); super.testRemoveChild(node); } @Test - public void testRemoveChildNull() { + void testRemoveChildNull() { super.testRemoveChild(null); } @Test - public void testReplaceChild() { + void testReplaceChild() { NodeList children = m_node.getChildNodes(); int pos = children.getLength() / 2; Node newNode = (m_node instanceof Document) @@ -79,21 +79,21 @@ public abstract class NodeWithChildrenTe } @Test - public void testReplaceChildEnd() { + void testReplaceChildEnd() { Node node = m_node.getLastChild(); Node newNode = m_doc.createTextNode("fooBAR"); super.testReplaceChild(newNode, node); } @Test - public void testReplaceChildFront() { + void testReplaceChildFront() { Node node = m_node.getFirstChild(); Node newNode = m_doc.createTextNode("fooBAR"); super.testReplaceChild(newNode, node); } @Test - public void testReplaceChildNullChild() { + void testReplaceChildNullChild() { Node node = m_node.getChildNodes().item(0); Node newNode = null; assertNotNull(node); @@ -101,7 +101,7 @@ public abstract class NodeWithChildrenTe } @Test - public void testReplaceChildNull() { + void testReplaceChildNull() { Node node = null; Node newNode = (m_node instanceof Document) ? ((Document) m_node).createElement("fooBAR") @@ -110,78 +110,57 @@ public abstract class NodeWithChildrenTe } @Test - public void testReplaceChildDNE() { + void testReplaceChildDNE() { if (m_doc == null) { assertEquals(m_doc, m_node.getOwnerDocument()); } //node to replace is not a child - Node node =m_doc.createElement("foobar"); - Node newNode = m_doc.createElement("fooBAR"); + Node node1 =m_doc.createElement("foobar"); + Node newNode1a = m_doc.createElement("fooBAR"); try { - super.testReplaceChild(newNode, node); + super.testReplaceChild(newNode1a, node1); } catch (DOMException de) { assertEquals(DOMException.NOT_FOUND_ERR, de.code);//Raised if oldChild is not a child of this node. } //newChild was created from a different document than the one that created this node - newNode = m_docNS.createElement("fooBAR"); + Node newNode1b = m_docNS.createElement("fooBAR"); assertNotEquals(m_docNS, m_node.getOwnerDocument()); - try { - super.testReplaceChild(newNode, node); - fail("Node is from the wrong document"); - } catch (DOMException de) { - assertEquals(DOMException.WRONG_DOCUMENT_ERR, de.code); - } - //refChild was created from a different document than the one that created this node + DOMException de2 = assertThrows(DOMException.class, () -> super.testReplaceChild(newNode1b, node1), "Node is from the wrong document"); + assertEquals(DOMException.WRONG_DOCUMENT_ERR, de2.code); - node = m_docNS.createElement("fooBAR"); - newNode=m_doc.createElement("fooBAR"); - try { - super.testReplaceChild(newNode, node); - fail("Node is from the wrong document"); - } catch (DOMException de) { - assertTrue( - (DOMException.WRONG_DOCUMENT_ERR == de.code) - || (DOMException.NOT_FOUND_ERR == de.code) - ); - } + //refChild was created from a different document than the one that created this node + Node node2 = m_docNS.createElement("fooBAR"); + Node newNode2 =m_doc.createElement("fooBAR"); + DOMException de3 = assertThrows(DOMException.class, () -> super.testReplaceChild(newNode2, node2), "Node is from the wrong document"); + assertTrue((DOMException.WRONG_DOCUMENT_ERR == de3.code) || (DOMException.NOT_FOUND_ERR == de3.code)); } // public void testInsertBeforeDiffDoc(){}:done above @Test - public void testReplace_replacement_DiffImpl() throws Exception { + void testReplace_replacement_DiffImpl() throws Exception { Node node = m_node.getFirstChild(); Node newnode=NodeTest.getApacheNode(sXml,true,'T'); - try { - super.testReplaceChild(newnode, node); - fail("Inserting node created from a different impl"); - } catch (DOMException de) { - assertEquals(de.code, DOMException.WRONG_DOCUMENT_ERR); - } - + DOMException de = assertThrows(DOMException.class, () -> super.testReplaceChild(newnode, node), "Inserting node created from a different impl"); + assertEquals(de.code, DOMException.WRONG_DOCUMENT_ERR); } //ref child is diff impl @Test - public void testReplace_target_DiffImpl() throws Exception { + void testReplace_target_DiffImpl() throws Exception { Node node =NodeTest.getApacheNode(sXml,true,'E'); Node newnode=m_node.getFirstChild(); - try { - super.testReplaceChild(newnode, node); - fail("Inserting node created from a different impl"); - } catch (DOMException de) { - assertEquals(de.code, DOMException.WRONG_DOCUMENT_ERR); - } - + DOMException de = assertThrows(DOMException.class, () -> super.testReplaceChild(newnode, node), "Inserting node created from a different impl"); + assertEquals(de.code, DOMException.WRONG_DOCUMENT_ERR); } @Test - public void testReplaceChildDocFrag() { + protected void testReplaceChildDocFrag() { DocumentFragment child = m_doc.createDocumentFragment(); child.appendChild(m_doc.createElement("foo")); child.appendChild(m_doc.createElement("foobar")); @@ -190,7 +169,7 @@ public abstract class NodeWithChildrenTe } @Test - public void testInsertBefore() { + protected void testInsertBefore() { Node target = m_node.getFirstChild(); Node child = m_doc.createElementNS("org.foo.www", "foonode"); assertNotNull(target); @@ -198,82 +177,55 @@ public abstract class NodeWithChildrenTe } @Test - public void testInsertBeforeNullTarget() { + protected void testInsertBeforeNullTarget() { Node child = m_doc.createElementNS("org.foo.www", "foonode"); super.testInsertBefore(child, null); } @Test - public void testInsertBeforeInvalidRefNode() { + void testInsertBeforeInvalidRefNode() { Node child = m_doc.createElementNS("org.foo.www", "foonode"); Node target = m_doc.createElement("foo"); - DOMException de = assertThrows(DOMException.class, () -> super.testInsertBefore(child, target)); + DOMException de = assertThrows(DOMException.class, () -> super.testInsertBefore(child, target), "Insert cannot happen"); assertEquals(DOMException.NOT_FOUND_ERR, de.code); - -// try { -// super.testInsertBefore(child, target); -// fail("Insert cannot happen"); -// } catch (DOMException de) { -// System.err.println(de.getMessage() + " " + de.code); -// assertEquals(DOMException.NOT_FOUND_ERR, de.code); -// } } @Test - public void testInsertBeforeNewChildDiffDoc(){ + void testInsertBeforeNewChildDiffDoc(){ Node target = m_node.getFirstChild(); Node toInsert=m_docNS.getDocumentElement(); - try { - super.testInsertBefore(toInsert, target); - fail("Inserting node created from a different doc"); - } catch (DOMException de) { - assertEquals(de.code, DOMException.WRONG_DOCUMENT_ERR); - } - - + DOMException de = assertThrows(DOMException.class, () -> super.testInsertBefore(toInsert, target), "Inserting node created from a different doc"); + assertEquals(de.code, DOMException.WRONG_DOCUMENT_ERR); } @Test - public void testInsertBeforeNewChildDiffImpl() throws Exception { + void testInsertBeforeNewChildDiffImpl() throws Exception { Node target = m_node.getFirstChild(); Node toInsert=NodeTest.getApacheNode(sXml,true,'T'); - try { - super.testInsertBefore(toInsert, target); - fail("Inserting node created from a different impl"); - } catch (DOMException de) { - assertEquals(de.code, DOMException.WRONG_DOCUMENT_ERR); - } - + DOMException de = assertThrows(DOMException.class, () -> super.testInsertBefore(toInsert, target), "Inserting node created from a different impl"); + assertEquals(de.code, DOMException.WRONG_DOCUMENT_ERR); } @Test - public void testInsertBeforeRefChildDiffDoc(){ + void testInsertBeforeRefChildDiffDoc(){ Node target = m_docNS.getDocumentElement(); Node toInsert = m_node.getFirstChild(); - try { - super.testInsertBefore(toInsert, target); - fail("Ref Child from a different doc"); - } catch (DOMException de) { - assertEquals(de.code, DOMException.WRONG_DOCUMENT_ERR); - } + DOMException de = assertThrows(DOMException.class, () -> super.testInsertBefore(toInsert, target), "Ref Child from a different doc"); + assertEquals(de.code, DOMException.WRONG_DOCUMENT_ERR); } @Test - public void testInsertBeforeRefChildDiffImpl() throws Exception { + void testInsertBeforeRefChildDiffImpl() throws Exception { Node target = NodeTest.getApacheNode(sXml, true, 'T'); Node toInsert = m_node.getFirstChild(); - try { - super.testInsertBefore(toInsert, target); - fail("Inserting node created from a different impl"); - } catch (DOMException de) { - assertEquals(de.code, DOMException.WRONG_DOCUMENT_ERR); - } + DOMException de = assertThrows(DOMException.class, () -> super.testInsertBefore(toInsert, target)); + assertEquals(de.code, DOMException.WRONG_DOCUMENT_ERR); } @Test - public void testInsertBeforeNullChild() { + void testInsertBeforeNullChild() { Node target = m_doc.createElement("foo"); super.testInsertBefore(null, target); } @@ -290,18 +242,17 @@ public abstract class NodeWithChildrenTe /** * pre: child cannot be an ancestor of m_node - * @param child */ public void testInsertExistingNode(Node child) { Node target = m_node.getFirstChild(); - if (target.getParentNode()==child.getParentNode()) + if (target != null && child != null && target.getParentNode()==child.getParentNode()) child=child.getParentNode(); assertFalse(target == null || child == null); super.testInsertBefore(child, target); } @Test - public void testInsertBeforeDocFrag() { + protected void testInsertBeforeDocFrag() { DocumentFragment child = m_doc.createDocumentFragment(); child.appendChild(m_doc.createElement("foo1")); Node target = m_node.getFirstChild(); @@ -309,39 +260,31 @@ public abstract class NodeWithChildrenTe } @Test - public void testAppendChild() { + protected void testAppendChild() { Node newNode = m_doc.createElement("foo"); super.testAppendChild(newNode); } //try to append the parent @Test - public void testAppendChildIllegal0() { + void testAppendChildIllegal0() { Node parent = m_node.getFirstChild(); m_node = m_node.getFirstChild(); - try { - super.testAppendChild(parent); - fail("Appending parent "); - } catch (DOMException de) { - assertEquals(DOMException.HIERARCHY_REQUEST_ERR, de.code); - } + DOMException de = assertThrows(DOMException.class, () -> super.testAppendChild(parent), "Appending parent"); + assertEquals(DOMException.HIERARCHY_REQUEST_ERR, de.code); } //try to insert diff doc @Test - public void testAppendChildIllegal1() { + void testAppendChildIllegal1() { Node newNode = m_docNS.createElement("newNode"); - try { - super.testAppendChild(newNode); - fail("Appending wrong doc"); - } catch (DOMException de) { - assertEquals(DOMException.WRONG_DOCUMENT_ERR, de.code); - } + DOMException de = assertThrows(DOMException.class, () -> super.testAppendChild(newNode), "Appending wrong doc"); + assertEquals(DOMException.WRONG_DOCUMENT_ERR, de.code); } //append doc frag @Test - public void testAppendChildDocFrag() { + protected void testAppendChildDocFrag() { DocumentFragment child = m_doc.createDocumentFragment(); child.appendChild(m_doc.createElement("foo")); super.testAppendChild(child); @@ -349,11 +292,11 @@ public abstract class NodeWithChildrenTe //TODO : not implemented @Test - public void testNormalize() { + void testNormalize() { int nCount=m_node.getChildNodes().getLength(); String value=""; if (m_node.getLastChild() instanceof Text) - value=((Text)m_node.getLastChild()).getNodeValue(); + value= m_node.getLastChild().getNodeValue(); int nExistingText=0; for (int i=nCount-1; i > -1; i--) @@ -367,52 +310,43 @@ public abstract class NodeWithChildrenTe txt=m_doc.createTextNode(" bar"); m_node.appendChild(txt); - assertEquals(nCount+3,m_node.getChildNodes().getLength()); + assertEquals(nCount + 3, m_node.getChildNodes().getLength()); m_node.normalize(); - assertEquals(true,(m_node.getLastChild() instanceof Text)); + assertTrue((m_node.getLastChild() instanceof Text)); // if (value.length()==0)nCount++;//if last node was a text nCount stays the same - assertEquals(nCount-nExistingText+1,m_node.getChildNodes().getLength()); + assertEquals(nCount - nExistingText + 1, m_node.getChildNodes().getLength()); value+="foo bar"; - assertEquals(value,m_node.getLastChild().getNodeValue()); + assertEquals(value, m_node.getLastChild().getNodeValue()); } @Test - public void testSetPrefixInvalid() { + void testSetPrefixInvalid() { //test only applies to Attrs and Elems if (!(m_node.getNodeType() == Node.ATTRIBUTE_NODE || m_node.getNodeType() == Node.ELEMENT_NODE)) return; //qualifiedName is malformed - try { - m_node.setPrefix("invalid<"); - fail("Invalid prefix name--see http://www.w3.org/TR/REC-xml#NT-BaseChar"); - } catch (DOMException de) { - assertEquals(DOMException.INVALID_CHARACTER_ERR, de.code); - } + DOMException de1 = assertThrows(DOMException.class, () -> m_node.setPrefix("invalid<"), "Invalid prefix name--see http://www.w3.org/TR/REC-xml#NT-BaseChar"); + assertEquals(DOMException.INVALID_CHARACTER_ERR, de1.code); //the qualifiedName has a prefix and the namespaceURI is null - try { - if (m_node.getNamespaceURI() == null) { - m_node.setPrefix("foo"); - fail("Can not set prefix here"); - } else { - m_node.setPrefix("xml"); - fail("Xml is not a valid prefix here"); - } - } catch (DOMException de) { - assertEquals(DOMException.NAMESPACE_ERR, de.code); + DOMException de2; + if (m_node.getNamespaceURI() == null) { + de2 = assertThrows(DOMException.class, () -> m_node.setPrefix("foo"), "Can not set prefix here"); + } else { + de2 = assertThrows(DOMException.class, () -> m_node.setPrefix("xml"), "Xml is not a valid prefix here"); } - + assertEquals(DOMException.NAMESPACE_ERR, de2.code); } @Test - public void testSetNodeValue() { + void testSetNodeValue() { int nCount = m_node.getChildNodes().getLength(); m_node.setNodeValue("blah"); assertEquals(nCount, m_node.getChildNodes().getLength()); Modified: xmlbeans/trunk/src/test/java/dom/detailed/AttrNamespaceTest.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/dom/detailed/AttrNamespaceTest.java?rev=1897795&r1=1897794&r2=1897795&view=diff ============================================================================== --- xmlbeans/trunk/src/test/java/dom/detailed/AttrNamespaceTest.java (original) +++ xmlbeans/trunk/src/test/java/dom/detailed/AttrNamespaceTest.java Sun Feb 6 01:51:55 2022 @@ -17,9 +17,9 @@ package dom.detailed; import dom.common.Loader; import org.apache.xmlbeans.XmlObject; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.w3c.dom.Attr; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -28,7 +28,7 @@ import org.xml.sax.InputSource; import java.io.StringReader; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; /** @@ -44,13 +44,13 @@ public class AttrNamespaceTest { @Test - @Ignore + @Disabled public void testDefaultNamespace() { assertTrue(((Element) m_node).hasAttribute("xmlns")); } @Test - public void testAttr2Namespace() { + void testAttr2Namespace() { Attr at = (Attr) ((Element) m_node).getAttributeNode("at0"); String namespaceURI = "http://foo.org"; String qualifiedName = "xmlns:bar"; @@ -69,7 +69,7 @@ public class AttrNamespaceTest { } @Test - public void testNamespace2Attr() { + void testNamespace2Attr() { m_node = m_docNS.getFirstChild(); int nAttrCount = ((Element) m_node).getAttributes().getLength(); @@ -100,7 +100,7 @@ public class AttrNamespaceTest { * with NULL URI? */ @Test - public void testInsertBadAttribute() throws Exception{ + void testInsertBadAttribute() throws Exception{ String sER="<foo/>"; org.apache.xerces.parsers.DOMParser parser = new org.apache.xerces.parsers.DOMParser(); parser.parse(new InputSource(new StringReader(sER))); @@ -118,7 +118,7 @@ public class AttrNamespaceTest { at_xerces.setValue(""); } - @Before + @BeforeEach public void setUp() throws Exception { if (sXml == null && sXmlNS == null) throw new IllegalArgumentException("Test bug : Initialize xml strings"); Loader loader = Loader.getLoader(); Modified: xmlbeans/trunk/src/test/java/dom/detailed/IDTest.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/dom/detailed/IDTest.java?rev=1897795&r1=1897794&r2=1897795&view=diff ============================================================================== --- xmlbeans/trunk/src/test/java/dom/detailed/IDTest.java (original) +++ xmlbeans/trunk/src/test/java/dom/detailed/IDTest.java Sun Feb 6 01:51:55 2022 @@ -20,8 +20,8 @@ import org.apache.xmlbeans.XmlError; import org.apache.xmlbeans.XmlException; import org.apache.xmlbeans.XmlObject; import org.apache.xmlbeans.XmlOptions; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.w3c.dom.Document; import org.w3c.dom.Element; import xbean.dom.id.FooDocument; @@ -29,17 +29,16 @@ import xbean.dom.id.FooDocument; import java.io.File; import java.util.ArrayList; import java.util.Collection; -import java.util.Iterator; import java.util.List; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; public class IDTest { private String P = File.separator; - // Test the getElementById() DOM API with DTDs , run with jvm arg -Dcases.location + // Test the getElementById() DOM API with DTDs , run with jvm arg -Dcases.location @Test - public void testGetElemById() throws Exception { + void testGetElemById() throws Exception { Document doc; Element element; String tagname; @@ -51,13 +50,13 @@ public class IDTest { assertNotNull(element); tagname = element.getTagName(); - assertEquals("throw_Equals", "emp:address", tagname); + assertEquals("emp:address", tagname, "throw_Equals"); assertNull(doc.getDoctype()); } // test getElementById() with schema containing DTD with ID definition for untyped XmlObject @Test - public void testIDSchema() throws Exception { + void testIDSchema() throws Exception { String dtdAndData = "<!DOCTYPE xs:schema PUBLIC \"-//W3C//DTD XMLSCHEMA 200102//EN\" \"XMLSchema.dtd\" [\n" + "<!ELEMENT first_name (#PCDATA)>\n" + @@ -89,7 +88,7 @@ public class IDTest { // typed XmlObject @Test - @Ignore("doesn't work anymore - xerces 2.11 is not calling the DeclHandler and so no ID attribute is added") + @Disabled("doesn't work anymore - xerces 2.11 is not calling the DeclHandler and so no ID attribute is added") public void testSchemaWithDTD() throws Exception { XmlOptions opt = new XmlOptions(); List err = new ArrayList(); Modified: xmlbeans/trunk/src/test/java/dom/detailed/ImportUnsupportedNodesTest.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/dom/detailed/ImportUnsupportedNodesTest.java?rev=1897795&r1=1897794&r2=1897795&view=diff ============================================================================== --- xmlbeans/trunk/src/test/java/dom/detailed/ImportUnsupportedNodesTest.java (original) +++ xmlbeans/trunk/src/test/java/dom/detailed/ImportUnsupportedNodesTest.java Sun Feb 6 01:51:55 2022 @@ -16,9 +16,9 @@ package dom.detailed; import dom.common.Loader; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.w3c.dom.DOMException; import org.w3c.dom.Document; import org.w3c.dom.Node; @@ -26,7 +26,7 @@ import org.xml.sax.InputSource; import java.io.StringReader; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; public class ImportUnsupportedNodesTest { @@ -37,8 +37,20 @@ public class ImportUnsupportedNodesTest String sER="<!DOCTYPE note [<!ENTITY ORG \"IICD\">] >" +"<foo>&ORG;</foo>"; + + //TODO: see if code coverage can help id gaps here... + @BeforeEach + public void setUp() throws Exception{ + Loader _loader = Loader.getLoader(); + if (sXml == null) throw new IllegalArgumentException("Test bug : Initialize xml strings"); + m_doc = (org.w3c.dom.Document) _loader.load(sXml); + + m_node = m_doc.getFirstChild(); + } + + @Test - @Ignore("not implemented") + @Disabled("not implemented") public void testImportEnitityNode()throws Exception{ org.apache.xerces.parsers.DOMParser parser = new org.apache.xerces.parsers.DOMParser(); parser.parse(new InputSource(new StringReader(sER))); @@ -54,7 +66,7 @@ public class ImportUnsupportedNodesTest } @Test - @Ignore("not implemented") + @Disabled("not implemented") public void testImportERNode()throws Exception{ org.apache.xerces.parsers.DOMParser parser = new org.apache.xerces.parsers.DOMParser(); parser.parse(new InputSource(new StringReader(sER))); @@ -74,26 +86,21 @@ public class ImportUnsupportedNodesTest * DOCUMENT_TYPE_NODE * cannot be imported. */ - @Test(expected = DOMException.class) - public void testImportDocType() throws Exception{ + @Test + void testImportDocType() throws Exception{ org.apache.xerces.parsers.DOMParser parser = new org.apache.xerces.parsers.DOMParser(); parser.parse(new InputSource(new StringReader(sER))); Document xercesDocument = parser.getDocument(); assertNotNull(xercesDocument); Node toImport = xercesDocument.getDoctype(); - try { - Node importedNode = m_doc.importNode(toImport, true); - fail("can't import DocType Node"); - } catch (DOMException e) { + assertThrows(DOMException.class, () -> m_doc.importNode(toImport, true), "can't import DocType Node"); - } - - m_doc.importNode(toImport, false); + assertThrows(DOMException.class, () -> m_doc.importNode(toImport, false)); } @Test - public void testImportCDATAType() throws Exception{ + void testImportCDATAType() throws Exception{ org.apache.xerces.parsers.DOMParser parser = new org.apache.xerces.parsers.DOMParser(); parser.parse(new InputSource(new StringReader(sER))); Document xercesDocument = parser.getDocument(); @@ -116,16 +123,5 @@ public class ImportUnsupportedNodesTest assertEquals(importedNode, m_node.getFirstChild()); assertEquals(Node.CDATA_SECTION_NODE, m_node.getFirstChild().getNodeType()); } - - - //TODO: see if code coverage can help id gaps here... - @Before - public void setUp() throws Exception{ - Loader _loader = Loader.getLoader(); - if (sXml == null) throw new IllegalArgumentException("Test bug : Initialize xml strings"); - m_doc = (org.w3c.dom.Document) _loader.load(sXml); - - m_node = m_doc.getFirstChild(); - } } Modified: xmlbeans/trunk/src/test/java/dom/detailed/InsertDeleteNodesTest.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/dom/detailed/InsertDeleteNodesTest.java?rev=1897795&r1=1897794&r2=1897795&view=diff ============================================================================== --- xmlbeans/trunk/src/test/java/dom/detailed/InsertDeleteNodesTest.java (original) +++ xmlbeans/trunk/src/test/java/dom/detailed/InsertDeleteNodesTest.java Sun Feb 6 01:51:55 2022 @@ -16,12 +16,12 @@ package dom.detailed; import dom.common.Loader; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.w3c.dom.*; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; /** @@ -35,7 +35,7 @@ public class InsertDeleteNodesTest { Node m_node; @Test - public void testInsertNodes(){ + void testInsertNodes(){ //insert one of each type of node: Text txt0 = m_doc.createTextNode("foo"); Text txt1 = m_doc.createTextNode(" "); @@ -144,14 +144,14 @@ public class InsertDeleteNodesTest { try { m_doc.insertBefore(root, doc_frag.getLastChild()); - fail("Should except here"); + Assertions.fail("Should except here"); } catch (DOMException de) { assertEquals(de.code, DOMException.HIERARCHY_REQUEST_ERR); } } //TODO: insert nodes at all illegal places: - @Before + @BeforeEach public void setUp() throws Exception{ Loader loader = Loader.getLoader(); if (sXml == null && sXmlNS == null) throw new IllegalArgumentException("Test bug : Initialize xml strings"); Modified: xmlbeans/trunk/src/test/java/dom/detailed/MoveImportNodeTest.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/dom/detailed/MoveImportNodeTest.java?rev=1897795&r1=1897794&r2=1897795&view=diff ============================================================================== --- xmlbeans/trunk/src/test/java/dom/detailed/MoveImportNodeTest.java (original) +++ xmlbeans/trunk/src/test/java/dom/detailed/MoveImportNodeTest.java Sun Feb 6 01:51:55 2022 @@ -17,8 +17,9 @@ package dom.detailed; import dom.common.Loader; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.w3c.dom.DOMException; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -27,7 +28,7 @@ import org.xml.sax.InputSource; import java.io.StringReader; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; public class MoveImportNodeTest { @@ -43,7 +44,7 @@ public class MoveImportNodeTest { //insert a node from a ns into a non-ns: node will move "as is" //even though ns is not in scope as DOM does no prefix resolution @Test - public void testMoveNodeNStoNoNS(){ + void testMoveNodeNStoNoNS(){ Node toMove = m_docNS.getFirstChild().getFirstChild().getFirstChild(); //bar assertEquals("myns:bar", toMove.getNodeName()); Element newParent = (Element) m_docNS.getFirstChild(); @@ -52,15 +53,14 @@ public class MoveImportNodeTest { assertEquals(2, newParent.getChildNodes().getLength()); assertEquals(toMove, newParent.getElementsByTagNameNS("http://foo.org", "bar").item(0)); - assertEquals(newParent.getElementsByTagName("bar").item(0), - newParent.getElementsByTagNameNS(null, "bar").item(0)); + assertEquals(newParent.getElementsByTagName("bar").item(0), newParent.getElementsByTagNameNS(null, "bar").item(0)); } //move node to a different namespace //namespace of node should be unchanged -- DOM does not care @Test - public void testMoveDiffNS(){ + void testMoveDiffNS(){ Node toMove = m_docNS.getFirstChild().getFirstChild().getFirstChild(); //bar Element newParent = (Element) m_docNS.getFirstChild(); newParent.insertBefore(toMove, newParent.getFirstChild()); @@ -73,18 +73,18 @@ public class MoveImportNodeTest { //import to a doc where the given ns DNE @Test - public void testMoveDiffDoc(){ + void testMoveDiffDoc(){ Node toMove=m_docNS.getFirstChild().getFirstChild().getFirstChild(); //bar try{ m_node.insertBefore(toMove,m_node.getFirstChild()); - fail(" Cannot move nodes across docs"); + Assertions.fail(" Cannot move nodes across docs"); }catch(DOMException de){ - assertEquals(DOMException.WRONG_DOCUMENT_ERR,de.code); + assertEquals(DOMException.WRONG_DOCUMENT_ERR, de.code); } } @Test - public void testMoveDiffImplementations() throws Exception{ + void testMoveDiffImplementations() throws Exception{ org.apache.xerces.parsers.DOMParser parser = new org.apache.xerces.parsers.DOMParser(); @@ -99,7 +99,7 @@ public class MoveImportNodeTest { try { m_node.insertBefore(toMove, m_node.getFirstChild()); - fail(" Cannot move nodes across implementations"); + Assertions.fail(" Cannot move nodes across implementations"); } catch (DOMException de) { assertEquals(DOMException.WRONG_DOCUMENT_ERR, de.code); } @@ -117,7 +117,7 @@ public class MoveImportNodeTest { // public void @Test - public void testImportSameDoc(){ + void testImportSameDoc(){ //inspired by nist documentimportnode10? Node toImport = m_doc.createElement("foobar"); @@ -129,7 +129,7 @@ public class MoveImportNodeTest { m_doc.importNode(toImport, true); } - @Before + @BeforeEach public void setUp() throws Exception{ Loader loader = Loader.getLoader(); if (sXml == null && sXmlNS == null) throw new IllegalArgumentException("Test bug : Initialize xml strings"); Modified: xmlbeans/trunk/src/test/java/dom/detailed/MultipleDocsTest.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/dom/detailed/MultipleDocsTest.java?rev=1897795&r1=1897794&r2=1897795&view=diff ============================================================================== --- xmlbeans/trunk/src/test/java/dom/detailed/MultipleDocsTest.java (original) +++ xmlbeans/trunk/src/test/java/dom/detailed/MultipleDocsTest.java Sun Feb 6 01:51:55 2022 @@ -16,8 +16,8 @@ package dom.detailed; import dom.common.Loader; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.w3c.dom.*; @@ -41,7 +41,7 @@ public class MultipleDocsTest { Document[] m_doc; @Test - public void testRunThreads() { + void testRunThreads() { for (int j = 0; j < nThreadCount; j++) threads[j].start(); @@ -57,7 +57,7 @@ public class MultipleDocsTest { } } - @Before + @BeforeEach public void setUp() throws Exception { threads = new Thread[nThreadCount]; for (int i = 0; i < nThreadCount; i++) { Modified: xmlbeans/trunk/src/test/java/dom/detailed/TextInsertDeleteTest.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/dom/detailed/TextInsertDeleteTest.java?rev=1897795&r1=1897794&r2=1897795&view=diff ============================================================================== --- xmlbeans/trunk/src/test/java/dom/detailed/TextInsertDeleteTest.java (original) +++ xmlbeans/trunk/src/test/java/dom/detailed/TextInsertDeleteTest.java Sun Feb 6 01:51:55 2022 @@ -18,11 +18,11 @@ package dom.detailed; import dom.common.Loader; import org.apache.xmlbeans.XmlObject; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.w3c.dom.*; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class TextInsertDeleteTest { String sXml = "<foo>txt0<bar/>txt1<baz/>txt2</foo>"; @@ -32,7 +32,7 @@ public class TextInsertDeleteTest { Node m_node; @Test - public void testBuildMixedContent(){ + void testBuildMixedContent(){ DOMImplementation domImpl = XmlObject.Factory.newDomImplementation(null); m_doc = domImpl.createDocument("foobar", "val", null); Element root = m_doc.getDocumentElement(); @@ -47,7 +47,7 @@ public class TextInsertDeleteTest { } @Test - public void testAdjacent() { + void testAdjacent() { NodeList ch = m_node.getChildNodes(); m_node.removeChild(ch.item(1)); assertEquals(ch.getLength(), 4); @@ -60,7 +60,7 @@ public class TextInsertDeleteTest { } @Test - public void testInsertDelete() { + void testInsertDelete() { //eric test // TODO: three children delete middle--verify length m_node = m_docNS.getFirstChild(); @@ -93,7 +93,7 @@ public class TextInsertDeleteTest { } @Test - public void testInsertDeleteBulk() { + void testInsertDeleteBulk() { int nNodeCnt = 16; m_node = m_docNS.getDocumentElement(); @@ -113,7 +113,7 @@ public class TextInsertDeleteTest { m_node.removeChild(nodes[i]); } - assertEquals(nNodeCnt/2 , ch.getLength()); + assertEquals(nNodeCnt / 2, ch.getLength()); //split all remaining nodes @@ -134,7 +134,7 @@ public class TextInsertDeleteTest { } - @Before + @BeforeEach public void setUp() throws Exception { Loader loader = Loader.getLoader(); if (sXml == null && sXmlNS == null) throw new IllegalArgumentException("Test bug : Initialize xml strings"); Modified: xmlbeans/trunk/src/test/java/dom/detailed/TextTest.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/dom/detailed/TextTest.java?rev=1897795&r1=1897794&r2=1897795&view=diff ============================================================================== --- xmlbeans/trunk/src/test/java/dom/detailed/TextTest.java (original) +++ xmlbeans/trunk/src/test/java/dom/detailed/TextTest.java Sun Feb 6 01:51:55 2022 @@ -17,13 +17,13 @@ package dom.detailed; import dom.common.Loader; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.w3c.dom.Attr; import org.w3c.dom.Document; import org.w3c.dom.Node; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class TextTest { String sXml="<foo at0=\"no_ns_attr\"></foo>"; @@ -33,7 +33,7 @@ public class TextTest { Node m_node; @Test - public void testTextToAttrValue(){ + void testTextToAttrValue(){ m_node = m_docNS.getFirstChild().getFirstChild().getFirstChild();//footext Attr attrib = (Attr) m_docNS.getFirstChild().getFirstChild().getAttributes().getNamedItem("xmlns:myns"); assertEquals("http://foo.org", attrib.getNodeValue()); @@ -43,7 +43,7 @@ public class TextTest { //assertFalse(m_docNS.getFirstChild().getFirstChild().hasChildNodes()); } - @Before + @BeforeEach public void setUp() throws Exception { Loader loader = Loader.getLoader(); Modified: xmlbeans/trunk/src/test/java/misc/checkin/CharUtilTests.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/misc/checkin/CharUtilTests.java?rev=1897795&r1=1897794&r2=1897795&view=diff ============================================================================== --- xmlbeans/trunk/src/test/java/misc/checkin/CharUtilTests.java (original) +++ xmlbeans/trunk/src/test/java/misc/checkin/CharUtilTests.java Sun Feb 6 01:51:55 2022 @@ -16,228 +16,196 @@ package misc.checkin; import org.apache.xmlbeans.impl.store.CharUtil; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.ArrayList; +import java.util.List; import java.util.Random; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; -public class CharUtilTests -{ +public class CharUtilTests { private static class Triple { - Triple ( Object src, int off, int cch ) - { + Triple(Object src, int off, int cch) { _src = src; _off = off; _cch = cch; } - + final Object _src; - final int _off; - final int _cch; + final int _off; + final int _cch; + } + + private char randomChar() { + int n = rnd(27); + return n == 0 ? ' ' : (char) ('a' + n - 1); } - private char randomChar ( ) - { - int n = rnd( 27 ); - - switch ( n ) - { - case 0 : return ' '; - default : return (char)( 'a' + n - 1 ); - } - } - - private String randomString ( ) - { + private String randomString() { StringBuilder sb = new StringBuilder(); - for ( int i = rnd( 128 ) ; i >= 0 ; i-- ) - sb.append( randomChar() ); + for (int i = rnd(128); i >= 0; i--) { + sb.append(randomChar()); + } return sb.toString(); } - - private interface CharUtilTest - { - void newText ( String s ); - int numTexts ( ); + private interface CharUtilTest { + void newText(String s); + + int numTexts(); - String getText ( int i ); - - int length ( int i ); + String getText(int i); - void insert ( int i, int j, int off ); - - void remove ( int i, int off, int cch ); + int length(int i); + + void insert(int i, int j, int off); + + void remove(int i, int off, int cch); } - private static class RealCharUtil implements CharUtilTest - { - public void newText ( String s ) - { - _triples.add( new Triple( s, 0, s.length() ) ); + private static class RealCharUtil implements CharUtilTest { + final List<Triple> _triples = new ArrayList<>(); + final CharUtil _cu = new CharUtil(1024); + + public void newText(String s) { + _triples.add(new Triple(s, 0, s.length())); } - public int numTexts ( ) - { + public int numTexts() { return _triples.size(); } - public String getText ( int i ) - { - Triple t = (Triple) _triples.get( i ); - - return CharUtil.getString( t._src, t._off, t._cch ); - } - - public int length ( int i ) - { - return ((Triple) _triples.get( i ))._cch; - } - - public void insert ( int i, int j, int off ) - { - Triple ti = (Triple) _triples.get( i ); - Triple tj = (Triple) _triples.get( j ); - + public String getText(int i) { + Triple t = _triples.get(i); + + return CharUtil.getString(t._src, t._off, t._cch); + } + + public int length(int i) { + return _triples.get(i)._cch; + } + + public void insert(int i, int j, int off) { + Triple ti = _triples.get(i); + Triple tj = _triples.get(j); + Object src = - _cu.insertChars( off, ti._src, ti._off, ti._cch, tj._src, tj._off, tj._cch ); + _cu.insertChars(off, ti._src, ti._off, ti._cch, tj._src, tj._off, tj._cch); - _triples.set( i, new Triple( src, _cu._offSrc, _cu._cchSrc ) ); + _triples.set(i, new Triple(src, _cu._offSrc, _cu._cchSrc)); } - - public void remove ( int i, int off, int cch ) - { - Triple ti = (Triple) _triples.get( i ); - - Object src = _cu.removeChars( off, cch, ti._src, ti._off, ti._cch ); - - _triples.set( i, new Triple( src, _cu._offSrc, _cu._cchSrc ) ); - } - - ArrayList _triples = new ArrayList(); - CharUtil _cu = new CharUtil( 1024 ); - } - - private static class FakeCharUtil implements CharUtilTest - { - public void newText ( String s ) - { - _strings.add( s ); + + public void remove(int i, int off, int cch) { + Triple ti = _triples.get(i); + + Object src = _cu.removeChars(off, cch, ti._src, ti._off, ti._cch); + + _triples.set(i, new Triple(src, _cu._offSrc, _cu._cchSrc)); + } + } + + private static class FakeCharUtil implements CharUtilTest { + final List<String> _strings = new ArrayList<>(); + + public void newText(String s) { + _strings.add(s); } - public int numTexts ( ) - { + public int numTexts() { return _strings.size(); } - public String getText ( int i ) - { - return (String) _strings.get( i ); + public String getText(int i) { + return _strings.get(i); } - public int length ( int i ) - { - return ((String) _strings.get( i )).length(); + public int length(int i) { + return _strings.get(i).length(); } - - public void insert ( int i, int j, int off ) - { - String si = (String) _strings.get( i ); - String sj = (String) _strings.get( j ); - _strings.set( i, si.substring( 0, off ) + sj + si.substring( off ) ); + public void insert(int i, int j, int off) { + String si = _strings.get(i); + String sj = _strings.get(j); + + _strings.set(i, si.substring(0, off) + sj + si.substring(off)); } - public void remove ( int i, int off, int cch ) - { - String si = (String) _strings.get( i ); - - _strings.set( i, si.substring( 0, off ) + si.substring( off + cch ) ); + public void remove(int i, int off, int cch) { + String si = _strings.get(i); + + _strings.set(i, si.substring(0, off) + si.substring(off + cch)); } - - ArrayList _strings = new ArrayList(); } @Test - public void testCharUtil ( ) throws Exception - { + void testCharUtil() throws Exception { RealCharUtil real = new RealCharUtil(); FakeCharUtil fake = new FakeCharUtil(); - for ( int iter = 0 ; iter < 5000 ; iter++ ) - { - switch( rnd( 4 ) ) - { - case 0 : - { - String s = randomString(); + for (int iter = 0; iter < 5000; iter++) { + switch (rnd(4)) { + case 0: { + String s = randomString(); - real.newText( s ); - fake.newText( s ); + real.newText(s); + fake.newText(s); - break; - } + break; + } - case 1 : - { - assertEquals(real.numTexts(), fake.numTexts()); - - if (real.numTexts() > 0) - { - int j = rnd( real.numTexts() ); + case 1: { + assertEquals(real.numTexts(), fake.numTexts()); - assertEquals(real.getText(j), fake.getText(j)); - } - } - - case 2 : - { - if (real.numTexts() > 1) - { - int i = rnd( real.numTexts() ); - int j = rnd( real.numTexts() ); - int off = rnd( real.length( i ) + 1 ); + if (real.numTexts() > 0) { + int j = rnd(real.numTexts()); - real.insert( i, j, off ); - fake.insert( i, j, off ); + assertEquals(real.getText(j), fake.getText(j)); + } + } - assertEquals(real.getText(i), fake.getText(i)); - assertEquals(real.getText(j), fake.getText(j)); + case 2: { + if (real.numTexts() > 1) { + int i = rnd(real.numTexts()); + int j = rnd(real.numTexts()); + int off = rnd(real.length(i) + 1); + + real.insert(i, j, off); + fake.insert(i, j, off); + + assertEquals(real.getText(i), fake.getText(i)); + assertEquals(real.getText(j), fake.getText(j)); + } } - } - case 3 : - { - int i = rnd( real.numTexts() ); - int l = real.length( i ); - int off = rnd( l + 1 ); - int cch = rnd( l - off + 1 ); + case 3: { + int i = rnd(real.numTexts()); + int l = real.length(i); + int off = rnd(l + 1); + int cch = rnd(l - off + 1); - real.remove( i, off, cch ); - fake.remove( i, off, cch ); + real.remove(i, off, cch); + fake.remove(i, off, cch); - assertEquals(real.getText(i), fake.getText(i)); - } + assertEquals(real.getText(i), fake.getText(i)); + } } } } - private int rnd ( int n ) - { - return n == 1 ? 0 : _rnd.nextInt( n - 1 ); + private int rnd(int n) { + return n == 1 ? 0 : _rnd.nextInt(n - 1); } - private Random _rnd = new Random( 0 ); + private final Random _rnd = new Random(0); @Test - public void testThreadLocal() { - assertNotNull("Should always get a CharUtil from ThreadLocals", CharUtil.getThreadLocalCharUtil()); + void testThreadLocal() { + assertNotNull(CharUtil.getThreadLocalCharUtil(), "Should always get a CharUtil from ThreadLocals"); CharUtil.clearThreadLocals(); - assertNotNull("Should always get a CharUtil from ThreadLocals", CharUtil.getThreadLocalCharUtil()); + assertNotNull(CharUtil.getThreadLocalCharUtil(), "Should always get a CharUtil from ThreadLocals"); } } \ No newline at end of file Modified: xmlbeans/trunk/src/test/java/misc/checkin/ErrorCodeTest.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/misc/checkin/ErrorCodeTest.java?rev=1897795&r1=1897794&r2=1897795&view=diff ============================================================================== --- xmlbeans/trunk/src/test/java/misc/checkin/ErrorCodeTest.java (original) +++ xmlbeans/trunk/src/test/java/misc/checkin/ErrorCodeTest.java Sun Feb 6 01:51:55 2022 @@ -16,7 +16,7 @@ package misc.checkin; import org.apache.xmlbeans.XmlErrorCodes; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.lang.reflect.Field; import java.lang.reflect.Modifier; @@ -27,32 +27,33 @@ import java.util.Set; public class ErrorCodeTest { @Test - public void testCodes() throws Exception - { + void testCodes() throws Exception { // throws Exception if a duplicate error code value is found. - Set codes = readCodes(); + Set<String> codes = readCodes(); // throws Exception if a duplicate message property key is found. Properties messages = readMessages(); // each message key should have an error code value - Enumeration e = messages.keys(); + Enumeration<Object> e = messages.keys(); while (e.hasMoreElements()) { String key = (String) e.nextElement(); // these properties are known not to have an error code - if (key.equals("message.missing.resource") || key.equals("message.pattern.invalid")) + if (key.equals("message.missing.resource") || key.equals("message.pattern.invalid")) { continue; + } - if (!codes.contains(key)) + if (!codes.contains(key)) { throw new Exception("message.properties key '" + key + "' has no error code."); + } } // each error code value should have a message key - for (Object code1 : codes) { - String code = (String) code1; - if (messages.get(code) == null) + for (Object code : codes) { + if (messages.get(code) == null) { throw new Exception("missing message.properties key for error code: " + code); + } } } @@ -61,27 +62,28 @@ public class ErrorCodeTest { * Reads the field values of the public static final String fields of XmlErrorCodes. * Throws an Exception if a duplicate value is found. */ - private Set readCodes() throws Exception - { - Set result = new LinkedHashSet(); + private Set<String> readCodes() throws Exception { + Set<String> result = new LinkedHashSet<>(); Field[] fields = XmlErrorCodes.class.getDeclaredFields(); - for (int i = 0; i < fields.length; i++) { - Field field = fields[i]; + for (Field field : fields) { int modifiers = field.getModifiers(); // only look at fields that are public static final - if ((modifiers & (Modifier.PUBLIC | Modifier.STATIC | Modifier.FINAL)) == 0) + if ((modifiers & (Modifier.PUBLIC | Modifier.STATIC | Modifier.FINAL)) == 0) { continue; + } // only look at String fields - if (field.getType() != String.class) + if (field.getType() != String.class) { continue; + } - String value = (String)field.get(null); + String value = (String) field.get(null); - if (!result.add(value)) + if (!result.add(value)) { throw new Exception("duplicate error code value in XmlErrorCodes: " + value + " in field " + field.getName()); + } } return result; @@ -90,15 +92,13 @@ public class ErrorCodeTest { /** * Reads the message.properties file and throws an exception if a duplicate property key is found. */ - private Properties readMessages() throws Exception - { - class UniqueProperties extends Properties - { - public Object put(Object key, Object value) - { + private Properties readMessages() throws Exception { + class UniqueProperties extends Properties { + public Object put(Object key, Object value) { Object old = super.put(key, value); - if (old != null) + if (old != null) { throw new RuntimeException("duplicate property key '" + key + "' with value: " + value); + } return null; } } Modified: xmlbeans/trunk/src/test/java/misc/checkin/HexBinTest.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/misc/checkin/HexBinTest.java?rev=1897795&r1=1897794&r2=1897795&view=diff ============================================================================== --- xmlbeans/trunk/src/test/java/misc/checkin/HexBinTest.java (original) +++ xmlbeans/trunk/src/test/java/misc/checkin/HexBinTest.java Sun Feb 6 01:51:55 2022 @@ -19,17 +19,17 @@ import net.sf.saxon.str.StringView; import net.sf.saxon.trans.XPathException; import net.sf.saxon.value.HexBinaryValue; import org.apache.xmlbeans.impl.util.HexBin; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.nio.charset.StandardCharsets; import java.util.Locale; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class HexBinTest { @Test - public void testSurrogate() throws Exception { + void testSurrogate() throws Exception { String exp = "ABC\ud83c\udf09123"; String enc = HexBin.encode(exp); String dec = HexBin.decode(enc); @@ -37,7 +37,7 @@ public class HexBinTest { } @Test - public void knownValue() throws XPathException { + void knownValue() throws XPathException { // I've looked for comparison values but the following definition seems to be wrong, // because Saxon also returns the same encoded value // see http://books.xmlschemata.org/relaxng/ch19-77143.html Modified: xmlbeans/trunk/src/test/java/misc/checkin/RegularExpressionTest.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/misc/checkin/RegularExpressionTest.java?rev=1897795&r1=1897794&r2=1897795&view=diff ============================================================================== --- xmlbeans/trunk/src/test/java/misc/checkin/RegularExpressionTest.java (original) +++ xmlbeans/trunk/src/test/java/misc/checkin/RegularExpressionTest.java Sun Feb 6 01:51:55 2022 @@ -16,17 +16,16 @@ package misc.checkin; import org.apache.xmlbeans.impl.regex.RegularExpression; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Random; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; public class RegularExpressionTest { @Test - public void testLongString() - { + void testLongString() { RegularExpression regex = new RegularExpression("[A-Z0-9]+"); String rnd = randomString(10000); assertTrue(regex.matches(rnd)); @@ -38,8 +37,9 @@ public class RegularExpressionTest { private String randomString(int len) { StringBuilder sb = new StringBuilder(len); - for(int i = 0; i < len; i++) + for (int i = 0; i < len; i++) { sb.append(AB.charAt(rnd.nextInt(AB.length()))); + } return sb.toString(); } } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
