GetRecordsResponse { public Iterator<MetadataRecord> getRecords() { return new Iterator<MetadataRecord>() { @Override public boolean hasNext() { return recordElementName != null && xmlStream.isStartElement() && recordElementName.equals( xmlStream.getLocalName() ); } @Override public MetadataRecord next() { if ( !hasNext() ) { throw new NoSuchElementException(); } try { MetadataRecord record = MetadataRecordFactory.create( xmlStream ); return record; } finally { try { nextElement( xmlStream ); } catch ( XMLStreamException e ) { throw new XMLParsingException( xmlStream, e.getMessage() ); } } } @Override public void remove() { throw new UnsupportedOperationException(); } }; } GetRecordsResponse( OwsHttpResponse response ); OwsHttpResponse getResponse(); Iterator<MetadataRecord> getRecords(); int getNumberOfRecordsMatched(); int getNumberOfRecordsReturned(); int getNextRecord(); void close();  }
@Test public void testGeoNetworksResponse() throws XMLStreamException, FactoryConfigurationError, OWSExceptionReport { OwsHttpResponseImpl mock = Mockito.mock( OwsHttpResponseImpl.class ); XMLStreamReader xmlStream = getExampleResponseReader( "geonetworks_response.invalid" ); Mockito.when( mock.getAsXMLStream() ).thenReturn( xmlStream ); GetRecordsResponse response = new GetRecordsResponse( mock ); Iterator<MetadataRecord> iter = response.getRecords(); int i = 0; while ( iter.hasNext() ) { assertTrue( xmlStream.isStartElement() ); assertEquals( ISO_RECORD_NS, xmlStream.getNamespaceURI() ); assertEquals( "MD_Metadata", xmlStream.getLocalName() ); ISORecord isoRecord = null; isoRecord = (ISORecord) iter.next(); assertNotNull( isoRecord.getIdentifier() ); i++; } assertEquals( 10, i ); }