@Test
public void convertToMatchableEntities() {

    
    // given
    
    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);
    
    
    // execute
    
    List<Tuple2<String, MatchableEntity>> docIdEntities = referenceMetadataConverter.convertToMatchableEntities(references.iterator());
    
    // assert
    
    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");
}