### Question:
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);  }### Answer:
@Test public void testSkipElement() throws XMLStreamException { final List<String> localNames = new ArrayList<String>(); localNames.add("myLocalName1"); localNames.add("myLocalName2"); localNames.add("myLocalName2"); localNames.add("myLocalName1"); final List<Integer> eventTypes = new ArrayList<Integer>(); eventTypes.add(XMLStreamConstants.START_ELEMENT); eventTypes.add(XMLStreamConstants.CHARACTERS); eventTypes.add(XMLStreamConstants.END_ELEMENT); eventTypes.add(XMLStreamConstants.END_ELEMENT); when(mockReader.hasNext()).thenReturn(true); when(mockReader.getEventType()).thenAnswer(new Answer<Integer>() { @Override public Integer answer(InvocationOnMock invocation) throws Throwable { return eventTypes.remove(0); } }); when(mockReader.getLocalName()).thenAnswer(new Answer<String>() { @Override public String answer(InvocationOnMock invocation) throws Throwable { return localNames.remove(0); } }); XmiReader.skipElement(mockReader, false); }
@Test(expected = AssertionError.class) public void testSkipElementSadPath2NoNext() throws XMLStreamException { when(mockReader.hasNext()).thenReturn(false); XmiReader.skipElement(mockReader, false); }
@Test(expected = AssertionError.class) public void testSkipElementSadPath3UnknownEventType() throws XMLStreamException { when(mockReader.hasNext()).thenReturn(true); when(mockReader.getEventType()).thenReturn(123456789); XmiReader.skipElement(mockReader, false); }
@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); }