test/jaxp/javax/xml/jaxp/unittest/stream/XMLEventReaderTest/EventReaderTest.java
author joehw
Mon, 02 Jul 2018 13:54:01 -0700
changeset 50905 67f6158279d8
permissions -rw-r--r--
8204329: Java API doc for XMLStreamReader.next() needs to be clarified for the exception thrown when hasNext() method returns false Reviewed-by: lancea, rriggs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50905
67f6158279d8 8204329: Java API doc for XMLStreamReader.next() needs to be clarified for the exception thrown when hasNext() method returns false
joehw
parents:
diff changeset
     1
/*
67f6158279d8 8204329: Java API doc for XMLStreamReader.next() needs to be clarified for the exception thrown when hasNext() method returns false
joehw
parents:
diff changeset
     2
 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
67f6158279d8 8204329: Java API doc for XMLStreamReader.next() needs to be clarified for the exception thrown when hasNext() method returns false
joehw
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
67f6158279d8 8204329: Java API doc for XMLStreamReader.next() needs to be clarified for the exception thrown when hasNext() method returns false
joehw
parents:
diff changeset
     4
 *
67f6158279d8 8204329: Java API doc for XMLStreamReader.next() needs to be clarified for the exception thrown when hasNext() method returns false
joehw
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
67f6158279d8 8204329: Java API doc for XMLStreamReader.next() needs to be clarified for the exception thrown when hasNext() method returns false
joehw
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
67f6158279d8 8204329: Java API doc for XMLStreamReader.next() needs to be clarified for the exception thrown when hasNext() method returns false
joehw
parents:
diff changeset
     7
 * published by the Free Software Foundation.
67f6158279d8 8204329: Java API doc for XMLStreamReader.next() needs to be clarified for the exception thrown when hasNext() method returns false
joehw
parents:
diff changeset
     8
 *
67f6158279d8 8204329: Java API doc for XMLStreamReader.next() needs to be clarified for the exception thrown when hasNext() method returns false
joehw
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
67f6158279d8 8204329: Java API doc for XMLStreamReader.next() needs to be clarified for the exception thrown when hasNext() method returns false
joehw
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
67f6158279d8 8204329: Java API doc for XMLStreamReader.next() needs to be clarified for the exception thrown when hasNext() method returns false
joehw
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
67f6158279d8 8204329: Java API doc for XMLStreamReader.next() needs to be clarified for the exception thrown when hasNext() method returns false
joehw
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
67f6158279d8 8204329: Java API doc for XMLStreamReader.next() needs to be clarified for the exception thrown when hasNext() method returns false
joehw
parents:
diff changeset
    13
 * accompanied this code).
67f6158279d8 8204329: Java API doc for XMLStreamReader.next() needs to be clarified for the exception thrown when hasNext() method returns false
joehw
parents:
diff changeset
    14
 *
67f6158279d8 8204329: Java API doc for XMLStreamReader.next() needs to be clarified for the exception thrown when hasNext() method returns false
joehw
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
67f6158279d8 8204329: Java API doc for XMLStreamReader.next() needs to be clarified for the exception thrown when hasNext() method returns false
joehw
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
67f6158279d8 8204329: Java API doc for XMLStreamReader.next() needs to be clarified for the exception thrown when hasNext() method returns false
joehw
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
67f6158279d8 8204329: Java API doc for XMLStreamReader.next() needs to be clarified for the exception thrown when hasNext() method returns false
joehw
parents:
diff changeset
    18
 *
67f6158279d8 8204329: Java API doc for XMLStreamReader.next() needs to be clarified for the exception thrown when hasNext() method returns false
joehw
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
67f6158279d8 8204329: Java API doc for XMLStreamReader.next() needs to be clarified for the exception thrown when hasNext() method returns false
joehw
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
67f6158279d8 8204329: Java API doc for XMLStreamReader.next() needs to be clarified for the exception thrown when hasNext() method returns false
joehw
parents:
diff changeset
    21
 * questions.
67f6158279d8 8204329: Java API doc for XMLStreamReader.next() needs to be clarified for the exception thrown when hasNext() method returns false
joehw
parents:
diff changeset
    22
 */
67f6158279d8 8204329: Java API doc for XMLStreamReader.next() needs to be clarified for the exception thrown when hasNext() method returns false
joehw
parents:
diff changeset
    23
67f6158279d8 8204329: Java API doc for XMLStreamReader.next() needs to be clarified for the exception thrown when hasNext() method returns false
joehw
parents:
diff changeset
    24
package stream.XMLEventReaderTest;
67f6158279d8 8204329: Java API doc for XMLStreamReader.next() needs to be clarified for the exception thrown when hasNext() method returns false
joehw
parents:
diff changeset
    25
67f6158279d8 8204329: Java API doc for XMLStreamReader.next() needs to be clarified for the exception thrown when hasNext() method returns false
joehw
parents:
diff changeset
    26
import java.io.StringReader;
67f6158279d8 8204329: Java API doc for XMLStreamReader.next() needs to be clarified for the exception thrown when hasNext() method returns false
joehw
parents:
diff changeset
    27
import java.util.NoSuchElementException;
67f6158279d8 8204329: Java API doc for XMLStreamReader.next() needs to be clarified for the exception thrown when hasNext() method returns false
joehw
parents:
diff changeset
    28
