BELDocumentConverter extends BELConverter<BELDocument, Document> { @Override public Document convert(BELDocument bd) { if (bd == null) { return null; } final Header header = dhc.convert(bd.getDocumentHeader()); Set<BELAnnotationDefinition> badlist = bd.getAnnotationDefinitions(); List<AnnotationDefinition> adlist = null; if (badlist != null) { adlist = sizedArrayList(badlist.size()); if (hasItems(badlist)) { for (BELAnnotationDefinition bad : badlist) { adlist.add(badc.convert(bad)); } } } Set<BELNamespaceDefinition> bndlist = bd.getNamespaceDefinitions(); NamespaceGroup nsgroup = null; if (bndlist != null) { nsgroup = new NamespaceGroup(); if (hasItems(bndlist)) { List<Namespace> nslist = new ArrayList<Namespace>(); for (BELNamespaceDefinition bnd : bndlist) { if (bnd.isNsDefault()) { nsgroup.setDefaultResourceLocation(bnd .getResourceLocation()); } else { nslist.add(bndc.convert(bnd)); } } nsgroup.setNamespaces(nslist); } } final BELStatementGroupConverter sgc = new BELStatementGroupConverter( getNamespaceMap(nsgroup), getDefinitionMap(adlist)); List<StatementGroup> statementGroups = new ArrayList<StatementGroup>(); for (BELStatementGroup bsg : bd.getBelStatementGroups()) { statementGroups.add(sgc.convert(bsg)); } return new Document(header, statementGroups, nsgroup, adlist); }  @Override Document convert(BELDocument bd); @Override BELDocument convert(Document d); Map<String, AnnotationDefinition> getDefinitionMap(
            final List<AnnotationDefinition> definitions);  }
@Test public void testNamespaceGroupConversion() { final BELDocumentHeader dh = new BELDocumentHeader("Unit Test", "Unit Test", "1.0"); final Set<BELNamespaceDefinition> nsset = constrainedHashSet(2); nsset.add(new BELNamespaceDefinition("HGNC", DEFAULT_NS, true)); nsset.add(new BELNamespaceDefinition("EGID", NS, false)); final List<BELStatementGroup> sglist = sizedArrayList(1); final BELStatementGroup sg = new BELStatementGroup("Example"); sg.getStatements().add(new BELStatement("p(AKT1) => g(EGID:1024)")); sglist.add(sg); final BELDocument beldoc = new BELDocument(dh, null, nsset, sglist); final BELDocumentConverter converter = new BELDocumentConverter(); final Document doc = converter.convert(beldoc); final NamespaceGroup nsgroup = doc.getNamespaceGroup(); assertThat("More than one custom namespace exists.", nsgroup .getNamespaces().size(), is(1)); assertThat("The custom namespace does not match.", nsgroup .getNamespaces().get(0).getResourceLocation(), is(NS)); assertThat("The default namespace does not match.", nsgroup.getDefaultResourceLocation(), is(DEFAULT_NS)); }