@Test(expected = AssertionError.class) public void testSkipElementSadPath4LocalNamesDoNotMatch() throws XMLStreamException { final List<String> localNames = new ArrayList<String>(); localNames.add("myLocalName1"); localNames.add("myLocalName2"); localNames.add("myLocalName2"); when(mockReader.hasNext()).thenReturn(true); when(mockReader.getEventType()).thenReturn(XMLStreamConstants.END_ELEMENT); when(mockReader.getLocalName()).thenAnswer(new Answer<String>() { @Override public String answer(InvocationOnMock invocation) throws Throwable { return localNames.remove(0); } }); XmiReader.skipElement(mockReader, false); }
protected static final void skipElement(final XMLStreamReader reader, final boolean check) throws XMLStreamException { if (check) { throw new AssertionError(reader.getName()); } final String localName = reader.getLocalName(); while (reader.hasNext()) { reader.next(); switch (reader.getEventType()) { case XMLStreamConstants.START_ELEMENT: { skipElement(reader, check); break; } case XMLStreamConstants.END_ELEMENT: { if (localName.equals(reader.getLocalName())) { return; } else { throw new AssertionError(reader.getLocalName()); } } case XMLStreamConstants.CHARACTERS: { break; } default: { throw new AssertionError(reader.getEventType()); } } } throw new AssertionError(); }
XmiReader { protected static final void skipElement(final XMLStreamReader reader, final boolean check) throws XMLStreamException { if (check) { throw new AssertionError(reader.getName()); } final String localName = reader.getLocalName(); while (reader.hasNext()) { reader.next(); switch (reader.getEventType()) { case XMLStreamConstants.START_ELEMENT: { skipElement(reader, check); break; } case XMLStreamConstants.END_ELEMENT: { if (localName.equals(reader.getLocalName())) { return; } else { throw new AssertionError(reader.getLocalName()); } } case XMLStreamConstants.CHARACTERS: { break; } default: { throw new AssertionError(reader.getEventType()); } } } throw new AssertionError(); } }
XmiReader { protected static final void skipElement(final XMLStreamReader reader, final boolean check) throws XMLStreamException { if (check) { throw new AssertionError(reader.getName()); } final String localName = reader.getLocalName(); while (reader.hasNext()) { reader.next(); switch (reader.getEventType()) { case XMLStreamConstants.START_ELEMENT: { skipElement(reader, check); break; } case XMLStreamConstants.END_ELEMENT: { if (localName.equals(reader.getLocalName())) { return; } else { throw new AssertionError(reader.getLocalName()); } } case XMLStreamConstants.CHARACTERS: { break; } default: { throw new AssertionError(reader.getEventType()); } } } throw new AssertionError(); }  }
XmiReader { protected static final void skipElement(final XMLStreamReader reader, final boolean check) throws XMLStreamException { if (check) { throw new AssertionError(reader.getName()); } final String localName = reader.getLocalName(); while (reader.hasNext()) { reader.next(); switch (reader.getEventType()) { case XMLStreamConstants.START_ELEMENT: { skipElement(reader, check); break; } case XMLStreamConstants.END_ELEMENT: { if (localName.equals(reader.getLocalName())) { return; } else { throw new AssertionError(reader.getLocalName()); } } case XMLStreamConstants.CHARACTERS: { break; } default: { throw new AssertionError(reader.getEventType()); } } } throw new AssertionError(); }  static final Model readModel(final File file); static final Model readModel(final InputStream stream); static final Model readModel(final String fileName); }
XmiReader { protected static final void skipElement(final XMLStreamReader reader, final boolean check) throws XMLStreamException { if (check) { throw new AssertionError(reader.getName()); } final String localName = reader.getLocalName(); while (reader.hasNext()) { reader.next(); switch (reader.getEventType()) { case XMLStreamConstants.START_ELEMENT: { skipElement(reader, check); break; } case XMLStreamConstants.END_ELEMENT: { if (localName.equals(reader.getLocalName())) { return; } else { throw new AssertionError(reader.getLocalName()); } } case XMLStreamConstants.CHARACTERS: { break; } default: { throw new AssertionError(reader.getEventType()); } } } throw new AssertionError(); }  static final Model readModel(final File file); static final Model readModel(final InputStream stream); static final Model readModel(final String fileName);  }