@Test
void testBuilder() {

  TermId rootId = TermId.of("owl:Thing");
  Term root = Term.of(rootId, "root");
  TermId childId = TermId.of("HP:0000001");
  Term child = Term.of(childId, "child");
  TermId child2Id = TermId.of("HP:0000002");
  Term child2 = Term.of(child2Id, "child2");
  TermId child3Id = TermId.of("HP:0000003");
  TermId child3SecondaryId = TermId.of("HP:3333333");
  Term child3 = Term.builder()
    .id(child3Id)
    .name("child3")
    .altTermIds(ImmutableList.of(child3SecondaryId))
    .build();
  TermId obsoleteId = TermId.of("HP:0000004");
  Term obsolete = Term.builder().id(obsoleteId).name("obsolete").obsolete(true).build();
  ImmutableList<Term> terms = ImmutableList.of(root, child, child2, child3, obsolete);
  Relationship relationship1 = new Relationship(childId, rootId, 1, RelationshipType.IS_A);
  Relationship relationship2 = new Relationship(child2Id, rootId, 2, RelationshipType.IS_A);
  Relationship relationship3 = new Relationship(child3Id, child2Id, 3, RelationshipType.IS_A);
  Relationship relationship4 = new Relationship(childId, obsoleteId, 4, RelationshipType.IS_A);
  ImmutableList<Relationship> relationships = ImmutableList.of(relationship1, relationship2, relationship3, relationship4);
  Ontology instance = ImmutableOntology.builder()
    .terms(terms)
    .relationships(relationships)
    .build();
  assertEquals(rootId, instance.getRootTermId());
  assertTrue(instance.isRootTerm(rootId));
  Set<TermId> allTermIds = terms.stream().map(Term::getId).collect(Collectors.toSet());
  assertEquals(allTermIds, instance.getAllTermIds());
  Set<TermId> nonObsoleteTermIds = terms.stream()
    .filter(term -> !term.isObsolete())
    .map(Term::getId)
    .collect(Collectors.toSet());
  assertEquals(nonObsoleteTermIds, instance.getNonObsoleteTermIds());
  assertEquals(child3Id, instance.getPrimaryTermId(child3Id));
  assertEquals(child3Id, instance.getPrimaryTermId(child3SecondaryId));
  assertEquals(ImmutableSet.of(rootId), instance.getParentTermIds(child2Id));
  assertEquals(ImmutableSet.of(child2Id), instance.getParentTermIds(child3Id));
  assertEquals(ImmutableSet.of(child3Id, child2Id, rootId), instance.getAncestorTermIds(child3Id));
  assertEquals(ImmutableSet.of(child3Id, child2Id), instance.getAncestorTermIds(child3Id, false));
}