AffiliationConverter implements Serializable { public List<AffMatchAffiliation> convert(ExtractedDocumentMetadata document) { Preconditions.checkNotNull(document); Preconditions.checkArgument(StringUtils.isNotBlank(document.getId())); List<AffMatchAffiliation> affMatchAffiliations = new ArrayList<>(); if (CollectionUtils.isEmpty(document.getAffiliations())) { return affMatchAffiliations; } for (int i = 0; i < document.getAffiliations().size(); i++) { Affiliation srcAffiliation = document.getAffiliations().get(i); if (isAuthorAffiliation(i, document.getAuthors())) { affMatchAffiliations.add(convertAffiliation(document.getId(), i + 1, srcAffiliation)); } } return affMatchAffiliations; }  List<AffMatchAffiliation> convert(ExtractedDocumentMetadata document);  }
@Test(expected = NullPointerException.class) public void convert_null_document() { converter.convert(null); }
@Test(expected = IllegalArgumentException.class) public void convert_blank_organization_id() { ExtractedDocumentMetadata document = new ExtractedDocumentMetadata(); document.setId(null); converter.convert(document); }
@Test public void convert_null_affiliations() { ExtractedDocumentMetadata document = new ExtractedDocumentMetadata(); document.setId("xxx"); assertNull(document.getAffiliations()); List<AffMatchAffiliation> affMatchAffiliations = converter.convert(document); assertNotNull(affMatchAffiliations); assertTrue(affMatchAffiliations.size() == 0); }
@Test public void convert_empty_affiliations() { ExtractedDocumentMetadata document = new ExtractedDocumentMetadata(); document.setId("ABC"); document.setAffiliations(new ArrayList<>()); List<AffMatchAffiliation> affMatchAffiliations = converter.convert(document); assertNotNull(affMatchAffiliations); assertTrue(affMatchAffiliations.size() == 0); }
@Test public void convert_null_aff_properties() { ExtractedDocumentMetadata document = new ExtractedDocumentMetadata(); document.setId("XYZ"); Affiliation aff1 = createAffiliation(null, null, null); List<Affiliation> affiliations = Lists.newArrayList(aff1); document.setAffiliations(affiliations); document.setAuthors(Lists.newArrayList(createAuthor("author1", 0))); List<AffMatchAffiliation> affMatchAffiliations = converter.convert(document); assertNotNull(affMatchAffiliations); assertAffiliation(affMatchAffiliations.get(0), "XYZ", 1, "", "", ""); }
@Test public void convert() { ExtractedDocumentMetadata document = new ExtractedDocumentMetadata(); document.setId("XYZ"); Affiliation aff1 = createAffiliation("ABC", "PL", "Poland"); Affiliation aff2 = createAffiliation("DEF", "DE", "Deutschland"); Affiliation aff3 = createAffiliation("GHI", "SL", "Slovakia"); List<Affiliation> affiliations = Lists.newArrayList(aff1, aff2, aff3); document.setAffiliations(affiliations); document.setAuthors(Lists.newArrayList(createAuthor("author1", 0), createAuthor("author2", 1))); List<AffMatchAffiliation> affMatchAffiliations = converter.convert(document); assertNotNull(affMatchAffiliations); assertEquals(2, affMatchAffiliations.size()); assertAffiliation(affMatchAffiliations.get(0), "XYZ", 1, "ABC", "Poland", "PL"); assertAffiliation(affMatchAffiliations.get(1), "XYZ", 2, "DEF", "Deutschland", "DE"); }