blob: d9001c0a7eb8015f0fe096099f1867de22cc42ce [file] [log] [blame]
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.axiom.truth.xml;
import static com.google.common.truth.Truth.assertThat;
import java.io.StringReader;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamReader;
import org.apache.axiom.truth.xml.spi.Event;
import org.apache.axiom.truth.xml.spi.Traverser;
import org.junit.Test;
public class StAXTraverserTest {
@Test
public void testFragment() throws Exception {
XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(
new StringReader("<root><a><b/></a></root>"));
reader.next();
reader.next();
Traverser t = new StAXTraverser(reader);
assertThat(t.next()).isEqualTo(Event.START_ELEMENT);
assertThat(t.getQName()).isEqualTo(new QName("a"));
assertThat(t.next()).isEqualTo(Event.START_ELEMENT);
assertThat(t.getQName()).isEqualTo(new QName("b"));
assertThat(t.next()).isEqualTo(Event.END_ELEMENT);
assertThat(t.next()).isEqualTo(Event.END_ELEMENT);
assertThat(t.next()).isNull();
}
}