GlobalDistributionBuilder { public Set<NewDocumentType> build(ModelElement documentsElement) { if (documentsElement == null || documentsElement.subElements("document").isEmpty()) return Collections.emptySet(); return documentsElement.subElements("document") .stream() .filter(GlobalDistributionBuilder::isGloballyDistributed) .map(GlobalDistributionBuilder::getDocumentName) .map(this::getDocumentType) .collect(toSet()); } GlobalDistributionBuilder(Map<String, NewDocumentType> documentDefinitions); Set<NewDocumentType> build(ModelElement documentsElement);  }
@Test public void global_documents_are_identified() { GlobalDistributionBuilder builder = new GlobalDistributionBuilder(createDocumentDefinitions()); String documentsElement = "<documents>" + " <document type=\"" + NON_GLOBAL_EXPLICIT.getName() + "\" global=\"false\"/>" + " <document type=\"" + GLOBAL_1.getName() + "\" global=\"true\"/>" + " <document type=\"" + NON_GLOBAL_IMPLICIT.getName() + "\"/>" + " <document type=\"" + GLOBAL_2.getName() + "\" global=\"true\"/>" + "</documents>"; Set<NewDocumentType> expectedResult = new HashSet<>(Arrays.asList(GLOBAL_1, GLOBAL_2)); Set<NewDocumentType> actualResult = builder.build(new ModelElement(XML.getDocument(documentsElement).getDocumentElement())); assertEquals(expectedResult, actualResult); }