// Path: src/main/java/immanix/matchers/NamedEndElementMatcher.java
// public class NamedEndElementMatcher extends BaseEventMatcher<EndElement> {
//     private final String namespaceURI;
//     private final String name;
// 
//     /**
//      * @param name the end element's name to match
//      */
//     public NamedEndElementMatcher(String name) {
//         this.name = name;
//         this.namespaceURI = null;
//     }
// 
//     /**
//      * @param namespaceURI the end element's namespace uri
//      * @param name         the end element's name to match
//      */
//     public NamedEndElementMatcher(String namespaceURI, String name) {
//         this.name = name;
//         this.namespaceURI = namespaceURI;
//     }
// 
//     @Override
//     protected boolean accept(XMLEvent e) {
//         if (e.isEndElement()) {
//             QName qName = e.asEndElement().getName();
//             return name.equals(qName.getLocalPart()) && (namespaceURI == null || namespaceURI.equals
//                     (qName.getNamespaceURI()));
//         }
//         return false;
//     }
// 
//     @Override
//     protected EndElement process(XMLEvent e) {
//         return e.asEndElement();
//     }
// 
//     @Override
//     protected String expects() {
//         return toString();
//     }
// 
//     @Override
//     public String toString() {
//         return "</" + (namespaceURI == null ? "" : "{" + namespaceURI + "}") + name + ">";
//     }
// 
// }
// 
// Path: src/main/java/immanix/readers/ReplayEventReader.java
// @SuppressWarnings("restriction")
// public class ReplayEventReader implements EventReader {
// 
//     private Iterator<? extends XMLEvent> events;
// 
//     public ReplayEventReader(List<? extends XMLEvent> events) {
//         super();
//         this.events = new ArrayList(events).iterator();
//     }
// 
//     public boolean hasNext() {
//         return events.hasNext();
//     }
// 
//     public XMLEvent next() throws XMLStreamException {
//         return events.next();
//     }
// 
//     public EventReader unwrap() {
//         return this;
//     }
// 
//     @Override
//     public String toString() {
//         return "Replayer";
//     }
// }
// 
// Path: src/test/java/immanix/utils/XMLEventsUtils.java
// public class XMLEventsUtils {
//     private static XMLEventFactory eventFactory = XMLEventFactory.newInstance();
// 
//     public static XMLEvent a(String name, String val) {
//         return eventFactory.createAttribute(name, val);
//     }
// 
//     public static XMLEvent c(String val) {
//         return eventFactory.createCharacters(val);
//     }
// 
//     public static XMLEvent se(String name) {
//         return eventFactory.createStartElement(new QName(name), null, null);
//     }
// 
//     public static XMLEvent se(String namespaceURI, String name) {
//         return eventFactory.createStartElement(new QName(namespaceURI, name), null, null);
//     }
// 
//     public static XMLEvent ee(String name) {
//         return eventFactory.createEndElement(new QName(name), null);
//     }
// 
//     public static XMLEvent ee(String namespaceURI, String name) {
//         return eventFactory.createEndElement(new QName(namespaceURI, name), null);
//     }
// 
//     public static List<XMLEvent> evts(XMLEvent... items) {
//         return Arrays.asList(items);
//     }
// 
//     public static List<XMLEvent> close(List<XMLEvent> start) {
//         List<XMLEvent> res = new ArrayList<XMLEvent>();
//         for (int i = start.size() - 1; i >= 0; i--) {
//             if (start.get(i).isStartElement()) {
//                 res.add(ee(start.get(i).asStartElement().getName()
//                         .getLocalPart()));
//             }
//         }
//         return res;
//     }
// }


