NewStubDescriptorCommand implements StubDescriptorModificationCommand { @Override public Map<String, StubDescriptor> modify(final Map<String, StubDescriptor> stubDescriptors) { Map<String, StubDescriptor> updated = new LinkedHashMap<>(stubDescriptors); StubDescriptor stubDescriptor = stubConfigurationJsonBuilder.buildStubDescriptor(inputStream); StubDescriptorAttributes attributes = stubDescriptor.getAttributes(); String groupName = attributes.getGroupName(); sequenceDescriptorHolder.addAllSequenceDescriptors(stubDescriptor); updated.put(groupName, stubDescriptor); if (!attributes.isValid()) { updated.remove(groupName); } return updated; } NewStubDescriptorCommand(final InputStream inputStream, final StubDescriptorJsonFactory stubConfigurationJsonBuilder,
                                    final SequenceDescriptorHolder sequenceDescriptorHolder); @Override Map<String, StubDescriptor> modify(final Map<String, StubDescriptor> stubDescriptors);  }
@Test public void testModifyShouldPutANewStubDescriptorIntoTheMap() { Map<String, StubDescriptor> expected = new LinkedHashMap<>(normalStubDescriptors); expected.put(GROUPNAME_FIRST, stubDescriptor); given(stubDescriptor.getAttributes()).willReturn(attributes); given(attributes.getGroupName()).willReturn(GROUPNAME_FIRST); given(attributes.isValid()).willReturn(true); underTest = new NewStubDescriptorCommand(inputStream, stubConfigurationJsonBuilder, sequenceDescriptorHolder); Map<String, StubDescriptor> result = underTest.modify(normalStubDescriptors); Assert.assertEquals(result, expected); }
@Test public void testModifyShouldReplaceOneStubDescriptor() { normalStubDescriptors.put(GROUPNAME_FIRST, stubDescriptor); Map<String, StubDescriptor> expected = new LinkedHashMap<>(normalStubDescriptors); given(stubDescriptor.getAttributes()).willReturn(attributes); given(attributes.getGroupName()).willReturn(GROUPNAME_FIRST); given(attributes.isValid()).willReturn(true); underTest = new NewStubDescriptorCommand(inputStream, stubConfigurationJsonBuilder, sequenceDescriptorHolder); Map<String, StubDescriptor> result = underTest.modify(normalStubDescriptors); Assert.assertEquals(result, expected); }
@Test public void testModifyShouldAddSequenceDescriptorsToSequenceDescriptorHolder() { underTest = new NewStubDescriptorCommand(inputStream, stubConfigurationJsonBuilder, sequenceDescriptorHolder); underTest.modify(normalStubDescriptors); verify(sequenceDescriptorHolder).addAllSequenceDescriptors(stubDescriptor); }