Descriptions { public Collection<DescriptionsBySource> getBySource() { if(descriptionsBySource == null) { descriptionsBySource = new ArrayList<>(); if(taxon.looksAccepted()) { partitionBySource(taxon); for(Taxon synonym : taxon.getSynonymNameUsages()) { partitionBySource(synonym); } Collections.sort(descriptionsBySource); } } return descriptionsBySource; } Descriptions(Taxon taxon);  Descriptions(Taxon taxon, boolean isUses); @JsonSerialize(contentUsing = BaseSerializer.class) List<Taxon> getSynonymsIncluded(); Collection<DescriptionsBySource> getBySource();  }
@Test public void testBySource() { Description d2 = new Description(); Description d3 = new Description(); Organisation o2 = new Organisation(); o2.setAbbreviation("FTEA"); o2.setTitle("Flora of Tropical East Africa"); d1.setType(DescriptionType.morphologyGeneralHabit); d1.setId(1L); d1.setDescription("Perenial herb"); d2.setType(DescriptionType.morphologyLeaf); d2.setId(3L); d2.setDescription("Basal leaves"); d2.setAuthority(o1); d3.setType(DescriptionType.morphologyReproductiveFlower); d3.setId(2L); d3.setDescription("Large"); d3.setAuthority(o2); taxon.setDescriptions(ImmutableSet.<Description>of(d1, d2, d3)); Descriptions ds = new Descriptions(taxon); Collection<DescriptionsBySource> dbs = ds.getBySource(); assertEquals(2, dbs.size()); List<String> abbreviations = new ArrayList<>(); for(DescriptionsBySource d : dbs) { abbreviations.add(d.source.getAbbreviation()); } assertThat(abbreviations, containsInAnyOrder("FWTA", "FTEA")); }
@Test public void testMultiTypeDescriptions() { d1.setTypes(ImmutableSortedSet.<DescriptionType>of(useAnimalFoodBees, morphologyReproductiveFlower)); d1.setDescription("BEES!!!"); taxon.setDescriptions(ImmutableSet.<Description>of(d1)); Descriptions uses = new Descriptions(taxon, true); for(DescriptionsBySource dbs : uses.getBySource()) { for(DescriptionsByType dbt : dbs.byType) { assertEquals("useAnimalFoodBees", dbt.type); } } Descriptions desc = new Descriptions(taxon); assertEquals(0, desc.getBySource().size()); }
@Test public void testSynonymDescriptions() { Description d2 = new Description(); Taxon synonym = new Taxon(); synonym.setScientificName("Eucalypton"); synonym.setTaxonomicStatus(TaxonomicStatus.Synonym); d1.setType(DescriptionType.morphologyGeneral); d1.setDescription("accepted description"); d2.setAuthority(o1); d2.setType(DescriptionType.morphologyGeneralHabit); d2.setDescription("synonym description"); synonym.setDescriptions(ImmutableSet.<Description>of(d2)); taxon.setDescriptions(ImmutableSet.<Description>of(d1)); taxon.setSynonymNameUsages(ImmutableSet.<Taxon>of(synonym)); Descriptions ds = new Descriptions(taxon); for(DescriptionsBySource dbs : ds.getBySource()) { if(dbs.asTaxon.getScientificName().equals("Eucalypton")) { assertEquals(d2, dbs.byType.get(0).descriptions.get(0)); } else { assertEquals(d1, dbs.byType.get(0).descriptions.get(0)); } } }
@Test public void testOrderingByDescriptionId() { Description d2 = new Description(); Description d3 = new Description(); d1.setType(DescriptionType.morphologyGeneralHabit); d1.setId(1L); d1.setDescription("Perenial herb"); d2.setType(DescriptionType.morphologyLeaf); d2.setId(3L); d2.setDescription("Basal leaves"); d2.setAuthority(o1); d3.setType(DescriptionType.morphologyReproductiveFlower); d3.setId(2L); d3.setDescription("Large"); d3.setAuthority(o1); taxon.setDescriptions(ImmutableSet.<Description>of(d1, d2, d3)); Descriptions ds = new Descriptions(taxon); print(ds); DescriptionsBySource dbs = Iterators.getOnlyElement(ds.getBySource().iterator()); assertEquals(d1.getType().toString(), dbs.byType.get(0).type); assertEquals(d3.getType().toString(), dbs.byType.get(1).type); assertEquals(d2.getType().toString(), dbs.byType.get(2).type); }