ReferenceMetadataConverter implements Serializable { public List<Tuple2<String, MatchableEntity>> convertToMatchableEntities(Iterator<Tuple2<String, ReferenceMetadata>> docIdReferenceIterator) { Preconditions.checkNotNull(docIdReferenceIterator); List<Tuple2<String, MatchableEntity>> matchableEntities = Lists.newArrayList(); while (docIdReferenceIterator.hasNext()) { Tuple2<String, ReferenceMetadata> docIdReference = docIdReferenceIterator.next(); MatchableEntity matchableEntity = rawReferenceToEntityConverter.convert(new CitEntityId(docIdReference._1(), docIdReference._2().getPosition()), docIdReference._2().getRawCitationText()); matchableEntities.add(new Tuple2<>(matchableEntity.id(), matchableEntity)); } return matchableEntities; }  List<Tuple2<String, MatchableEntity>> convertToMatchableEntities(Iterator<Tuple2<String, ReferenceMetadata>> docIdReferenceIterator); void setRawReferenceToEntityConverter(RawReferenceToEntityConverter rawReferenceToEntityConverter);  }
@Test public void convertToMatchableEntities() { ReferenceMetadata ref1 = createReference("XXX"); ReferenceMetadata ref2 = createReference("YYY"); String doc1 = "DOC!"; Tuple2<String, ReferenceMetadata> refTuple1 = new Tuple2<>(doc1, ref1); Tuple2<String, ReferenceMetadata> refTuple2 = new Tuple2<>(doc1, ref2); List<Tuple2<String, ReferenceMetadata>> references = Lists.newArrayList(); references.add(refTuple1); references.add(refTuple2); MatchableEntity entity1 = Mockito.mock(MatchableEntity.class); when(entity1.id()).thenReturn("1"); MatchableEntity entity2 = Mockito.mock(MatchableEntity.class); when(entity2.id()).thenReturn("2"); when(rawReferenceToEntityConverter.convert(new CitEntityId(doc1, ref1.getPosition()), ref1.getRawCitationText())).thenReturn(entity1); when(rawReferenceToEntityConverter.convert(new CitEntityId(doc1, ref2.getPosition()), ref2.getRawCitationText())).thenReturn(entity2); List<Tuple2<String, MatchableEntity>> docIdEntities = referenceMetadataConverter.convertToMatchableEntities(references.iterator()); assertEquals(2, docIdEntities.size()); assertTrue(docIdEntities.get(0)._2() == entity1); assertEquals(docIdEntities.get(0)._1(), "1"); assertTrue(docIdEntities.get(1)._2() == entity2); assertEquals(docIdEntities.get(1)._1(), "2"); }