MatchableEntityWithSimilarityConverter implements Serializable { public Tuple2<String, Reference> convertToReference(Tuple2<MatchableEntity, IdWithSimilarity> entityWithId) { Preconditions.checkNotNull(entityWithId); Preconditions.checkNotNull(entityWithId._1()); Preconditions.checkNotNull(entityWithId._2()); MatchableEntity citation = entityWithId._1(); CitEntityId citEntityId = CitEntityId.fromString(citation.id()); DocEntityId destDocId = DocEntityId.fromString(entityWithId._2().getId()); Reference.Builder referenceB = Reference.newBuilder(); referenceB.setDocId(destDocId.documentId()); referenceB.setRefNum(citEntityId.position()); if (citation.rawText().isDefined()) { referenceB.setRawText(citation.rawText().get()); } return new Tuple2<>(citEntityId.sourceDocumentId(), referenceB.build()); }  Tuple2<String, Reference> convertToReference(Tuple2<MatchableEntity, IdWithSimilarity> entityWithId);  }
@Test(expectedExceptions=NullPointerException.class) public void convertToReference_NULL() { matchableEntityWithSimilarityConverter.convertToReference(null); }
@Test(expectedExceptions=NullPointerException.class) public void convertToReference_NULL_idWithSimilarity() { MatchableEntity entity = Mockito.mock(MatchableEntity.class); Tuple2<MatchableEntity, IdWithSimilarity> entityWithId = new Tuple2<>(entity, null); matchableEntityWithSimilarityConverter.convertToReference(entityWithId); }
@Test(expectedExceptions=NullPointerException.class) public void convertToReference_NULL_matchableEntity() { IdWithSimilarity idWithSimilarity = Mockito.mock(IdWithSimilarity.class); Tuple2<MatchableEntity, IdWithSimilarity> entityWithId = new Tuple2<>(null, idWithSimilarity); matchableEntityWithSimilarityConverter.convertToReference(entityWithId); }
@Test public void convertToReference() { String destDocId = "doc_ABC"; IdWithSimilarity idWithSimilarity = new IdWithSimilarity(destDocId, 13.4d); MatchableEntityData entityData = MatchableEntityData .newBuilder() .setRawText("RAW_TEXT") .setId("cit_QW1233_12") .build(); MatchableEntity entity = new MatchableEntity(entityData); Tuple2<MatchableEntity, IdWithSimilarity> entityWithId = new Tuple2<>(entity, idWithSimilarity); Tuple2<String, Reference> docIdReference = matchableEntityWithSimilarityConverter.convertToReference(entityWithId); assertEquals(docIdReference._1(), "QW1233"); assertEquals(docIdReference._2().getDocId(), "ABC"); assertEquals(docIdReference._2().getRawText(), "RAW_TEXT"); assertEquals(docIdReference._2().getRefNum(), 12); }