GenericCitationCollapser extends AbstractSimpleCollapser<Citation> { @Override public void setup(TaskAttemptContext context) { totalTextCounter = context.getCounter(CitationTextCounters.TOTAL); totalTextCounter.setValue(0); docsWithAtLeastOneCitationTextCounter = context.getCounter(CitationTextCounters.DOCS_WITH_AT_LEAST_ONE_CITATION); docsWithAtLeastOneCitationTextCounter.setValue(0); totalMatchedCounter = context.getCounter(MatchedCitationCounters.TOTAL); totalMatchedCounter.setValue(0); docsWithAtLeastOneMatchedCitationCounter = context.getCounter(MatchedCitationCounters.DOCS_WITH_AT_LEAST_ONE_CITATION); docsWithAtLeastOneMatchedCitationCounter.setValue(0); }  @Override void setup(TaskAttemptContext context);  }
@Test public void testSetup() throws Exception { collapser.setup(context); verify(totalTextCounter).setValue(0); verify(docsWithAtLeastOneCitationTextCounter).setValue(0); }
@Test public void testCollapseNull() throws Exception { collapser.setup(context); List<Citation> result = collapser.collapse(null); assertNull(result); }
@Test public void testCollapseEmpty() throws Exception { collapser.setup(context); List<Citation> result = collapser.collapse(Collections.emptyList()); assertNull(result); }
@Test public void testCollapseEmptyTextOnly() throws Exception { collapser.setup(context); List<Citation> source = new ArrayList<>(); String citationText = ""; source.add(buildCitationWithText(1, citationText)); List<Citation> result = collapser.collapse(source); assertNotNull(result); assertEquals(1, result.size()); assertEquals(1, result.get(0).getEntry().getPosition().intValue()); assertEquals(citationText, result.get(0).getEntry().getRawText()); verify(totalTextCounter, never()).increment(1); verify(docsWithAtLeastOneCitationTextCounter, never()).increment(1); verify(totalMatchedCounter, never()).increment(1); verify(docsWithAtLeastOneMatchedCitationCounter, never()).increment(1); }
@Test public void testCollapseTextOnly() throws Exception { collapser.setup(context); List<Citation> source = new ArrayList<>(); String citation1Text = "citation text"; String citation1OtherText = "citation new text"; String citation2Text = "some other text"; source.add(buildCitationWithText(1, citation1Text)); source.add(buildCitationWithText(1, citation1OtherText)); source.add(buildCitationWithText(2, citation2Text)); List<Citation> result = collapser.collapse(source); assertNotNull(result); assertEquals(2, result.size()); assertEquals(1, result.get(0).getEntry().getPosition().intValue()); assertEquals(citation1OtherText, result.get(0).getEntry().getRawText()); assertEquals(2, result.get(1).getEntry().getPosition().intValue()); assertEquals(citation2Text, result.get(1).getEntry().getRawText()); verify(totalTextCounter, times(1)).increment(2); verify(docsWithAtLeastOneCitationTextCounter, times(1)).increment(1); verify(totalMatchedCounter, never()).increment(1); verify(docsWithAtLeastOneMatchedCitationCounter, never()).increment(1); }
@Test public void testCollapseMultipleFields() throws Exception { collapser.setup(context); String citationText = "citation text"; String destId = "destId"; List<Citation> source = new ArrayList<>(); source.add(buildCitationWithText(1, citationText)); source.add(buildCitationWithDestId(1, destId, 0.8f)); String doiType = "doi"; String doiValue = "1234"; Map<CharSequence, CharSequence> externalIds1 = new HashMap<>(); externalIds1.put(doiType, doiValue); source.add(buildCitationWithExternalIds(1, externalIds1, null)); String pmidType = "pmid"; String pmidValue = "6789"; String doiValue2 = "12345"; Map<CharSequence, CharSequence> externalIds2 = new HashMap<>(); externalIds2.put(pmidType, pmidValue); externalIds2.put(doiType, doiValue2); source.add(buildCitationWithExternalIds(1, externalIds2, 0.7f)); List<Citation> result = collapser.collapse(source); assertNotNull(result); assertEquals(1, result.size()); assertEquals(1, result.get(0).getEntry().getPosition().intValue()); assertEquals(citationText, result.get(0).getEntry().getRawText()); assertEquals(destId, result.get(0).getEntry().getDestinationDocumentId()); assertEquals(2, result.get(0).getEntry().getExternalDestinationDocumentIds().size()); assertEquals(doiValue2, result.get(0).getEntry().getExternalDestinationDocumentIds().get(doiType)); assertEquals(pmidValue, result.get(0).getEntry().getExternalDestinationDocumentIds().get(pmidType)); assertEquals(0.8f, result.get(0).getEntry().getConfidenceLevel().floatValue(), 0.0001); verify(totalTextCounter, times(1)).increment(1); verify(docsWithAtLeastOneCitationTextCounter, times(1)).increment(1); verify(totalMatchedCounter, times(1)).increment(1); verify(docsWithAtLeastOneMatchedCitationCounter, times(1)).increment(1); }