import immanix.matchers.NamedEndElementMatcher;
import immanix.readers.ReplayEventReader;
import org.junit.Test;
import javax.xml.stream.events.EndElement;
import javax.xml.stream.events.XMLEvent;
import java.util.Arrays;
import java.util.List;
import static immanix.utils.XMLEventsUtils.*;
import static org.junit.Assert.*;

    @Test
    public void testFailureMatchBecauseOfDifferentNameWithNoNsXml() throws Exception {
        mustFail(new NamedEndElementMatcher("elem"), Arrays.<XMLEvent>asList(ee("42"), c("chars")));
    }

    @Test
    public void testFailureMatchBecauseOfDifferentNameWithNsXml() throws Exception {
        mustFail(new NamedEndElementMatcher("elem"), Arrays.<XMLEvent>asList(ee(NS, "42"), c("chars")));
    }

    @Test
    public void testFailureMatchBecauseOfNsWithNoNsXml() throws Exception {
        mustFail(new NamedEndElementMatcher(NS, "elem"), Arrays.<XMLEvent>asList(ee("elem"), c("chars")));
    }

    @Test
    public void testFailureMatchBecauseOfNsWithNsXml() throws Exception {
        mustFail(new NamedEndElementMatcher(NS, "elem"), Arrays.<XMLEvent>asList(ee(NS + "x",
                "elem"),
                c("chars")));
    }


    @Test
    public void testFailureMatchBecauseOfDifferentType() throws Exception {
        mustFail(new NamedEndElementMatcher("elem"), Arrays.<XMLEvent>asList(c("chars"), ee("42")));
    }

    private void mustFail(NamedEndElementMatcher m, List<XMLEvent> events) throws Exception {
// Path: src/main/java/immanix/matchers/NamedEndElementMatcher.java
// public class NamedEndElementMatcher extends BaseEventMatcher<EndElement> {
//     private final String namespaceURI;
//     private final String name;
// 
//     /**
//      * @param name the end element's name to match
//      */
//     public NamedEndElementMatcher(String name) {
//         this.name = name;
//         this.namespaceURI = null;
//     }
// 
//     /**
//      * @param namespaceURI the end element's namespace uri
//      * @param name         the end element's name to match
//      */
//     public NamedEndElementMatcher(String namespaceURI, String name) {
//         this.name = name;
//         this.namespaceURI = namespaceURI;
//     }
// 
//     @Override
//     protected boolean accept(XMLEvent e) {
//         if (e.isEndElement()) {
//             QName qName = e.asEndElement().getName();
//             return name.equals(qName.getLocalPart()) && (namespaceURI == null || namespaceURI.equals
//                     (qName.getNamespaceURI()));
//         }
//         return false;
//     }
// 
//     @Override
//     protected EndElement process(XMLEvent e) {
//         return e.asEndElement();
//     }
// 
//     @Override
//     protected String expects() {
//         return toString();
//     }
// 
//     @Override
//     public String toString() {
//         return "</" + (namespaceURI == null ? "" : "{" + namespaceURI + "}") + name + ">";
//     }
// 
// }
// 
// Path: src/main/java/immanix/readers/ReplayEventReader.java
// @SuppressWarnings("restriction")
// public class ReplayEventReader implements EventReader {
// 
//     private Iterator<? extends XMLEvent> events;
// 
//     public ReplayEventReader(List<? extends XMLEvent> events) {
//         super();
//         this.events = new ArrayList(events).iterator();
//     }
// 
//     public boolean hasNext() {
//         return events.hasNext();
//     }
// 
//     public XMLEvent next() throws XMLStreamException {
//         return events.next();
//     }
// 
//     public EventReader unwrap() {
//         return this;
//     }
// 
//     @Override
//     public String toString() {
//         return "Replayer";
//     }
// }
// 
// Path: src/test/java/immanix/utils/XMLEventsUtils.java
// public class XMLEventsUtils {
//     private static XMLEventFactory eventFactory = XMLEventFactory.newInstance();
// 
//     public static XMLEvent a(String name, String val) {
//         return eventFactory.createAttribute(name, val);
//     }
// 
//     public static XMLEvent c(String val) {
//         return eventFactory.createCharacters(val);
//     }
// 
//     public static XMLEvent se(String name) {
//         return eventFactory.createStartElement(new QName(name), null, null);
//     }
// 
//     public static XMLEvent se(String namespaceURI, String name) {
//         return eventFactory.createStartElement(new QName(namespaceURI, name), null, null);
//     }
// 
//     public static XMLEvent ee(String name) {
//         return eventFactory.createEndElement(new QName(name), null);
//     }
// 
//     public static XMLEvent ee(String namespaceURI, String name) {
//         return eventFactory.createEndElement(new QName(namespaceURI, name), null);
//     }
// 
//     public static List<XMLEvent> evts(XMLEvent... items) {
//         return Arrays.asList(items);
//     }
// 
//     public static List<XMLEvent> close(List<XMLEvent> start) {
//         List<XMLEvent> res = new ArrayList<XMLEvent>();
//         for (int i = start.size() - 1; i >= 0; i--) {
//             if (start.get(i).isStartElement()) {
//                 res.add(ee(start.get(i).asStartElement().getName()
//                         .getLocalPart()));
//             }
//         }
//         return res;
//     }
// }


// Path: src/test/java/immanix/NamedEndElementMatcherTest.java
import immanix.matchers.NamedEndElementMatcher;
import immanix.readers.ReplayEventReader;
import org.junit.Test;
import javax.xml.stream.events.EndElement;
import javax.xml.stream.events.XMLEvent;
import java.util.Arrays;
import java.util.List;
import static immanix.utils.XMLEventsUtils.*;
import static org.junit.Assert.*;


    @Test
    public void testFailureMatchBecauseOfDifferentNameWithNoNsXml() throws Exception {
        mustFail(new NamedEndElementMatcher("elem"), Arrays.<XMLEvent>asList(ee("42"), c("chars")));
    }

    @Test
    public void testFailureMatchBecauseOfDifferentNameWithNsXml() throws Exception {
        mustFail(new NamedEndElementMatcher("elem"), Arrays.<XMLEvent>asList(ee(NS, "42"), c("chars")));
    }

    @Test
    public void testFailureMatchBecauseOfNsWithNoNsXml() throws Exception {
        mustFail(new NamedEndElementMatcher(NS, "elem"), Arrays.<XMLEvent>asList(ee("elem"), c("chars")));
    }

    @Test
    public void testFailureMatchBecauseOfNsWithNsXml() throws Exception {
        mustFail(new NamedEndElementMatcher(NS, "elem"), Arrays.<XMLEvent>asList(ee(NS + "x",
                "elem"),
                c("chars")));
    }


    @Test
    public void testFailureMatchBecauseOfDifferentType() throws Exception {
        mustFail(new NamedEndElementMatcher("elem"), Arrays.<XMLEvent>asList(c("chars"), ee("42")));
    }

    private void mustFail(NamedEndElementMatcher m, List<XMLEvent> events) throws Exception {
        ReplayEventReader reader = new ReplayEventReader(events);