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);  }
@Test(expectedExceptions = DescriptorCannotBeParsedException.class) public final void testBuildStubDescriptorShouldThrowExceptionWhenDocumentBuildingFails() throws Exception { given(xmlDocumentBuilder.buildDocument(inputStream, schema)).willThrow(documentBuilderException); underTest.buildStubDescriptor(inputStream); }
@Test public final void testBuildStubDescriptorShouldCallUpdaterInitialize() throws Exception { given(xmlDocumentBuilder.buildDocument(inputStream, schema)).willReturn(document); given(descriptorBuilder.parse(document)).willReturn(stubDescriptor); underTest.buildStubDescriptor(inputStream); verify(stubResourceHolderUpdater).initializeTemporaryResourceHolder(); }
@Test public final void testBuildStubDescriptorShouldCallUpdaterUpdateResourceHolder() throws Exception { given(xmlDocumentBuilder.buildDocument(inputStream, schema)).willReturn(document); given(descriptorBuilder.parse(document)).willReturn(stubDescriptor); underTest.buildStubDescriptor(inputStream); verify(stubResourceHolderUpdater).updateResourceHolder(); }
@Test public final void testBuildStubDescriptorShouldCallUpdaterClearTempResourceHolder() throws Exception { given(xmlDocumentBuilder.buildDocument(inputStream, schema)).willReturn(document); given(descriptorBuilder.parse(document)).willReturn(stubDescriptor); underTest.buildStubDescriptor(inputStream); verify(stubResourceHolderUpdater).clearTemporaryResourceHolder(); }
@Test public final void testBuildStubDescriptorShouldCallStubConfigurationAccess() throws Exception { given(xmlDocumentBuilder.buildDocument(inputStream, schema)).willReturn(document); given(descriptorBuilder.parse(document)).willReturn(stubDescriptor); underTest.buildStubDescriptor(inputStream); verify(configurationAccess).setProperties(); }