GlobalDistributionValidator { public void validate(Map<String, NewDocumentType> documentDefinitions, Set<NewDocumentType> globallyDistributedDocuments) { verifyReferredDocumentsArePresent(documentDefinitions); verifyReferredDocumentsAreGlobal(documentDefinitions, globallyDistributedDocuments); }  void validate(Map<String, NewDocumentType> documentDefinitions,
                         Set<NewDocumentType> globallyDistributedDocuments);  }
@Test public void validation_succeeds_on_no_documents() { new GlobalDistributionValidator() .validate(emptyMap(), emptySet()); }
@Test public void validation_succeeds_on_no_global_documents() { Fixture fixture = new Fixture() .addNonGlobalDocument(createDocumentType("foo")); validate(fixture); }
@Test public void throws_exception_if_referenced_document_not_global() { NewDocumentType parent = createDocumentType("parent"); Fixture fixture = new Fixture() .addNonGlobalDocument(parent) .addNonGlobalDocument(createDocumentType("child", parent)); exceptionRule.expect(IllegalArgumentException.class); exceptionRule.expectMessage( "The following document types are referenced from other documents, but are not globally distributed: 'parent'"); validate(fixture); }
@Test public void validation_succeeds_if_referenced_document_is_global() { NewDocumentType parent = createDocumentType("parent"); Fixture fixture = new Fixture() .addGlobalDocument(parent) .addNonGlobalDocument(createDocumentType("child", parent)); validate(fixture); }
@Test public void throws_exception_on_unknown_document() { NewDocumentType unknown = new NewDocumentType(new NewDocumentType.Name("unknown")); NewDocumentType child = createDocumentType("child", unknown); Fixture fixture = new Fixture() .addNonGlobalDocument(child); exceptionRule.expect(IllegalArgumentException.class); exceptionRule.expectMessage( "The following document types are referenced from other documents, but are not listed in services.xml: 'unknown'"); validate(fixture); }