### Question:
InputStreamDescriptionFactory { @SuppressWarnings("unchecked") public List<InputStreamDescription> createInputStreamDescriptions(Class<?> componentClass) { List<InputStreamDescription> inputStreamDescriptions = new ArrayList<>(); Set<Field> inputStreamFields = getAllFields(componentClass, withAnnotation(InputStream.class)); for (Field inputStreamField : inputStreamFields) { if (inputStreamField.getType() != Stream.class) { throw new IllegalArgumentException(InputStream.class + " can only be applied to " + Stream.class); } InputStreamDescription inputStreamDescription = createInputStreamDescription(componentClass, inputStreamField); inputStreamDescriptions.add(inputStreamDescription); } return inputStreamDescriptions; }  @SuppressWarnings("unchecked") List<InputStreamDescription> createInputStreamDescriptions(Class<?> componentClass);  }### Answer:
@Test public void should_retrieve_input_stream_descriptions() { @Documentation(name = "Test component") class TestComponent implements Component { @InputStream(name = "in1") private Stream in1; @ListMapper(stream = "in1") private ListedFeaturesMapper in1Mapper; @InputStream(name = "in2", mandatory = false) private Stream in2; @NameMapper(stream = "in2", expectedFeatures = {}) private ListedFeaturesMapper in2Mapper; @Override public void init() { } } List<FeatureDescription> expectedFeatures = new ArrayList<>(); when(featureDescriptorFactory.createDescriptions(isA(NameMapper.class))).thenReturn(expectedFeatures); List<InputStreamDescription> actualDescriptions = factory.createInputStreamDescriptions(TestComponent.class); assertThat(actualDescriptions).containsOnly( new InputStreamDescription("in1", LISTED), new InputStreamDescription("in2", NAMED, expectedFeatures, false) ); }
@Test(expected = IllegalArgumentException.class) public void should_throw_illegal_argument_exception_when_input_stream_annotation_not_applied_on_stream() { @Documentation(name = "Test component") class TestComponent implements Component { @InputStream(name = "in") private Object in; @ListMapper(stream = "in") private ListedFeaturesMapper inMapper; @Override public void init() { } } factory.createInputStreamDescriptions(TestComponent.class); }
@Test public void should_retrieve_inherited_input_stream_descriptions() { @Documentation(name = "Test component") class AbstractTestComponent implements Component { @InputStream(name = "in1") private Stream in1; @ListMapper(stream = "in1") private ListedFeaturesMapper in1Mapper; @InputStream(name = "in2") private Stream in2; @NameMapper(stream = "in2", expectedFeatures = {}) private ListedFeaturesMapper in2Mapper; @Override public void init() { } } class TestComponent extends AbstractTestComponent { } List<FeatureDescription> expectedFeatures = new ArrayList<>(); when(featureDescriptorFactory.createDescriptions(isA(NameMapper.class))).thenReturn(expectedFeatures); List<InputStreamDescription> actualDescriptions = factory.createInputStreamDescriptions(TestComponent.class); assertThat(actualDescriptions).containsOnly( new InputStreamDescription("in1", LISTED), new InputStreamDescription("in2", NAMED, expectedFeatures) ); }