You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ki...@apache.org on 2022/02/06 01:52:00 UTC
svn commit: r1897795 [33/39] - in /xmlbeans: site/src/documentation/content/xdocs/ trunk/ trunk/src/main/java/org/apache/xmlbeans/impl/store/ trunk/src/test/java/ValidatingXSRTests/checkin/ trunk/src/test/java/ValidatingXSRTests/detailed/ trunk/src/tes...
Modified: xmlbeans/trunk/src/test/java/xmlcursor/jsr173/common/AttributeTest.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/xmlcursor/jsr173/common/AttributeTest.java?rev=1897795&r1=1897794&r2=1897795&view=diff
==============================================================================
--- xmlbeans/trunk/src/test/java/xmlcursor/jsr173/common/AttributeTest.java (original)
+++ xmlbeans/trunk/src/test/java/xmlcursor/jsr173/common/AttributeTest.java Sun Feb 6 01:51:55 2022
@@ -18,162 +18,176 @@ package xmlcursor.jsr173.common;
import org.apache.xmlbeans.XmlCursor;
import org.apache.xmlbeans.XmlObject;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
-@Ignore("abstract class")
-public abstract class AttributeTest {
+public class AttributeTest {
- private XMLStreamReader m_stream;
- private XmlCursor cur;
- private int indexMethods = 6;
-
- public abstract XMLStreamReader getStream(XmlCursor c) throws Exception;
-
- @Test
- public void testAttrEvent() throws Exception {
+ private XmlCursor cur() {
+ XmlCursor cur = XmlObject.Factory.newInstance().newCursor();
cur.toNextToken();
- m_stream = getStream(cur);
- assertEquals(XMLStreamConstants.ATTRIBUTE, m_stream.getEventType());
- assertEquals(1, m_stream.getAttributeCount());
- assertEquals(m_stream.getAttributeValue(0),
- m_stream.getAttributeValue("foo.org", "at0"));
- assertFalse(m_stream.hasNext());
+ cur.insertAttributeWithValue(new QName("foo.org", "at0", "pre"),
+ "val0");
+ cur.insertAttributeWithValue(new QName("", "at1", "pre"), "val1");
+ cur.insertNamespace("pre", "foons.bar.org");
+ cur.beginElement(new QName("foo.org", "foo", ""));
+ cur.insertAttribute("localName");
+ cur.insertChars("some text");
+ cur.toNextToken();
+ cur.toNextToken();//end elt
+ cur.insertProcInst("xml-stylesheet", "http://foobar");
+ cur.toStartDoc();
+ return cur;
}
@Test
- public void testAttrMethodsAtAttr() throws Exception {
-
- //2 attrs under the doc
- // assertEquals(2, m_stream.getAttributeCount());
-
- cur.toNextToken();
- m_stream = getStream(cur);
- ;
- //move 2 first attr
- assertEquals(XMLStreamConstants.ATTRIBUTE, m_stream.getEventType());
- assertEquals(1, m_stream.getAttributeCount());
+ void testAttrEvent() throws Exception {
+ try (XmlCursor cur = cur()) {
+ cur.toNextToken();
+ XMLStreamReader m_stream = cur.newXMLStreamReader();
+ assertEquals(XMLStreamConstants.ATTRIBUTE, m_stream.getEventType());
+ assertEquals(1, m_stream.getAttributeCount());
+ assertEquals(m_stream.getAttributeValue(0), m_stream.getAttributeValue("foo.org", "at0"));
- assertEquals(m_stream.getAttributeValue(0),
- m_stream.getAttributeValue("foo.org", "at0"));
+ assertFalse(m_stream.hasNext());
+ m_stream.close();
+ }
+ }
- //Below methods tested at index 0 and last at index tests
- //getAttributeLocalName(int)
- //getAttributeName(int)
- //getAttributeNamespace(int)
- //getAttributePrefix(int)
- //getAttributeType(int)
- //getAttributeValue(int)
+ @Test
+ void testAttrMethodsAtAttr() throws Exception {
+ try (XmlCursor cur = cur()) {
+ cur.toNextToken();
+ XMLStreamReader m_stream = cur.newXMLStreamReader();
+
+ //move 2 first attr
+ assertEquals(XMLStreamConstants.ATTRIBUTE, m_stream.getEventType());
+ assertEquals(1, m_stream.getAttributeCount());
+ assertEquals(m_stream.getAttributeValue(0), m_stream.getAttributeValue("foo.org", "at0"));
+
+ //Below methods tested at index 0 and last at index tests
+ //getAttributeLocalName(int)
+ //getAttributeName(int)
+ //getAttributeNamespace(int)
+ //getAttributePrefix(int)
+ //getAttributeType(int)
+ //getAttributeValue(int)
+ m_stream.close();
+ }
}
@Test
- public void testAttrMethodsAtStartElt() throws Exception {
- cur.toFirstChild();
- cur.toNextSibling();
- m_stream = getStream(cur);
- assertEquals(1, m_stream.getAttributeCount());
- assertTrue(m_stream.isStartElement());
- assertEquals(new QName("foo.org", "foo", ""), m_stream.getName());
- assertEquals(m_stream.getAttributeValue(0), "");
- assertEquals(m_stream.getAttributeValue(0),
- m_stream.getAttributeValue("", "localName"));
- }
+ void testAttrMethodsAtStartElt() throws Exception {
+ try (XmlCursor cur = cur()) {
+ cur.toFirstChild();
+ cur.toNextSibling();
+ XMLStreamReader m_stream = cur.newXMLStreamReader();
+
+ assertEquals(1, m_stream.getAttributeCount());
+ assertTrue(m_stream.isStartElement());
+ assertEquals(new QName("foo.org", "foo", ""), m_stream.getName());
+ assertEquals(m_stream.getAttributeValue(0), "");
+ assertEquals(m_stream.getAttributeValue(0), m_stream.getAttributeValue("", "localName"));
- private void assertIllegalState1() {
- try {
- m_stream.getAttributeCount();
- fail("Illegal State");
- } catch (java.lang.IllegalStateException e) {
+ m_stream.close();
}
}
- private void assertIllegalState2() {
- try {
- m_stream.getAttributeValue(0);
- fail("Illegal State");
- } catch (java.lang.IllegalStateException e) {
- }
+ private static void assertIllegalState1(XMLStreamReader m_stream) {
+ assertThrows(IllegalStateException.class, m_stream::getAttributeCount);
+ }
+
+ private static void assertIllegalState2(XMLStreamReader m_stream) {
+ assertThrows(IllegalStateException.class, () -> m_stream.getAttributeValue(0));
}
@Test
- public void testAttrMethodsAtNamespace() throws Exception {
- cur.toNextToken();
- cur.toNextToken();
- assertEquals(XmlCursor.TokenType.NAMESPACE, cur.toNextToken());
- m_stream = getStream(cur);
+ void testAttrMethodsAtNamespace() throws Exception {
+ try (XmlCursor cur = cur()) {
+ cur.toNextToken();
+ cur.toNextToken();
+ assertEquals(XmlCursor.TokenType.NAMESPACE, cur.toNextToken());
+ XMLStreamReader m_stream = cur.newXMLStreamReader();
- assertIllegalState1();
- assertIllegalState2();
-// assertEquals(1,m_stream.getNamespaceCount());
-// assertEquals("foons.bar.org",m_stream.getNamespaceURI(0));
-// assertEquals(m_stream.getNamespaceURI(0),m_stream.getAttributeValue("","localName"));
-//
+ assertIllegalState1(m_stream);
+ assertIllegalState2(m_stream);
+ m_stream.close();
+ }
}
//
// java.lang.IllegalStateException - if this is not a START_ELEMENT or ATTRIBUTE
//
@Test
- public void testAttrMethodsAtEndElt() throws Exception {
- cur.toFirstChild();
- cur.toNextSibling();
- cur.toNextToken();
- cur.toNextToken();
- assertEquals(XmlCursor.TokenType.END, cur.toNextToken()); //toEnd
- m_stream = getStream(cur);
- assertIllegalState1();
- assertIllegalState2();
+ void testAttrMethodsAtEndElt() throws Exception {
+ try (XmlCursor cur = cur()) {
+ cur.toFirstChild();
+ cur.toNextSibling();
+ cur.toNextToken();
+ cur.toNextToken();
+ assertEquals(XmlCursor.TokenType.END, cur.toNextToken()); //toEnd
+ XMLStreamReader m_stream = cur.newXMLStreamReader();
+ assertIllegalState1(m_stream);
+ assertIllegalState2(m_stream);
+ m_stream.close();
+ }
}
@Test
- public void testAttrMethodsAtEndDoc() throws Exception {
- cur.toFirstChild();
- cur.toNextSibling();
- cur.toNextToken();
- cur.toNextToken();
- cur.toNextToken();
- cur.toNextToken();
- assertEquals(XmlCursor.TokenType.ENDDOC, cur.toNextToken());
- m_stream = getStream(cur);
- assertIllegalState1();
- assertIllegalState2();
+ void testAttrMethodsAtEndDoc() throws Exception {
+ try (XmlCursor cur = cur()) {
+ cur.toFirstChild();
+ cur.toNextSibling();
+ cur.toNextToken();
+ cur.toNextToken();
+ cur.toNextToken();
+ cur.toNextToken();
+ assertEquals(XmlCursor.TokenType.ENDDOC, cur.toNextToken());
+ XMLStreamReader m_stream = cur.newXMLStreamReader();
+ assertIllegalState1(m_stream);
+ assertIllegalState2(m_stream);
+ m_stream.close();
+ }
}
@Test
- public void testAttrMethodstAtText() throws Exception {
- cur.toFirstChild();
- cur.toNextSibling();
- cur.toNextToken();
- assertEquals(XmlCursor.TokenType.TEXT, cur.toNextToken()); //text
- m_stream = getStream(cur);
- assertIllegalState1();
- assertIllegalState2();
+ void testAttrMethodstAtText() throws Exception {
+ try (XmlCursor cur = cur()) {
+ cur.toFirstChild();
+ cur.toNextSibling();
+ cur.toNextToken();
+ assertEquals(XmlCursor.TokenType.TEXT, cur.toNextToken()); //text
+ XMLStreamReader m_stream = cur.newXMLStreamReader();
+ assertIllegalState1(m_stream);
+ assertIllegalState2(m_stream);
+ m_stream.close();
+ }
}
@Test
- public void testAttrMethodstAtPI() throws Exception {
- cur.toFirstChild();
- cur.toNextSibling();
- cur.toNextToken();
- cur.toNextToken();
- cur.toNextToken();
- assertEquals(XmlCursor.TokenType.PROCINST, cur.toNextToken());
- m_stream = getStream(cur);
- assertIllegalState1();
- assertIllegalState2();
+ void testAttrMethodstAtPI() throws Exception {
+ try (XmlCursor cur = cur()) {
+ cur.toFirstChild();
+ cur.toNextSibling();
+ cur.toNextToken();
+ cur.toNextToken();
+ cur.toNextToken();
+ assertEquals(XmlCursor.TokenType.PROCINST, cur.toNextToken());
+ XMLStreamReader m_stream = cur.newXMLStreamReader();
+ assertIllegalState1(m_stream);
+ assertIllegalState2(m_stream);
+ m_stream.close();
+ }
}
/**
@@ -187,160 +201,74 @@ public abstract class AttributeTest {
* //getAttributeValue(int)
*/
@Test
- public void testAttrMethodsNegIndex() throws Exception {
+ void testAttrMethodsNegIndex() throws Exception {
+ try (XmlCursor cur = cur()) {
+ XMLStreamReader m_stream = cur.newXMLStreamReader();
+
+ assertThrows(IndexOutOfBoundsException.class, () -> m_stream.getAttributeLocalName(-1));
+ assertThrows(IndexOutOfBoundsException.class, () -> m_stream.getAttributeName(-1));
+ assertThrows(IndexOutOfBoundsException.class, () -> m_stream.getAttributeNamespace(-1));
+ assertThrows(IndexOutOfBoundsException.class, () -> m_stream.getAttributePrefix(-1));
+ assertThrows(IndexOutOfBoundsException.class, () -> m_stream.getAttributeType(-1));
+ assertThrows(IndexOutOfBoundsException.class, () -> m_stream.getAttributeValue(-1));
- int cnt = 0;
- try {
- m_stream.getAttributeLocalName(-1);
- } catch (java.lang.IndexOutOfBoundsException e) {
- cnt++;
- }
- try {
- m_stream.getAttributeName(-1);
- } catch (java.lang.IndexOutOfBoundsException e) {
- cnt++;
- }
- try {
- m_stream.getAttributeNamespace(-1);
- } catch (java.lang.IndexOutOfBoundsException e) {
- cnt++;
- }
- try {
- m_stream.getAttributePrefix(-1);
- } catch (java.lang.IndexOutOfBoundsException e) {
- cnt++;
- }
- try {
- m_stream.getAttributeType(-1);
- } catch (java.lang.IndexOutOfBoundsException e) {
- cnt++;
- }
- try {
- m_stream.getAttributeValue(-1);
- } catch (java.lang.IndexOutOfBoundsException e) {
- cnt++;
+ m_stream.close();
}
-
- assertEquals("A negative error wasn't thrown", indexMethods, cnt);
}
@Test
- public void testAttrMethodsLargeIndex() throws XMLStreamException {
-
- int cnt = 0;
- int pos = -1;
- try {
+ void testAttrMethodsLargeIndex() throws XMLStreamException {
+ try (XmlCursor cur = cur()) {
+ XMLStreamReader m_stream = cur.newXMLStreamReader();
m_stream.next();
- pos = m_stream.getAttributeCount();
- m_stream.getAttributeLocalName(pos);
- } catch (java.lang.IndexOutOfBoundsException e) {
- cnt++;
- }
- try {
- m_stream.getAttributeName(pos);
- } catch (java.lang.IndexOutOfBoundsException e) {
- cnt++;
- }
- try {
- m_stream.getAttributeNamespace(pos);
- } catch (java.lang.IndexOutOfBoundsException e) {
- cnt++;
- }
- try {
- m_stream.getAttributePrefix(pos);
- } catch (java.lang.IndexOutOfBoundsException e) {
- cnt++;
- }
- try {
- m_stream.getAttributeType(pos);
- } catch (java.lang.IndexOutOfBoundsException e) {
- cnt++;
- }
- try {
- m_stream.getAttributeValue(pos);
- } catch (java.lang.IndexOutOfBoundsException e) {
- cnt++;
- }
-
- assertEquals("A negative error wasn't thrown", indexMethods, cnt);
- }
-
- @Test
- public void testAttrMethods0Index() throws Exception {
- assertEquals(XMLStreamConstants.START_DOCUMENT, m_stream.getEventType());
-
- assertEquals(XMLStreamConstants.ATTRIBUTE, m_stream.next());
- assertEquals(1, m_stream.getAttributeCount());
- assertEquals("val0", m_stream.getAttributeValue(0));
-
- assertEquals(XMLStreamConstants.ATTRIBUTE, m_stream.next());
-
- assertEquals("val1", m_stream.getAttributeValue(0));
- //why does this crash here????
- assertEquals(XMLStreamConstants.NAMESPACE, m_stream.next()); //ns
- m_stream.next(); //elt
- assertEquals("", m_stream.getAttributeValue(0));
-
- }
-
- //NOTHING to do; eric always emits one event per attr=>
- //getAttributeCount is always 1
- @Test
- public void testAttrMethodsLastIndex() {
+ final int pos = m_stream.getAttributeCount();
+ assertThrows(IndexOutOfBoundsException.class, () -> m_stream.getAttributeLocalName(pos));
+ assertThrows(IndexOutOfBoundsException.class, () -> m_stream.getAttributeName(pos));
+ assertThrows(IndexOutOfBoundsException.class, () -> m_stream.getAttributeNamespace(pos));
+ assertThrows(IndexOutOfBoundsException.class, () -> m_stream.getAttributePrefix(pos));
+ assertThrows(IndexOutOfBoundsException.class, () -> m_stream.getAttributeType(pos));
+ assertThrows(IndexOutOfBoundsException.class, () -> m_stream.getAttributeValue(pos));
+ m_stream.close();
+ }
}
@Test
- public void testIsAttributeSpecified() throws Exception {
- assertEquals(XMLStreamConstants.START_DOCUMENT,
- m_stream.getEventType());
- try {
- m_stream.isAttributeSpecified(0);
- fail("Bad state");
- } catch (IllegalStateException e) {
- }
-
- assertEquals(XMLStreamConstants.ATTRIBUTE, m_stream.next());
- assertEquals(false, m_stream.isAttributeSpecified(0));
-
- try {
- m_stream.isAttributeSpecified(-1);
- fail("Bad state");
- } catch (java.lang.IndexOutOfBoundsException e) {
- }
-
- try {
- m_stream.isAttributeSpecified(2);
- fail("Bad state");
- } catch (java.lang.IndexOutOfBoundsException e) {
+ void testAttrMethods0Index() throws Exception {
+ try (XmlCursor cur = cur()) {
+ XMLStreamReader m_stream = cur.newXMLStreamReader();
+ assertEquals(XMLStreamConstants.START_DOCUMENT, m_stream.getEventType());
+
+ assertEquals(XMLStreamConstants.ATTRIBUTE, m_stream.next());
+ assertEquals(1, m_stream.getAttributeCount());
+
+ assertEquals("val0", m_stream.getAttributeValue(0));
+
+ assertEquals(XMLStreamConstants.ATTRIBUTE, m_stream.next());
+
+ assertEquals("val1", m_stream.getAttributeValue(0));
+ //why does this crash here????
+ assertEquals(XMLStreamConstants.NAMESPACE, m_stream.next()); //ns
+ m_stream.next(); //elt
+ assertEquals("", m_stream.getAttributeValue(0));
+ m_stream.close();
}
}
- @Before
- public void setUp() throws Exception {
- cur = XmlObject.Factory.newInstance().newCursor();
- cur.toNextToken();
-
- cur.insertAttributeWithValue(new QName("foo.org", "at0", "pre"),
- "val0");
- cur.insertAttributeWithValue(new QName("", "at1", "pre"), "val1");
- cur.insertNamespace("pre", "foons.bar.org");
- cur.beginElement(new QName("foo.org", "foo", ""));
- cur.insertAttribute("localName");
- cur.insertChars("some text");
- cur.toNextToken();
- cur.toNextToken();//end elt
- cur.insertProcInst("xml-stylesheet", "http://foobar");
-
- cur.toStartDoc();
- m_stream = getStream(cur);
- //cur.newXMLStreamReader();
- }
+ @Test
+ void testIsAttributeSpecified() throws Exception {
+ try (XmlCursor cur = cur()) {
+ XMLStreamReader m_stream = cur.newXMLStreamReader();
+
+ assertEquals(XMLStreamConstants.START_DOCUMENT, m_stream.getEventType());
+ assertThrows(IllegalStateException.class, () -> m_stream.isAttributeSpecified(0));
+ assertEquals(XMLStreamConstants.ATTRIBUTE, m_stream.next());
+ assertFalse(m_stream.isAttributeSpecified(0));
+ assertThrows(IndexOutOfBoundsException.class, () -> m_stream.isAttributeSpecified(-1));
+ assertThrows(IndexOutOfBoundsException.class, () -> m_stream.isAttributeSpecified(2));
- @After
- public void tearDown() throws Exception {
- if (m_stream != null)
m_stream.close();
+ }
}
}
\ No newline at end of file
Modified: xmlbeans/trunk/src/test/java/xmlcursor/jsr173/common/CharactersTest.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/xmlcursor/jsr173/common/CharactersTest.java?rev=1897795&r1=1897794&r2=1897795&view=diff
==============================================================================
--- xmlbeans/trunk/src/test/java/xmlcursor/jsr173/common/CharactersTest.java (original)
+++ xmlbeans/trunk/src/test/java/xmlcursor/jsr173/common/CharactersTest.java Sun Feb 6 01:51:55 2022
@@ -18,16 +18,14 @@ package xmlcursor.jsr173.common;
import org.apache.xmlbeans.XmlCursor;
import org.apache.xmlbeans.XmlObject;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
/**
* Methods tested
@@ -39,186 +37,186 @@ import static org.junit.Assert.*;
* Token Types should be DTD, ER, Chars, Comment, Space
* currently DTD and ER are Not Impl
*/
-@Ignore("abstract class")
-public abstract class CharactersTest {
+public class CharactersTest {
- private XMLStreamReader m_stream;
- public abstract XMLStreamReader getStream(XmlCursor c) throws Exception;
+ private static XmlCursor cur() {
+ XmlCursor cur = XmlObject.Factory.newInstance().newCursor();
+ cur.toNextToken();
+
+ // cur.insertAttributeWithValue(new QName("foo.org", "at0", "pre"), "val0");
+ cur.insertComment(" some comment ");
+ cur.beginElement(new QName("foo.org", "foo", ""));
+ cur.insertAttribute("localName");
+ cur.insertChars("some text");
+ cur.insertElement("foo2");
+ cur.toNextToken(); //close foo elt
+ cur.insertChars("\t");
+ cur.toStartDoc();
+
+ return cur;
+ }
@Test
- public void testHasText() throws Exception {
- assertEquals(XMLStreamConstants.START_DOCUMENT,
- m_stream.getEventType());
+ void testHasText() throws XMLStreamException {
+ try (XmlCursor cur = cur()) {
+ XMLStreamReader m_stream = cur.newXMLStreamReader();
- // assertEquals( XMLStreamConstants.ATTRIBUTE, m_stream.next() );
- // assertFalse( m_stream.hasText() );
+ assertEquals(XMLStreamConstants.START_DOCUMENT, m_stream.getEventType());
- assertEquals(XMLStreamConstants.COMMENT, m_stream.next());
- assertTrue(m_stream.hasText());
+ // assertEquals( XMLStreamConstants.ATTRIBUTE, m_stream.next() );
+ // assertFalse( m_stream.hasText() );
- assertEquals(XMLStreamConstants.START_ELEMENT, m_stream.next());
- assertFalse(m_stream.hasText());
+ assertEquals(XMLStreamConstants.COMMENT, m_stream.next());
+ assertTrue(m_stream.hasText());
- assertEquals(XMLStreamConstants.CHARACTERS, m_stream.next());
- assertTrue(m_stream.hasText());
+ assertEquals(XMLStreamConstants.START_ELEMENT, m_stream.next());
+ assertFalse(m_stream.hasText());
- assertEquals(XMLStreamConstants.START_ELEMENT, m_stream.next());
- assertFalse(m_stream.hasText());
- assertEquals(XMLStreamConstants.END_ELEMENT, m_stream.next());
- assertFalse(m_stream.hasText());
- assertEquals(XMLStreamConstants.END_ELEMENT, m_stream.next());
- assertFalse(m_stream.hasText());
+ assertEquals(XMLStreamConstants.CHARACTERS, m_stream.next());
+ assertTrue(m_stream.hasText());
- assertEquals(XMLStreamConstants.CHARACTERS, m_stream.next());
+ assertEquals(XMLStreamConstants.START_ELEMENT, m_stream.next());
+ assertFalse(m_stream.hasText());
+ assertEquals(XMLStreamConstants.END_ELEMENT, m_stream.next());
+ assertFalse(m_stream.hasText());
+ assertEquals(XMLStreamConstants.END_ELEMENT, m_stream.next());
+ assertFalse(m_stream.hasText());
+
+ assertEquals(XMLStreamConstants.CHARACTERS, m_stream.next());
// assertTrue( m_stream.isWhiteSpace());
- assertTrue(m_stream.hasText());
+ assertTrue(m_stream.hasText());
+
+ m_stream.close();
+ }
}
//also testing getTextStart and getTextLength
@Test
- public void testGetTextCharacters() throws Exception {
- try {
+ void testGetTextCharacters() throws Exception {
+ try (XmlCursor cur = cur()) {
+ XMLStreamReader m_stream = cur.newXMLStreamReader();
+
assertEquals(XMLStreamConstants.START_DOCUMENT, m_stream.getEventType());
- m_stream.getTextLength();
- fail("Illegal State");
- } catch (IllegalStateException e) {
- }
+ assertThrows(IllegalStateException.class, m_stream::getTextLength);
- assertEquals(XMLStreamConstants.COMMENT, m_stream.next());
- char[] result = m_stream.getTextCharacters();
- assertEquals(" some comment ", new String(result).substring(m_stream.getTextStart(),
- m_stream.getTextLength()));
+ assertEquals(XMLStreamConstants.COMMENT, m_stream.next());
+ char[] result = m_stream.getTextCharacters();
+ assertEquals(" some comment ", new String(result).substring(m_stream.getTextStart(),
+ m_stream.getTextLength()));
- try {
assertEquals(XMLStreamConstants.START_ELEMENT, m_stream.next());
- m_stream.getTextLength();
- fail("Illegal State");
- } catch (IllegalStateException e) {
- }
-
+ assertThrows(IllegalStateException.class, m_stream::getTextLength);
- assertEquals(XMLStreamConstants.CHARACTERS, m_stream.next());
- result = m_stream.getTextCharacters();
- assertEquals("some text", new String(result).substring(m_stream.getTextStart(),
- m_stream.getTextLength()));
+ assertEquals(XMLStreamConstants.CHARACTERS, m_stream.next());
+ result = m_stream.getTextCharacters();
+ assertEquals("some text", new String(result).substring(m_stream.getTextStart(), m_stream.getTextLength()));
- m_stream.next();
- m_stream.next();//skip empty elt
- m_stream.next(); //end foo
- assertEquals(XMLStreamConstants.CHARACTERS, m_stream.next());
- result = m_stream.getTextCharacters();
- assertEquals("\t", new String(result).substring(m_stream.getTextStart(),
- m_stream.getTextLength()));
- try {
m_stream.next();
- m_stream.getTextLength();
- fail("Illegal State");
- } catch (IllegalStateException e) {
+ m_stream.next();//skip empty elt
+ m_stream.next(); //end foo
+ assertEquals(XMLStreamConstants.CHARACTERS, m_stream.next());
+ result = m_stream.getTextCharacters();
+ assertEquals("\t", new String(result).substring(m_stream.getTextStart(), m_stream.getTextLength()));
+ m_stream.next();
+ assertThrows(IllegalStateException.class, m_stream::getTextLength);
+
+ m_stream.close();
}
+
}
- @Test(expected = IndexOutOfBoundsException.class)
- public void testGetTextCharactersBufferNegStart() throws Exception {
- m_stream.next();
- m_stream.getTextCharacters(-1, new char[10], 12, 12);
+ @Test
+ void testGetTextCharactersBufferNegStart() throws Exception {
+ try (XmlCursor cur = cur()) {
+ XMLStreamReader m_stream = cur.newXMLStreamReader();
+ m_stream.next();
+ assertThrows(IndexOutOfBoundsException.class, () -> m_stream.getTextCharacters(-1, new char[10], 12, 12));
+ m_stream.close();
+ }
}
- @Test(expected = NullPointerException.class)
- public void testGetTextCharactersBufferNull() throws Exception {
- m_stream.next();
- m_stream.getTextCharacters(0, null, 12, 12);
+ @Test
+ void testGetTextCharactersBufferNull() throws Exception {
+ try (XmlCursor cur = cur()) {
+ XMLStreamReader m_stream = cur.newXMLStreamReader();
+ m_stream.next();
+ assertThrows(NullPointerException.class, () -> m_stream.getTextCharacters(0, null, 12, 12));
+ m_stream.close();
+ }
}
- @Test(expected = IndexOutOfBoundsException.class)
- public void testGetTextCharactersLargeSrcOff() throws Exception {
- m_stream.next();
- m_stream.getTextCharacters(110, new char[10], 0, 9);
+ @Test
+ void testGetTextCharactersLargeSrcOff() throws Exception {
+ try (XmlCursor cur = cur()) {
+ XMLStreamReader m_stream = cur.newXMLStreamReader();
+ m_stream.next();
+ assertThrows(IndexOutOfBoundsException.class, () -> m_stream.getTextCharacters(110, new char[10], 0, 9));
+ m_stream.close();
+ }
}
- @Test(expected = IndexOutOfBoundsException.class)
- public void testGetTextCharactersLargeTrgOff() throws Exception {
- m_stream.next();
- m_stream.getTextCharacters(110, new char[10], 10, 9);
+ @Test
+ void testGetTextCharactersLargeTrgOff() throws Exception {
+ try (XmlCursor cur = cur()) {
+ XMLStreamReader m_stream = cur.newXMLStreamReader();
+ m_stream.next();
+ assertThrows(IndexOutOfBoundsException.class, () -> m_stream.getTextCharacters(110, new char[10], 10, 9));
+ m_stream.close();
+ }
}
- @Test(expected = IndexOutOfBoundsException.class)
- public void testGetTextCharactersLargeLen() throws Exception {
- m_stream.next();
- char[] buff = new char[9];
- m_stream.getTextCharacters(0, buff, 0, 30);
+ @Test
+ void testGetTextCharactersLargeLen() throws Exception {
+ try (XmlCursor cur = cur()) {
+ XMLStreamReader m_stream = cur.newXMLStreamReader();
+ m_stream.next();
+ char[] buff = new char[9];
+ assertThrows(IndexOutOfBoundsException.class, () -> m_stream.getTextCharacters(0, buff, 0, 30));
+ m_stream.close();
+ }
}
//off+len past end
- @Test(expected = IndexOutOfBoundsException.class)
- public void testGetTextCharactersLargeSum() throws Exception {
- m_stream.next();
- char[] buff = new char[9];
- m_stream.getTextCharacters(0, buff, 3, 10);
+ @Test
+ void testGetTextCharactersLargeSum() throws Exception {
+ try (XmlCursor cur = cur()) {
+ XMLStreamReader m_stream = cur.newXMLStreamReader();
+ m_stream.next();
+ char[] buff = new char[9];
+ assertThrows(IndexOutOfBoundsException.class, () -> m_stream.getTextCharacters(0, buff, 3, 10));
+ m_stream.close();
+ }
}
@Test
- public void testGetText() throws Exception {
- try {
+ void testGetText() throws Exception {
+ try (XmlCursor cur = cur()) {
+ XMLStreamReader m_stream = cur.newXMLStreamReader();
assertEquals(XMLStreamConstants.START_DOCUMENT, m_stream.getEventType());
- m_stream.getText();
- fail("Illegal State");
- } catch (IllegalStateException e) {
- }
+ assertThrows(IllegalStateException.class, m_stream::getText);
- assertEquals(XMLStreamConstants.COMMENT, m_stream.next());
- String result = m_stream.getText();
- assertEquals(" some comment ", result);
+ assertEquals(XMLStreamConstants.COMMENT, m_stream.next());
+ String result = m_stream.getText();
+ assertEquals(" some comment ", result);
- try {
assertEquals(XMLStreamConstants.START_ELEMENT, m_stream.next());
- m_stream.getText();
- fail("Illegal State");
- } catch (IllegalStateException e) {
- }
+ assertThrows(IllegalStateException.class, m_stream::getText);
+ assertEquals(XMLStreamConstants.CHARACTERS, m_stream.next());
+ result = m_stream.getText();
+ assertEquals("some text", result);
- assertEquals(XMLStreamConstants.CHARACTERS, m_stream.next());
- result = m_stream.getText();
- assertEquals("some text", result);
-
- m_stream.next();
- m_stream.next();//skip empty elt
- m_stream.next(); //end foo
- assertEquals(XMLStreamConstants.CHARACTERS, m_stream.next());
- result = m_stream.getText();
- assertEquals("\t", result);
- try {
m_stream.next();
- m_stream.getText();
- fail("Illegal State");
- } catch (IllegalStateException e) {
- }
- }
-
- @Before
- public void setUp() throws Exception {
- try (XmlCursor cur = XmlObject.Factory.newInstance().newCursor()) {
- cur.toNextToken();
-
- // cur.insertAttributeWithValue(new QName("foo.org", "at0", "pre"), "val0");
- cur.insertComment(" some comment ");
- cur.beginElement(new QName("foo.org", "foo", ""));
- cur.insertAttribute("localName");
- cur.insertChars("some text");
- cur.insertElement("foo2");
- cur.toNextToken(); //close foo elt
- cur.insertChars("\t");
-
-
- cur.toStartDoc();
- m_stream = getStream(cur);
- }
- }
+ m_stream.next();//skip empty elt
+ m_stream.next(); //end foo
+ assertEquals(XMLStreamConstants.CHARACTERS, m_stream.next());
+ result = m_stream.getText();
+ assertEquals("\t", result);
+ m_stream.next();
+ assertThrows(IllegalStateException.class, m_stream::getText);
- @After
- public void tearDown() throws Exception {
- if (m_stream != null)
m_stream.close();
+ }
}
}
\ No newline at end of file
Modified: xmlbeans/trunk/src/test/java/xmlcursor/jsr173/common/ElementTest.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/xmlcursor/jsr173/common/ElementTest.java?rev=1897795&r1=1897794&r2=1897795&view=diff
==============================================================================
--- xmlbeans/trunk/src/test/java/xmlcursor/jsr173/common/ElementTest.java (original)
+++ xmlbeans/trunk/src/test/java/xmlcursor/jsr173/common/ElementTest.java Sun Feb 6 01:51:55 2022
@@ -19,135 +19,137 @@ package xmlcursor.jsr173.common;
import org.apache.xmlbeans.XmlCursor;
import org.apache.xmlbeans.XmlObject;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
-@Ignore("abstract class")
-public abstract class ElementTest {
+public class ElementTest {
- private XMLStreamReader m_stream;
- private XmlCursor cur;
-
- public abstract XMLStreamReader getStream(XmlCursor c) throws Exception;
+ private static XmlCursor cur() {
+ XmlCursor cur = XmlObject.Factory.newInstance().newCursor();
+ cur.toNextToken();
- @Test
- public void testGetElementText() throws Exception {
- cur.toFirstChild(); //first element?
- m_stream = getStream(cur);
+ cur.insertAttributeWithValue(new QName("foo.org", "at0", "pre"),
+ "val0");
+ cur.insertNamespace("pre", "foons.bar.org");
+ cur.beginElement(new QName("foo.org", "foo", ""));
+ cur.insertAttribute("localName");
+ cur.insertChars("some text");
+ cur.toNextToken();
+ cur.toNextToken();//end elt
+ cur.insertElement("foo1");
+ cur.beginElement(new QName("foo.org", "foo", ""));
+ cur.insertChars("\t");
+ cur.insertElement("foo2");
+ cur.insertChars("hooa");
- assertEquals("some text", m_stream.getElementText());
+ cur.toStartDoc();
+ return cur;
}
- @Test
- public void testGetElementTextEmptyElt() throws Exception {
- cur.toFirstChild(); //first element?
- cur.toNextSibling();
- m_stream = getStream(cur);
-
- assertEquals("", m_stream.getElementText());
- }
@Test
- public void testGetElementTextMixedContent() throws Exception {
- cur.toFirstChild(); //first element?
- cur.toNextSibling();
- cur.toNextSibling();
- m_stream = getStream(cur);
- assertEquals(new QName("foo.org", "foo", ""), m_stream.getName());
- try {
- assertEquals("\thooa", m_stream.getElementText());
- fail("Mixed content needs exception");
- } catch (javax.xml.stream.XMLStreamException e) {
+ void testGetElementText() throws Exception {
+ try (XmlCursor cur = cur()) {
+ //first element?
+ cur.toFirstChild();
+ XMLStreamReader m_stream = cur.newXMLStreamReader();
+ assertEquals("some text", m_stream.getElementText());
+ m_stream.close();
}
-
- //mixed content txt1, PI, COMMENT,txt2:
- //should coalesce txt1 & txt2
- cur = XmlObject.Factory.newInstance().newCursor();
- cur.toNextToken();
- cur.beginElement("foo");
- cur.insertChars(" \n ");
- cur.insertComment("My comment");
- cur.insertProcInst("xml-stylesheet", "http://foobar");
- cur.insertChars("txt1\t");
- cur.toStartDoc();
- m_stream = getStream(cur);
- assertEquals(XMLStreamConstants.START_ELEMENT, m_stream.next());
- assertEquals(" \n txt1\t", m_stream.getElementText());
}
@Test
- public void testGetNameAtStartElt() throws Exception {
- cur.toFirstChild(); //first element
- m_stream = getStream(cur);
- assertEquals(new QName("foo.org", "foo", ""), m_stream.getName());
+ void testGetElementTextEmptyElt() throws Exception {
+ try (XmlCursor cur = cur()) {
+ //first element?
+ cur.toFirstChild();
+ cur.toNextSibling();
+ XMLStreamReader m_stream = cur.newXMLStreamReader();
+ assertEquals("", m_stream.getElementText());
+ m_stream.close();
+ }
}
@Test
- public void testGetNameAtEndElt() throws Exception {
- cur.toFirstChild();
- m_stream = getStream(cur);
- m_stream.next();
- assertEquals(XMLStreamConstants.END_ELEMENT, m_stream.next());
- assertEquals(new QName("foo.org", "foo", ""), m_stream.getName());
+ void testGetElementTextMixedContent() throws Exception {
+ try (XmlCursor cur = cur()) {
+ //first element?
+ cur.toFirstChild();
+ cur.toNextSibling();
+ cur.toNextSibling();
+ XMLStreamReader m_stream = cur.newXMLStreamReader();
+ assertEquals(new QName("foo.org", "foo", ""), m_stream.getName());
+ assertThrows(XMLStreamException.class, m_stream::getElementText, "Mixed content needs exception");
+ m_stream.close();
+ }
+ //mixed content txt1, PI, COMMENT,txt2:
+ //should coalesce txt1 & txt2
+ try (XmlCursor cur = XmlObject.Factory.newInstance().newCursor()) {
+ cur.toNextToken();
+ cur.beginElement("foo");
+ cur.insertChars(" \n ");
+ cur.insertComment("My comment");
+ cur.insertProcInst("xml-stylesheet", "http://foobar");
+ cur.insertChars("txt1\t");
+ cur.toStartDoc();
+ XMLStreamReader m_stream = cur.newXMLStreamReader();
+ assertEquals(XMLStreamConstants.START_ELEMENT, m_stream.next());
+ assertEquals(" \n txt1\t", m_stream.getElementText());
+ m_stream.close();
+ }
}
@Test
- public void testHasName() throws Exception {
- m_stream = getStream(cur);
- m_stream.next();
- m_stream.next();
- assertEquals(XMLStreamConstants.START_ELEMENT, m_stream.next());
- assertTrue(m_stream.hasName());
+ void testGetNameAtStartElt() throws Exception {
+ try (XmlCursor cur = cur()) {
+ //first element
+ cur.toFirstChild();
+ XMLStreamReader m_stream = cur.newXMLStreamReader();
+ assertEquals(new QName("foo.org", "foo", ""), m_stream.getName());
+ m_stream.close();
+ }
}
- //call at a bad place..here just attr but should exhaust all
@Test
- public void testGetNameIllegal() throws Exception {
- cur.toNextToken(); //attr
- m_stream = getStream(cur);
- try {
- m_stream.getName();
- fail("getName illegal pos");
- } catch (java.lang.IllegalStateException e) {
+ void testGetNameAtEndElt() throws Exception {
+ try (XmlCursor cur = cur()) {
+ cur.toFirstChild();
+ XMLStreamReader m_stream = cur.newXMLStreamReader();
+ m_stream.next();
+ assertEquals(XMLStreamConstants.END_ELEMENT, m_stream.next());
+ assertEquals(new QName("foo.org", "foo", ""), m_stream.getName());
+ m_stream.close();
}
-
- assertFalse(m_stream.hasName());
}
- @Before
- public void setUp() throws Exception {
- cur = XmlObject.Factory.newInstance().newCursor();
- cur.toNextToken();
-
- cur.insertAttributeWithValue(new QName("foo.org", "at0", "pre"),
- "val0");
- cur.insertNamespace("pre", "foons.bar.org");
- cur.beginElement(new QName("foo.org", "foo", ""));
- cur.insertAttribute("localName");
- cur.insertChars("some text");
- cur.toNextToken();
- cur.toNextToken();//end elt
- cur.insertElement("foo1");
- cur.beginElement(new QName("foo.org", "foo", ""));
- cur.insertChars("\t");
- cur.insertElement("foo2");
- cur.insertChars("hooa");
-
- cur.toStartDoc();
-
+ @Test
+ void testHasName() throws Exception {
+ try (XmlCursor cur = cur()) {
+ XMLStreamReader m_stream = cur.newXMLStreamReader();
+ m_stream.next();
+ m_stream.next();
+ assertEquals(XMLStreamConstants.START_ELEMENT, m_stream.next());
+ assertTrue(m_stream.hasName());
+ m_stream.close();
+ }
}
- @After
- public void tearDown() throws Exception {
- if (m_stream != null)
+ //call at a bad place..here just attr but should exhaust all
+ @Test
+ void testGetNameIllegal() throws Exception {
+ try (XmlCursor cur = cur()) {
+ //attr
+ cur.toNextToken();
+ XMLStreamReader m_stream = cur.newXMLStreamReader();
+ assertThrows(IllegalStateException.class, m_stream::getName, "getName illegal pos");
+ assertFalse(m_stream.hasName());
m_stream.close();
+ }
}
}
\ No newline at end of file
Modified: xmlbeans/trunk/src/test/java/xmlcursor/jsr173/common/GeneralMethodsTest.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/xmlcursor/jsr173/common/GeneralMethodsTest.java?rev=1897795&r1=1897794&r2=1897795&view=diff
==============================================================================
--- xmlbeans/trunk/src/test/java/xmlcursor/jsr173/common/GeneralMethodsTest.java (original)
+++ xmlbeans/trunk/src/test/java/xmlcursor/jsr173/common/GeneralMethodsTest.java Sun Feb 6 01:51:55 2022
@@ -18,11 +18,7 @@ package xmlcursor.jsr173.common;
import org.apache.xmlbeans.XmlCursor;
import org.apache.xmlbeans.XmlDocumentProperties;
import org.apache.xmlbeans.XmlObject;
-import org.apache.xmlbeans.XmlOptions;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import javax.xml.namespace.QName;
import javax.xml.stream.Location;
@@ -30,7 +26,7 @@ import javax.xml.stream.XMLStreamConstan
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
/**
@@ -45,93 +41,68 @@ import static org.junit.Assert.*;
* require
* standaloneSet
*/
-@Ignore("abstract class")
-public abstract class GeneralMethodsTest {
+public class GeneralMethodsTest {
- private XMLStreamReader m_stream;
- private XMLStreamReader m_stream1;
+ private static XmlCursor cur() throws Exception {
+ XmlCursor cur = XmlObject.Factory.newInstance().newCursor();
+ cur.toNextToken();
+
+ cur.insertAttributeWithValue(new QName("foo.org", "at0", "pre"), "val0");
+ cur.insertAttributeWithValue(new QName("", "at1", "pre"), "val1");
+ cur.insertNamespace("pre", "foons.bar.org");
+ cur.beginElement(new QName("foo.org", "foo", ""));
+ cur.insertAttribute("localName");
+ cur.insertChars("some text");
+ cur.toNextToken();
+ cur.toNextToken();//end elt
+ cur.insertProcInst("xml-stylesheet", "http://foobar");
- public abstract XMLStreamReader getStream(XmlCursor c) throws Exception;
+ cur.toStartDoc();
- @Test
- public void testClose() throws Exception {
- m_stream.close();
- m_stream.next();
+ return cur;
}
@Test
- public void testAll() throws Exception {
- m_stream.next();
- m_stream.next();
- assertEquals("utf-8", m_stream.getCharacterEncodingScheme());
- assertEquals("utf-8", m_stream1.getCharacterEncodingScheme());
- assertNull(m_stream1.getEncoding());
- //TODO: why is this still -1???
- Location l = m_stream.getLocation();
- assertEquals(-1, l.getCharacterOffset());
- assertEquals(-1, l.getColumnNumber());
- assertEquals(-1, l.getLineNumber());
- assertNull(l.getPublicId());
- assertNull(l.getSystemId());
-
-
- // m_stream.getProperty("");
- m_stream.getVersion();
-// m_stream.isStandalone();
- assertEquals(XMLStreamConstants.ATTRIBUTE, m_stream.getEventType());
- //only elements can have localnames
- try {
- m_stream.require(10, "", "at1");
- fail("IllegalStateException needed here");
- } catch (IllegalStateException e) {
- }
-
-
- m_stream.next();
- assertEquals(XMLStreamConstants.START_ELEMENT, m_stream.next());
- m_stream.require(1, "foo.org", "foo");
- try {
- m_stream.require(10, "", "");
- fail("XMLStreamException needed here");
- } catch (XMLStreamException e) {
+ void testClose() throws Exception {
+ try (XmlCursor cur = cur()) {
+ XMLStreamReader m_stream = cur.newXMLStreamReader();
+ m_stream.close();
+ m_stream.next();
}
-
-
-// m_stream.standaloneSet();
}
- @Before
- public void setUp() throws Exception {
- try (XmlCursor cur = XmlObject.Factory.newInstance().newCursor()) {
- cur.toNextToken();
-
- cur.insertAttributeWithValue(new QName("foo.org", "at0", "pre"),
- "val0");
- cur.insertAttributeWithValue(new QName("", "at1", "pre"), "val1");
- cur.insertNamespace("pre", "foons.bar.org");
- cur.beginElement(new QName("foo.org", "foo", ""));
- cur.insertAttribute("localName");
- cur.insertChars("some text");
- cur.toNextToken();
- cur.toNextToken();//end elt
- cur.insertProcInst("xml-stylesheet", "http://foobar");
-
- cur.toStartDoc();
+ @Test
+ void testAll() throws Exception {
+ try (XmlCursor cur = cur()) {
+ XMLStreamReader m_stream1 = cur.newXMLStreamReader();
XmlDocumentProperties opt = cur.documentProperties();
-
- m_stream1 = getStream(cur);
-
opt.setEncoding("utf-8");
- m_stream = getStream(cur);
- }
-
- }
+ XMLStreamReader m_stream = cur.newXMLStreamReader();
+ m_stream.next();
+ m_stream.next();
+ assertEquals("utf-8", m_stream.getCharacterEncodingScheme());
+ assertEquals("utf-8", m_stream1.getCharacterEncodingScheme());
+ assertNull(m_stream1.getEncoding());
+ //TODO: why is this still -1???
+ Location l = m_stream.getLocation();
+ assertEquals(-1, l.getCharacterOffset());
+ assertEquals(-1, l.getColumnNumber());
+ assertEquals(-1, l.getLineNumber());
+ assertNull(l.getPublicId());
+ assertNull(l.getSystemId());
+
+
+ m_stream.getVersion();
+ assertEquals(XMLStreamConstants.ATTRIBUTE, m_stream.getEventType());
+ //only elements can have localnames
+ assertThrows(IllegalStateException.class, () -> m_stream.require(10, "", "at1"));
+
+ m_stream.next();
+ assertEquals(XMLStreamConstants.START_ELEMENT, m_stream.next());
+ m_stream.require(1, "foo.org", "foo");
+ assertThrows(XMLStreamException.class, () -> m_stream.require(10, "", ""));
- @After
- public void tearDown() throws Exception {
- if (m_stream != null)
m_stream.close();
+ }
}
-
-
}
\ No newline at end of file
Modified: xmlbeans/trunk/src/test/java/xmlcursor/jsr173/common/IsXXXTest.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/xmlcursor/jsr173/common/IsXXXTest.java?rev=1897795&r1=1897794&r2=1897795&view=diff
==============================================================================
--- xmlbeans/trunk/src/test/java/xmlcursor/jsr173/common/IsXXXTest.java (original)
+++ xmlbeans/trunk/src/test/java/xmlcursor/jsr173/common/IsXXXTest.java Sun Feb 6 01:51:55 2022
@@ -18,115 +18,97 @@ package xmlcursor.jsr173.common;
import org.apache.xmlbeans.XmlCursor;
import org.apache.xmlbeans.XmlObject;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamReader;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
/**
* This class tests next, hasNext, nextTag,getEventType and isXXX methods
*/
-@Ignore("abstract class")
-public abstract class IsXXXTest {
+public class IsXXXTest {
- private XMLStreamReader m_stream;
+ private static XmlCursor cur() {
+ XmlCursor cur = XmlObject.Factory.newInstance().newCursor();
+ cur.toNextToken();
+
+ cur.insertAttributeWithValue(new QName("foo.org", "at0", "pre"), "val0");
+ cur.insertAttributeWithValue(new QName("", "at1", "pre"), "val1");
+ cur.insertNamespace("pre", "foons.bar.org");
+ cur.beginElement(new QName("foo.org", "foo", ""));
+ cur.insertAttribute("localName");
+ cur.insertChars("some text");
+ cur.toNextToken();
+ cur.toNextToken();//end elt
+ cur.insertProcInst("xml-stylesheet", "http://foobar");
+ cur.insertChars("\t");
+ cur.insertComment(" some comment ");
- public abstract XMLStreamReader getStream(XmlCursor c) throws Exception;
-
- @Test
- public void testAll() throws Exception {
- assertEquals(XMLStreamConstants.START_DOCUMENT,
- m_stream.getEventType());
-
- assertTrue(m_stream.hasNext());
- assertEquals(XMLStreamConstants.ATTRIBUTE, m_stream.next());
- assertEquals(XMLStreamConstants.ATTRIBUTE, m_stream.getEventType());
- assertFalse(m_stream.isAttributeSpecified(0));
-
- assertTrue(m_stream.hasNext());
- assertEquals(XMLStreamConstants.ATTRIBUTE, m_stream.next());
- assertEquals(XMLStreamConstants.ATTRIBUTE, m_stream.getEventType());
- assertFalse(m_stream.isAttributeSpecified(0));
-
- assertTrue(m_stream.hasNext());
- assertEquals(XMLStreamConstants.NAMESPACE, m_stream.next());
- assertEquals(XMLStreamConstants.NAMESPACE, m_stream.getEventType());
- assertFalse(m_stream.isCharacters());
-
- assertTrue(m_stream.hasNext());
- assertEquals(XMLStreamConstants.START_ELEMENT, m_stream.next());
- assertEquals(XMLStreamConstants.START_ELEMENT, m_stream.getEventType());
- assertTrue(m_stream.isStartElement());
-
- assertTrue(m_stream.hasNext());
- assertEquals(XMLStreamConstants.CHARACTERS, m_stream.next());
- assertEquals(XMLStreamConstants.CHARACTERS, m_stream.getEventType());
- assertTrue(m_stream.isCharacters());
-
- assertTrue(m_stream.hasNext());
- assertEquals(XMLStreamConstants.END_ELEMENT, m_stream.next());
- assertEquals(XMLStreamConstants.END_ELEMENT, m_stream.getEventType());
- assertTrue(m_stream.isEndElement());
-
- assertTrue(m_stream.hasNext());
- assertEquals(XMLStreamConstants.PROCESSING_INSTRUCTION,
- m_stream.next());
- assertEquals(XMLStreamConstants.PROCESSING_INSTRUCTION,
- m_stream.getEventType());
-
-
- assertTrue(m_stream.hasNext());
- assertEquals(XMLStreamConstants.CHARACTERS, m_stream.next());
- assertEquals(XMLStreamConstants.CHARACTERS, m_stream.getEventType());
- assertTrue(m_stream.isCharacters());
-// assertTrue(m_stream.isWhiteSpace());
-
- assertTrue(m_stream.hasNext());
- assertEquals(XMLStreamConstants.COMMENT, m_stream.next());
- assertEquals(XMLStreamConstants.COMMENT, m_stream.getEventType());
- assertFalse(m_stream.isCharacters());
-
- assertTrue(m_stream.hasNext());
- assertEquals(XMLStreamConstants.END_DOCUMENT, m_stream.next());
- assertEquals(XMLStreamConstants.END_DOCUMENT, m_stream.getEventType());
-// assertFalse(m_stream.isWhiteSpace());
-
- assertFalse(m_stream.hasNext());
+ cur.toStartDoc();
+ return cur;
}
- @Before
- public void setUp() throws Exception {
- try (XmlCursor cur = XmlObject.Factory.newInstance().newCursor()) {
- cur.toNextToken();
-
- cur.insertAttributeWithValue(new QName("foo.org", "at0", "pre"),
- "val0");
- cur.insertAttributeWithValue(new QName("", "at1", "pre"), "val1");
- cur.insertNamespace("pre", "foons.bar.org");
- cur.beginElement(new QName("foo.org", "foo", ""));
- cur.insertAttribute("localName");
- cur.insertChars("some text");
- cur.toNextToken();
- cur.toNextToken();//end elt
- cur.insertProcInst("xml-stylesheet", "http://foobar");
- cur.insertChars("\t");
- cur.insertComment(" some comment ");
-
- cur.toStartDoc();
+ @Test
+ void testAll() throws Exception {
+ try (XmlCursor cur = cur()) {
+ XMLStreamReader m_stream = cur.newXMLStreamReader();
+ assertEquals(XMLStreamConstants.START_DOCUMENT, m_stream.getEventType());
+
+ assertTrue(m_stream.hasNext());
+ assertEquals(XMLStreamConstants.ATTRIBUTE, m_stream.next());
+ assertEquals(XMLStreamConstants.ATTRIBUTE, m_stream.getEventType());
+ assertFalse(m_stream.isAttributeSpecified(0));
+
+ assertTrue(m_stream.hasNext());
+ assertEquals(XMLStreamConstants.ATTRIBUTE, m_stream.next());
+ assertEquals(XMLStreamConstants.ATTRIBUTE, m_stream.getEventType());
+ assertFalse(m_stream.isAttributeSpecified(0));
+
+ assertTrue(m_stream.hasNext());
+ assertEquals(XMLStreamConstants.NAMESPACE, m_stream.next());
+ assertEquals(XMLStreamConstants.NAMESPACE, m_stream.getEventType());
+ assertFalse(m_stream.isCharacters());
+
+ assertTrue(m_stream.hasNext());
+ assertEquals(XMLStreamConstants.START_ELEMENT, m_stream.next());
+ assertEquals(XMLStreamConstants.START_ELEMENT, m_stream.getEventType());
+ assertTrue(m_stream.isStartElement());
+
+ assertTrue(m_stream.hasNext());
+ assertEquals(XMLStreamConstants.CHARACTERS, m_stream.next());
+ assertEquals(XMLStreamConstants.CHARACTERS, m_stream.getEventType());
+ assertTrue(m_stream.isCharacters());
+
+ assertTrue(m_stream.hasNext());
+ assertEquals(XMLStreamConstants.END_ELEMENT, m_stream.next());
+ assertEquals(XMLStreamConstants.END_ELEMENT, m_stream.getEventType());
+ assertTrue(m_stream.isEndElement());
+
+ assertTrue(m_stream.hasNext());
+ assertEquals(XMLStreamConstants.PROCESSING_INSTRUCTION, m_stream.next());
+ assertEquals(XMLStreamConstants.PROCESSING_INSTRUCTION, m_stream.getEventType());
+
+
+ assertTrue(m_stream.hasNext());
+ assertEquals(XMLStreamConstants.CHARACTERS, m_stream.next());
+ assertEquals(XMLStreamConstants.CHARACTERS, m_stream.getEventType());
+ assertTrue(m_stream.isCharacters());
+
+ assertTrue(m_stream.hasNext());
+ assertEquals(XMLStreamConstants.COMMENT, m_stream.next());
+ assertEquals(XMLStreamConstants.COMMENT, m_stream.getEventType());
+ assertFalse(m_stream.isCharacters());
+
+ assertTrue(m_stream.hasNext());
+ assertEquals(XMLStreamConstants.END_DOCUMENT, m_stream.next());
+ assertEquals(XMLStreamConstants.END_DOCUMENT, m_stream.getEventType());
- m_stream = getStream(cur);
- }
- }
+ assertFalse(m_stream.hasNext());
- @After
- public void tearDown() throws Exception {
- if (m_stream != null)
m_stream.close();
+ }
}
}
\ No newline at end of file
Modified: xmlbeans/trunk/src/test/java/xmlcursor/jsr173/common/NamespaceTest.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/xmlcursor/jsr173/common/NamespaceTest.java?rev=1897795&r1=1897794&r2=1897795&view=diff
==============================================================================
--- xmlbeans/trunk/src/test/java/xmlcursor/jsr173/common/NamespaceTest.java (original)
+++ xmlbeans/trunk/src/test/java/xmlcursor/jsr173/common/NamespaceTest.java Sun Feb 6 01:51:55 2022
@@ -18,16 +18,13 @@ package xmlcursor.jsr173.common;
import org.apache.xmlbeans.XmlCursor;
import org.apache.xmlbeans.XmlObject;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamReader;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
/**
@@ -40,242 +37,220 @@ import static org.junit.Assert.*;
* getNamespaceURI x 3
* getPrefix
*/
-@Ignore("abstract class")
-public abstract class NamespaceTest {
+public class NamespaceTest {
- private XMLStreamReader m_stream;
-
- //only valid at TAGs and ER
- //TODO: ER
-
- public abstract XMLStreamReader getStream(XmlCursor c) throws Exception;
+ private static XmlCursor cur() {
+ XmlCursor cur = XmlObject.Factory.newInstance().newCursor();
+ cur.toNextToken();
+
+ cur.insertAttributeWithValue(new QName("foo.org", "at0", "pre"),
+ "val0");
+ cur.insertNamespace("pre0", "bea.com");
+
+ cur.beginElement(new QName("foo.org", "foo", ""));
+ cur.insertNamespace("pre", "foons.bar.org");
+ cur.insertNamespace("pre1", "foons1.bar1.org1");
+ cur.insertChars("some text");
+ cur.toNextToken();
+ cur.toNextToken();//end elt
+ cur.insertProcInst("xml-stylesheet", "http://foobar");
+ cur.insertChars("\t");
+ cur.insertComment(" some comment ");
+
+ cur.toStartDoc();
+
+ return cur;
+ }
@Test
- public void testGetLocalName() throws Exception {
- try {
- m_stream.getLocalName();
- fail("no name at startdoc");
- } catch (IllegalStateException e) {
+ void testGetLocalName() throws Exception {
+ try (XmlCursor cur = cur()) {
+ XMLStreamReader m_stream = cur.newXMLStreamReader();
+
+ assertThrows(IllegalStateException.class, m_stream::getLocalName, "no name at startdoc");
+ m_stream.next();
+ m_stream.next();
+ assertEquals(XMLStreamConstants.START_ELEMENT, m_stream.next());
+ assertEquals("foo", m_stream.getLocalName());
+ m_stream.next();
+ assertEquals(XMLStreamConstants.END_ELEMENT, m_stream.next());
+ assertEquals("foo", m_stream.getLocalName());
+ m_stream.close();
}
-
- m_stream.next();
- m_stream.next();
- assertEquals(XMLStreamConstants.START_ELEMENT, m_stream.next());
- assertEquals("foo", m_stream.getLocalName());
- m_stream.next();
- assertEquals(XMLStreamConstants.END_ELEMENT, m_stream.next());
- assertEquals("foo", m_stream.getLocalName());
}
@Test
- public void testGetName() {
- //test in Element--only valid for Element events
- }
+ void testGetPrefix() throws Exception {
+ try (XmlCursor cur = cur()) {
+ XMLStreamReader m_stream = cur.newXMLStreamReader();
+ assertEquals(XMLStreamConstants.START_DOCUMENT, m_stream.getEventType());
+ assertThrows(IllegalStateException.class, m_stream::getPrefix, "no prefix here");
+
+ // assertFalse( m_stream.hasText() );
+ assertEquals(XMLStreamConstants.ATTRIBUTE, m_stream.next());
+ assertThrows(IllegalStateException.class, m_stream::getPrefix, "no prefix here");
- @Test
- public void testGetPrefix() throws Exception {
- assertEquals(XMLStreamConstants.START_DOCUMENT,
- m_stream.getEventType());
-
- try {
- assertNull(m_stream.getPrefix());
- fail("no prefix here");
- } catch (IllegalStateException e) {
- }
- // assertFalse( m_stream.hasText() );
- assertEquals(XMLStreamConstants.ATTRIBUTE, m_stream.next());
- try {
- assertNull(m_stream.getPrefix());
- fail("no prefix here");
- } catch (IllegalStateException e) {
- }
+ assertEquals(XMLStreamConstants.NAMESPACE, m_stream.next());
+ assertThrows(IllegalStateException.class, m_stream::getPrefix, "no prefix here");
- assertEquals(XMLStreamConstants.NAMESPACE, m_stream.next());
- try {
- assertNull(m_stream.getPrefix());
- fail("no prefix here");
- } catch (IllegalStateException e) {
- }
+ assertEquals(XMLStreamConstants.START_ELEMENT, m_stream.next());
+ assertEquals("", m_stream.getPrefix());
- assertEquals(XMLStreamConstants.START_ELEMENT, m_stream.next());
- assertEquals("", m_stream.getPrefix());
+ assertEquals(XMLStreamConstants.CHARACTERS, m_stream.next());
+ assertThrows(IllegalStateException.class, m_stream::getPrefix, "no prefix here");
- assertEquals(XMLStreamConstants.CHARACTERS, m_stream.next());
- try {
- assertNull(m_stream.getPrefix());
- fail("no prefix here");
- } catch (IllegalStateException e) {
- }
+ assertEquals(XMLStreamConstants.END_ELEMENT, m_stream.next());
+ assertEquals("", m_stream.getPrefix());
+ assertEquals(XMLStreamConstants.PROCESSING_INSTRUCTION, m_stream.next());
+ assertThrows(IllegalStateException.class, m_stream::getPrefix, "no prefix here");
- assertEquals(XMLStreamConstants.END_ELEMENT, m_stream.next());
- assertEquals("", m_stream.getPrefix());
- assertEquals(XMLStreamConstants.PROCESSING_INSTRUCTION, m_stream.next());
- try {
- assertNull(m_stream.getPrefix());
- fail("no prefix here");
- } catch (IllegalStateException e) {
- }
+ assertEquals(XMLStreamConstants.CHARACTERS, m_stream.next());
- assertEquals(XMLStreamConstants.CHARACTERS, m_stream.next());
+ assertEquals(XMLStreamConstants.COMMENT, m_stream.next());
+ assertThrows(IllegalStateException.class, m_stream::getPrefix, "no prefix here");
- assertEquals(XMLStreamConstants.COMMENT, m_stream.next());
- try {
- assertNull(m_stream.getPrefix());
- fail("no prefix here");
- } catch (IllegalStateException e) {
+ m_stream.close();
}
}
@Test
- public void testGetNamespaceContext() throws Exception {
- //assertEquals(XMLStreamConstants.ATTRIBUTE, m_stream.next());
- //assertEquals("", m_stream.getNamespaceContext().getNamespaceURI(""));
- //assertEquals("", m_stream.getNamespaceContext().getPrefix("foo.org"));
- //java.util.Iterator it = m_stream.getNamespaceContext().getPrefixes("foo.bar");
-
- m_stream.next();
- m_stream.next();
- m_stream.next();
-
- assertEquals(XMLStreamConstants.CHARACTERS, m_stream.next());
- //assertEquals("", m_stream.getNamespaceContext().getNamespaceURI("")) ;
- //assertEquals("", m_stream.getNamespaceContext().getPrefix("foo.bar")) ;
- assertNull(m_stream.getNamespaceContext().getPrefix("foo.bar"));
- java.util.Iterator it = m_stream.getNamespaceContext().getPrefixes("foo.bar");
+ void testGetNamespaceContext() throws Exception {
+ try (XmlCursor cur = cur()) {
+ XMLStreamReader m_stream = cur.newXMLStreamReader();
+
+ m_stream.next();
+ m_stream.next();
+ m_stream.next();
+
+ assertEquals(XMLStreamConstants.CHARACTERS, m_stream.next());
+ assertNull(m_stream.getNamespaceContext().getPrefix("foo.bar"));
+ assertNotNull(m_stream.getNamespaceContext().getPrefixes("foo.bar"));
+
+ m_stream.close();
+ }
}
/**
* only valid at Tags and NS decl
*/
@Test
- public void testGetNamespaceCount() throws Exception {
- m_stream.next();
- assertEquals(XMLStreamConstants.NAMESPACE, m_stream.next());
- assertEquals(1, m_stream.getNamespaceCount());
-
- assertEquals(XMLStreamConstants.START_ELEMENT, m_stream.next());
- assertEquals(2, m_stream.getNamespaceCount());
-
- //java.lang.IllegalStateException
- // - if this is not a START_ELEMENT, END_ELEMENT or NAMESPACE
- try {
+ void testGetNamespaceCount() throws Exception {
+ try (XmlCursor cur = cur()) {
+ XMLStreamReader m_stream = cur.newXMLStreamReader();
+ m_stream.next();
+ assertEquals(XMLStreamConstants.NAMESPACE, m_stream.next());
+ assertEquals(1, m_stream.getNamespaceCount());
+
+ assertEquals(XMLStreamConstants.START_ELEMENT, m_stream.next());
+ assertEquals(2, m_stream.getNamespaceCount());
+
+ //java.lang.IllegalStateException
+ // - if this is not a START_ELEMENT, END_ELEMENT or NAMESPACE
+
assertEquals(XMLStreamConstants.CHARACTERS, m_stream.next());
- m_stream.getNamespaceCount();
- fail("can't do this on a txt node");
- } catch (IllegalStateException e) {
- }
+ assertThrows(IllegalStateException.class, m_stream::getNamespaceCount, "can't do this on a txt node");
+
+ assertEquals(XMLStreamConstants.END_ELEMENT, m_stream.next());
+ assertEquals(2, m_stream.getNamespaceCount());
- assertEquals(XMLStreamConstants.END_ELEMENT, m_stream.next());
- assertEquals(2, m_stream.getNamespaceCount());
+ m_stream.close();
+ }
}
/**
* only valid at Tags and NS decl
*/
@Test
- public void testGetNamespacePrefix() throws Exception {
- m_stream.next();
- assertEquals(XMLStreamConstants.NAMESPACE, m_stream.next());
- assertEquals("pre0", m_stream.getNamespacePrefix(0));
-
- assertEquals(XMLStreamConstants.START_ELEMENT, m_stream.next());
- assertEquals("pre", m_stream.getNamespacePrefix(0));
- assertEquals("pre1", m_stream.getNamespacePrefix(1));
- //java.lang.IllegalStateException
- // - if this is not a START_ELEMENT, END_ELEMENT or NAMESPACE
+ void testGetNamespacePrefix() throws Exception {
+ try (XmlCursor cur = cur()) {
+ XMLStreamReader m_stream = cur.newXMLStreamReader();
+ m_stream.next();
+
+ assertEquals(XMLStreamConstants.NAMESPACE, m_stream.next());
+ assertEquals("pre0", m_stream.getNamespacePrefix(0));
+
+ assertEquals(XMLStreamConstants.START_ELEMENT, m_stream.next());
+ assertEquals("pre", m_stream.getNamespacePrefix(0));
+ assertEquals("pre1", m_stream.getNamespacePrefix(1));
+ //java.lang.IllegalStateException
+ // - if this is not a START_ELEMENT, END_ELEMENT or NAMESPACE
- try {
assertEquals(XMLStreamConstants.CHARACTERS, m_stream.next());
assertEquals(XMLStreamConstants.CHARACTERS, m_stream.getEventType());
- m_stream.getNamespacePrefix(0);
- fail("can't do this on a txt node");
- } catch (IllegalStateException e) {
+ assertThrows(IllegalStateException.class, () -> m_stream.getNamespacePrefix(0), "can't do this on a txt node");
+
+ assertEquals(XMLStreamConstants.END_ELEMENT, m_stream.next());
+ assertEquals("pre", m_stream.getNamespacePrefix(0));
+ assertEquals("pre1", m_stream.getNamespacePrefix(1));
+ m_stream.close();
}
+ }
- assertEquals(XMLStreamConstants.END_ELEMENT, m_stream.next());
- assertEquals("pre", m_stream.getNamespacePrefix(0));
- assertEquals("pre1", m_stream.getNamespacePrefix(1));
- }
-
- @Test(expected = IndexOutOfBoundsException.class)
- public void testGetNamespacePrefixNeg() throws Exception {
- m_stream.next();
- assertEquals(XMLStreamConstants.NAMESPACE, m_stream.next());
- m_stream.getNamespacePrefix(-1);
- }
-
- @Test(expected = IndexOutOfBoundsException.class)
- public void testGetNamespacePrefixLarge() throws Exception {
- m_stream.next();
- assertEquals(XMLStreamConstants.NAMESPACE, m_stream.next());
- assertEquals("", m_stream.getNamespacePrefix(3));
+ @Test
+ void testGetNamespacePrefixNeg() throws Exception {
+ try (XmlCursor cur = cur()) {
+ XMLStreamReader m_stream = cur.newXMLStreamReader();
+ m_stream.next();
+ assertEquals(XMLStreamConstants.NAMESPACE, m_stream.next());
+ assertThrows(IndexOutOfBoundsException.class, () -> m_stream.getNamespacePrefix(-1));
+ m_stream.close();
+ }
+ }
+
+ @Test
+ void testGetNamespacePrefixLarge() throws Exception {
+ try (XmlCursor cur = cur()) {
+ XMLStreamReader m_stream = cur.newXMLStreamReader();
+ m_stream.next();
+ assertEquals(XMLStreamConstants.NAMESPACE, m_stream.next());
+ assertThrows(IndexOutOfBoundsException.class, () -> m_stream.getNamespacePrefix(3));
+ m_stream.close();
+ }
}
//3 methods here
@Test
- public void testGetNamespaceURI() throws Exception {
- m_stream.next();
- assertEquals(XMLStreamConstants.NAMESPACE, m_stream.next());
- assertEquals("bea.com", m_stream.getNamespaceURI(0));
-
- assertEquals(XMLStreamConstants.START_ELEMENT, m_stream.next());
- assertEquals("foons.bar.org", m_stream.getNamespaceURI(0));
- assertEquals("foons1.bar1.org1", m_stream.getNamespaceURI(1));
- try {
+ void testGetNamespaceURI() throws Exception {
+ try (XmlCursor cur = cur()) {
+ XMLStreamReader m_stream = cur.newXMLStreamReader();
+ m_stream.next();
+ assertEquals(XMLStreamConstants.NAMESPACE, m_stream.next());
+ assertEquals("bea.com", m_stream.getNamespaceURI(0));
+
+ assertEquals(XMLStreamConstants.START_ELEMENT, m_stream.next());
+ assertEquals("foons.bar.org", m_stream.getNamespaceURI(0));
+ assertEquals("foons1.bar1.org1", m_stream.getNamespaceURI(1));
assertEquals(XMLStreamConstants.CHARACTERS, m_stream.next());
- m_stream.getNamespaceURI(0);
- fail("can't do this on a txt node");
- } catch (IllegalStateException e) {
- }
+ assertThrows(IllegalStateException.class, () -> m_stream.getNamespaceURI(0), "can't do this on a txt node");
- assertEquals(XMLStreamConstants.END_ELEMENT, m_stream.next());
- assertEquals("foons.bar.org", m_stream.getNamespaceURI(0));
- assertEquals("foons1.bar1.org1", m_stream.getNamespaceURI(1));
- }
-
- @Test(expected = IndexOutOfBoundsException.class)
- public void testGetNamespaceURINeg() throws Exception {
- m_stream.next();
- assertEquals(XMLStreamConstants.NAMESPACE, m_stream.next());
- assertEquals("", m_stream.getNamespaceURI(-1));
- }
-
- @Test(expected = IndexOutOfBoundsException.class)
- public void testGetNamespaceURILarge() throws Exception {
- m_stream.next();
- assertEquals(XMLStreamConstants.NAMESPACE, m_stream.next());
- assertEquals("", m_stream.getNamespaceURI(3));
- }
-
- @Before
- public void setUp() throws Exception {
- try (XmlCursor cur = XmlObject.Factory.newInstance().newCursor()) {
- cur.toNextToken();
-
- cur.insertAttributeWithValue(new QName("foo.org", "at0", "pre"),
- "val0");
- cur.insertNamespace("pre0", "bea.com");
-
- cur.beginElement(new QName("foo.org", "foo", ""));
- cur.insertNamespace("pre", "foons.bar.org");
- cur.insertNamespace("pre1", "foons1.bar1.org1");
- cur.insertChars("some text");
- cur.toNextToken();
- cur.toNextToken();//end elt
- cur.insertProcInst("xml-stylesheet", "http://foobar");
- cur.insertChars("\t");
- cur.insertComment(" some comment ");
+ assertEquals(XMLStreamConstants.END_ELEMENT, m_stream.next());
+ assertEquals("foons.bar.org", m_stream.getNamespaceURI(0));
+ assertEquals("foons1.bar1.org1", m_stream.getNamespaceURI(1));
- cur.toStartDoc();
+ m_stream.close();
+ }
+ }
- m_stream = getStream(cur);
+ @Test
+ void testGetNamespaceURINeg() throws Exception {
+ try (XmlCursor cur = cur()) {
+ XMLStreamReader m_stream = cur.newXMLStreamReader();
+ m_stream.next();
+ assertEquals(XMLStreamConstants.NAMESPACE, m_stream.next());
+ assertThrows(IndexOutOfBoundsException.class, () -> m_stream.getNamespaceURI(-1));
+ m_stream.close();
}
}
- @After
- public void tearDown() throws Exception {
- if (m_stream != null)
+ @Test
+ void testGetNamespaceURILarge() throws Exception {
+ try (XmlCursor cur = cur()) {
+ XMLStreamReader m_stream = cur.newXMLStreamReader();
+ m_stream.next();
+ assertEquals(XMLStreamConstants.NAMESPACE, m_stream.next());
+ assertThrows(IndexOutOfBoundsException.class, () -> m_stream.getNamespaceURI(3));
m_stream.close();
+ }
}
}
Modified: xmlbeans/trunk/src/test/java/xmlcursor/jsr173/common/PITest.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/xmlcursor/jsr173/common/PITest.java?rev=1897795&r1=1897794&r2=1897795&view=diff
==============================================================================
--- xmlbeans/trunk/src/test/java/xmlcursor/jsr173/common/PITest.java (original)
+++ xmlbeans/trunk/src/test/java/xmlcursor/jsr173/common/PITest.java Sun Feb 6 01:51:55 2022
@@ -18,62 +18,53 @@ package xmlcursor.jsr173.common;
import org.apache.xmlbeans.XmlCursor;
import org.apache.xmlbeans.XmlObject;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
/**
* Methods tested:
* getPIData
* getPITarget
*/
-@Ignore("abstract class")
-public abstract class PITest {
+public class PITest {
- private XMLStreamReader m_stream;
- public abstract XMLStreamReader getStream(XmlCursor c) throws Exception;
-
- @Test
- public void testGetPiData() throws XMLStreamException {
- assertEquals(XMLStreamConstants.PROCESSING_INSTRUCTION,
- m_stream.next());
- assertEquals("http://foobar", m_stream.getPIData());
- assertEquals(XMLStreamConstants.START_ELEMENT, m_stream.next());
- assertNull(m_stream.getPIData());
+ private static XmlCursor cur() {
+ XmlCursor cur = XmlObject.Factory.newInstance().newCursor();
+ cur.toNextToken();
+ cur.insertProcInst("xml-stylesheet", "http://foobar");
+ cur.insertElement("foobar");
+ cur.toStartDoc();
+ return cur;
}
@Test
- public void testGetPiTarget() throws XMLStreamException {
- assertEquals(XMLStreamConstants.PROCESSING_INSTRUCTION,
- m_stream.next());
- assertEquals("xml-stylesheet", m_stream.getPITarget());
- assertEquals(XMLStreamConstants.START_ELEMENT, m_stream.next());
- assertNull(m_stream.getPITarget());
- }
-
- @Before
- public void setUp() throws Exception {
- try (XmlCursor cur = XmlObject.Factory.newInstance().newCursor()) {
- cur.toNextToken();
- cur.insertProcInst("xml-stylesheet", "http://foobar");
- cur.insertElement("foobar");
- cur.toStartDoc();
- m_stream = getStream(cur);
+ void testGetPiData() throws XMLStreamException {
+ try (XmlCursor cur = cur()) {
+ XMLStreamReader m_stream = cur.newXMLStreamReader();
+ assertEquals(XMLStreamConstants.PROCESSING_INSTRUCTION, m_stream.next());
+ assertEquals("http://foobar", m_stream.getPIData());
+ assertEquals(XMLStreamConstants.START_ELEMENT, m_stream.next());
+ assertNull(m_stream.getPIData());
+ m_stream.close();
}
}
- @After
- public void tearDown() throws Exception {
- if (m_stream != null)
+ @Test
+ void testGetPiTarget() throws XMLStreamException {
+ try (XmlCursor cur = cur()) {
+ XMLStreamReader m_stream = cur.newXMLStreamReader();
+ assertEquals(XMLStreamConstants.PROCESSING_INSTRUCTION, m_stream.next());
+ assertEquals("xml-stylesheet", m_stream.getPITarget());
+ assertEquals(XMLStreamConstants.START_ELEMENT, m_stream.next());
+ assertNull(m_stream.getPITarget());
m_stream.close();
+ }
}
}
Modified: xmlbeans/trunk/src/test/java/xmlcursor/xpath/CustomerTest.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/xmlcursor/xpath/CustomerTest.java?rev=1897795&r1=1897794&r2=1897795&view=diff
==============================================================================
--- xmlbeans/trunk/src/test/java/xmlcursor/xpath/CustomerTest.java (original)
+++ xmlbeans/trunk/src/test/java/xmlcursor/xpath/CustomerTest.java Sun Feb 6 01:51:55 2022
@@ -18,7 +18,7 @@ package xmlcursor.xpath;
import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlObject;
import org.apache.xmlbeans.XmlOptions;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.util.HashMap;
@@ -88,7 +88,7 @@ public class CustomerTest {
}
@Test
- public void test_xpath() throws XmlException {
+ void test_xpath() throws XmlException {
String sXml1 =
"<report>\n" +
" <section>\n" +
@@ -97,16 +97,14 @@ public class CustomerTest {
" The patient was taken to the operating room where she was placed\n" +
" in supine position and\n" +
" </section.content> </section></report>";
- test_xpath(2, sXml1,
- "./report/section/section.title[text() = \"Procedure\"]");
+ test_xpath(2, sXml1, "./report/section/section.title[text() = \"Procedure\"]");
}
@Test
- public void test_xquery() throws XmlException {
+ void test_xquery() throws XmlException {
final String xquery1 =
"for $b in $this/bib/book "
- +
- " where $b/publisher[text() = \"Addison-Wesley\"] and $b[@year > 1992] "
+ + " where $b/publisher[text() = \"Addison-Wesley\"] and $b[@year > 1992] "
+ "return "
+ " <book year=\"{ $b/@year }\"> "
+ "{ $b/title }"
@@ -126,11 +124,10 @@ public class CustomerTest {
}
@Test
- public void testXMLBeans() throws XmlException {
+ void testXMLBeans() throws XmlException {
XmlObject doc = XmlObject.Factory.parse(" <contact xmlns=\"http://dearjohn/address-book\"/>");
HashMap<String, String> nsMap = new HashMap<String, String>();
nsMap.put("ns", "http://dearjohn/address-book");
- doc.execQuery("/ns:contact", new
- XmlOptions().setLoadAdditionalNamespaces(nsMap));
+ doc.execQuery("/ns:contact", new XmlOptions().setLoadAdditionalNamespaces(nsMap));
}
}
Modified: xmlbeans/trunk/src/test/java/xmlcursor/xpath/common/XPathCommon.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/xmlcursor/xpath/common/XPathCommon.java?rev=1897795&r1=1897794&r2=1897795&view=diff
==============================================================================
--- xmlbeans/trunk/src/test/java/xmlcursor/xpath/common/XPathCommon.java (original)
+++ xmlbeans/trunk/src/test/java/xmlcursor/xpath/common/XPathCommon.java Sun Feb 6 01:51:55 2022
@@ -19,10 +19,10 @@ import org.apache.xmlbeans.XmlCursor;
import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlObject;
import org.apache.xmlbeans.XmlOptions;
-import org.junit.Assert;
import tools.xml.XmlComparator;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
public class XPathCommon {
@@ -86,10 +86,10 @@ public class XPathCommon {
expected.xmlText(), diag);
assertTrue(
- "***********************\nFound difference: \nactual=\n'" +
+ match, "***********************\nFound difference: \nactual=\n'" +
actual.xmlText() +
"'\nexpected=\n'" + expected.xmlText()
- + "'\ndiagnostic=" + diag, match);
+ + "'\ndiagnostic=" + diag);
} catch (XmlException e) {
throw new RuntimeException(e);
}
@@ -110,7 +110,7 @@ public class XPathCommon {
}
}
- Assert.assertEquals(rSet.length, rObj.length);
+ assertEquals(rSet.length, rObj.length);
}
public static void compare(XmlCursor rObj, XmlObject[] rSet) {
@@ -121,6 +121,6 @@ public class XPathCommon {
}
}
- Assert.assertEquals(rSet.length, curLen);
+ assertEquals(rSet.length, curLen);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org