import javax.xml.stream.XMLEventReader;
67f6158279d8 8204329: Java API doc for XMLStreamReader.next() needs to be clarified for the exception thrown when hasNext() method returns false
joehw
parents:
diff changeset
    29
67f6158279d8 8204329: Java API doc for XMLStreamReader.next() needs to be clarified for the exception thrown when hasNext() method returns false
joehw
parents:
diff changeset
    30
import javax.xml.stream.XMLInputFactory;
67f6158279d8 8204329: Java API doc for XMLStreamReader.next() needs to be clarified for the exception thrown when hasNext() method returns false
joehw
parents:
diff changeset
    31
import org.testng.annotations.Listeners;
67f6158279d8 8204329: Java API doc for XMLStreamReader.next() needs to be clarified for the exception thrown when hasNext() method returns false
joehw
parents:
diff changeset
    32
import org.testng.annotations.Test;
67f6158279d8 8204329: Java API doc for XMLStreamReader.next() needs to be clarified for the exception thrown when hasNext() method returns false
joehw
parents:
diff changeset
    33
67f6158279d8 8204329: Java API doc for XMLStreamReader.next() needs to be clarified for the exception thrown when hasNext() method returns false
joehw
parents:
diff changeset
    34
/*
67f6158279d8 8204329: Java API doc for XMLStreamReader.next() needs to be clarified for the exception thrown when hasNext() method returns false
joehw
parents:
diff changeset
    35
 * @test
67f6158279d8 8204329: Java API doc for XMLStreamReader.next() needs to be clarified for the exception thrown when hasNext() method returns false
joehw
parents:
diff changeset
    36
 * @bug 8204329
67f6158279d8 8204329: Java API doc for XMLStreamReader.next() needs to be clarified for the exception thrown when hasNext() method returns false
joehw
parents:
diff changeset
    37
 * @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest
67f6158279d8 8204329: Java API doc for XMLStreamReader.next() needs to be clarified for the exception thrown when hasNext() method returns false
joehw
parents:
diff changeset
    38
 * @run testng stream.XMLEventReaderTest.EventReaderTest
67f6158279d8 8204329: Java API doc for XMLStreamReader.next() needs to be clarified for the exception thrown when hasNext() method returns false
joehw
parents:
diff changeset
    39
 * @summary Tests XMLEventReader
67f6158279d8 8204329: Java API doc for XMLStreamReader.next() needs to be clarified for the exception thrown when hasNext() method returns false
joehw
parents:
diff changeset
    40
 */
67f6158279d8 8204329: Java API doc for XMLStreamReader.next() needs to be clarified for the exception thrown when hasNext() method returns false
joehw
parents:
diff changeset
    41
@Listeners({jaxp.library.BasePolicy.class})
67f6158279d8 8204329: Java API doc for XMLStreamReader.next() needs to be clarified for the exception thrown when hasNext() method returns false
joehw
parents:
diff changeset
    42
public class EventReaderTest {
67f6158279d8 8204329: Java API doc for XMLStreamReader.next() needs to be clarified for the exception thrown when hasNext() method returns false
joehw
parents:
diff changeset
    43
    @Test(expectedExceptions = NoSuchElementException.class)
67f6158279d8 8204329: Java API doc for XMLStreamReader.next() needs to be clarified for the exception thrown when hasNext() method returns false
joehw
parents:
diff changeset
    44
    public void testNextEvent() throws Exception {
67f6158279d8 8204329: Java API doc for XMLStreamReader.next() needs to be clarified for the exception thrown when hasNext() method returns false
joehw
parents:
diff changeset
    45
        XMLEventReader eventReader = XMLInputFactory.newFactory().createXMLEventReader(
67f6158279d8 8204329: Java API doc for XMLStreamReader.next() needs to be clarified for the exception thrown when hasNext() method returns false
joehw
parents:
diff changeset
    46
                new StringReader("<?xml version='1.0'?><foo/>"));
67f6158279d8 8204329: Java API doc for XMLStreamReader.next() needs to be clarified for the exception thrown when hasNext() method returns false
joehw
parents:
diff changeset
    47
67f6158279d8 8204329: Java API doc for XMLStreamReader.next() needs to be clarified for the exception thrown when hasNext() method returns false
joehw
parents:
diff changeset
    48
        while (eventReader.hasNext()) {
67f6158279d8 8204329: Java API doc for XMLStreamReader.next() needs to be clarified for the exception thrown when hasNext() method returns false
joehw
parents:
diff changeset
    49
            eventReader.nextEvent();
67f6158279d8 8204329: Java API doc for XMLStreamReader.next() needs to be clarified for the exception thrown when hasNext() method returns false
joehw
parents:
diff changeset
    50
        }
67f6158279d8 8204329: Java API doc for XMLStreamReader.next() needs to be clarified for the exception thrown when hasNext() method returns false
joehw
parents:
diff changeset
    51
        // no more event
67f6158279d8 8204329: Java API doc for XMLStreamReader.next() needs to be clarified for the exception thrown when hasNext() method returns false
joehw
parents:
diff changeset
    52
        eventReader.nextEvent();
67f6158279d8 8204329: Java API doc for XMLStreamReader.next() needs to be clarified for the exception thrown when hasNext() method returns false
joehw
parents:
diff changeset
    53
    }
67f6158279d8 8204329: Java API doc for XMLStreamReader.next() needs to be clarified for the exception thrown when hasNext() method returns false
joehw
parents:
diff changeset
    54
}