@Test(expectedExceptions = DescriptorCannotBeParsedException.class) public final void testBuildStubDescriptorShouldThrowExceptionWhenDocumentBuildingFails() throws Exception { given(xmlDocumentBuilder.buildDocument(inputStream, schema)).willThrow(documentBuilderException); underTest.buildStubDescriptor(inputStream); }
@Override public synchronized StubDescriptor buildStubDescriptor(final InputStream inputStream) { try { Document document = xmlDocumentBuilder.buildDocument(inputStream, stubConfigSchema.getSchema()); validate(document); stubResourceHolderUpdater.initializeTemporaryResourceHolder(); configurationAccess.setProperties(); StubDescriptor stubDescriptor = descriptorParser.parse(document); stubResourceHolderUpdater.updateResourceHolder(); stubResourceHolderUpdater.clearTemporaryResourceHolder(); StubDescriptorAttributes attributes = stubDescriptor.getAttributes(); stubResourceHolderUpdater.addDocumentToResourceHolder(attributes.getGroupName(), document); return stubDescriptor; } catch (DocumentBuilderException e) { throw new DescriptorCannotBeParsedException("Stub descriptor cannot be parsed.", e); } }
DomBasedStubDescriptorFactory implements StubDescriptorFactory { @Override public synchronized StubDescriptor buildStubDescriptor(final InputStream inputStream) { try { Document document = xmlDocumentBuilder.buildDocument(inputStream, stubConfigSchema.getSchema()); validate(document); stubResourceHolderUpdater.initializeTemporaryResourceHolder(); configurationAccess.setProperties(); StubDescriptor stubDescriptor = descriptorParser.parse(document); stubResourceHolderUpdater.updateResourceHolder(); stubResourceHolderUpdater.clearTemporaryResourceHolder(); StubDescriptorAttributes attributes = stubDescriptor.getAttributes(); stubResourceHolderUpdater.addDocumentToResourceHolder(attributes.getGroupName(), document); return stubDescriptor; } catch (DocumentBuilderException e) { throw new DescriptorCannotBeParsedException("Stub descriptor cannot be parsed.", e); } } }
DomBasedStubDescriptorFactory implements StubDescriptorFactory { @Override public synchronized StubDescriptor buildStubDescriptor(final InputStream inputStream) { try { Document document = xmlDocumentBuilder.buildDocument(inputStream, stubConfigSchema.getSchema()); validate(document); stubResourceHolderUpdater.initializeTemporaryResourceHolder(); configurationAccess.setProperties(); StubDescriptor stubDescriptor = descriptorParser.parse(document); stubResourceHolderUpdater.updateResourceHolder(); stubResourceHolderUpdater.clearTemporaryResourceHolder(); StubDescriptorAttributes attributes = stubDescriptor.getAttributes(); stubResourceHolderUpdater.addDocumentToResourceHolder(attributes.getGroupName(), document); return stubDescriptor; } catch (DocumentBuilderException e) { throw new DescriptorCannotBeParsedException("Stub descriptor cannot be parsed.", e); } }  }
DomBasedStubDescriptorFactory implements StubDescriptorFactory { @Override public synchronized StubDescriptor buildStubDescriptor(final InputStream inputStream) { try { Document document = xmlDocumentBuilder.buildDocument(inputStream, stubConfigSchema.getSchema()); validate(document); stubResourceHolderUpdater.initializeTemporaryResourceHolder(); configurationAccess.setProperties(); StubDescriptor stubDescriptor = descriptorParser.parse(document); stubResourceHolderUpdater.updateResourceHolder(); stubResourceHolderUpdater.clearTemporaryResourceHolder(); StubDescriptorAttributes attributes = stubDescriptor.getAttributes(); stubResourceHolderUpdater.addDocumentToResourceHolder(attributes.getGroupName(), document); return stubDescriptor; } catch (DocumentBuilderException e) { throw new DescriptorCannotBeParsedException("Stub descriptor cannot be parsed.", e); } }  @Override synchronized StubDescriptor buildStubDescriptor(final InputStream inputStream); }
DomBasedStubDescriptorFactory implements StubDescriptorFactory { @Override public synchronized StubDescriptor buildStubDescriptor(final InputStream inputStream) { try { Document document = xmlDocumentBuilder.buildDocument(inputStream, stubConfigSchema.getSchema()); validate(document); stubResourceHolderUpdater.initializeTemporaryResourceHolder(); configurationAccess.setProperties(); StubDescriptor stubDescriptor = descriptorParser.parse(document); stubResourceHolderUpdater.updateResourceHolder(); stubResourceHolderUpdater.clearTemporaryResourceHolder(); StubDescriptorAttributes attributes = stubDescriptor.getAttributes(); stubResourceHolderUpdater.addDocumentToResourceHolder(attributes.getGroupName(), document); return stubDescriptor; } catch (DocumentBuilderException e) { throw new DescriptorCannotBeParsedException("Stub descriptor cannot be parsed.", e); } }  @Override synchronized StubDescriptor buildStubDescriptor(final InputStream inputStream);  }