### Question:
ComponentDescriptionFactory { public ComponentDescription createDescription(Class<? extends Component> componentClass) { checkArgument(componentClass != null, "Component class is mandatory"); Documentation documentation = componentClass.getAnnotation(Documentation.class); checkArgument(documentation != null, "No documentation found for " + componentClass + " but documentation is mandatory!"); ComponentDescription description = new ComponentDescription(componentClass, documentation.name(), documentation.description(), documentation.type()); description.addProperties(propertyDescriptionFactory.createPropertyDescriptions(componentClass)); description.addInputStreams(inputStreamDescriptionFactory.createInputStreamDescriptions(componentClass)); description.addOutputStreams(outputStreamDescriptionFactory.createOutputStreamDescriptions(componentClass)); description.addStates(stateDescriptionFactory.createDescriptions(componentClass)); description.ensureNoDuplicatedInputStreams(); description.ensureOutputStreamReference(); description.ensureNoDuplicatedOutputStreams(); description.ensureNoDuplicatedProperties(); description.ensureNoDuplicatedStateName(); return description; }  ComponentDescription createDescription(Class<? extends Component> componentClass);  }### Answer:
@Test(expected = IllegalArgumentException.class) public void should_throw_illegal_argument_exception_when_no_component_class() { factory.createDescription(null); }
@Test(expected = IllegalArgumentException.class) public void should_throw_illegal_argument_exception_when_no_component_documentation() { class TestComponent implements Component { @Override public void init() { } } factory.createDescription(TestComponent.class); }
@Test public void should_retrieve_name() { @Documentation(name = "Test component") class TestComponent implements Component { @Override public void init() { } } ComponentDescription actualDescription = factory.createDescription(TestComponent.class); assertThat(actualDescription.getName()).isEqualTo("Test component"); }
@Test public void should_retrieve_description() { @Documentation(name = "Test component", description = "Only for test purpose") class TestComponent implements Component { @Override public void init() { } } ComponentDescription actualDescription = factory.createDescription(TestComponent.class); assertThat(actualDescription.getDescription()).isEqualTo("Only for test purpose"); }
@Test public void should_retrieve_empty_description_when_no_declared_description() { @Documentation(name = "Test component") class TestComponent implements Component { @Override public void init() { } } ComponentDescription actualDescription = factory.createDescription(TestComponent.class); assertThat(actualDescription.getDescription()).isEmpty(); }
@Test public void should_retrieve_component_type() { @Documentation(name = "Test component", type = STREAM_SOURCE) class TestComponent implements Component { @Override public void init() { } } ComponentDescription actualDescription = factory.createDescription(TestComponent.class); assertThat(actualDescription.getType()).isEqualTo(ComponentType.STREAM_SOURCE); }
@Test public void should_retrieve_no_type() { @Documentation(name = "Test component") class TestComponent implements Component { @Override public void init() { } } ComponentDescription actualDescription = factory.createDescription(TestComponent.class); assertThat(actualDescription.getType()).isEqualTo(ComponentType.NO_TYPE); }
@Test public void should_retrieve_class() { @Documentation(name = "Test component") class TestComponent implements Component { @Override public void init() { } } ComponentDescription actualDescription = factory.createDescription(TestComponent.class); assertThat(actualDescription.getClazz()).isEqualTo(TestComponent.class); }
@Test(expected = IllegalArgumentException.class) public void should_fail_with_duplicated_state_names() { @Documentation(name = "Test component") class TestComponent implements Component { @State(name = "word count") private StateFactory stateFactory1; @State(name = "word count") private StateFactory stateFactory2; @Override public void init() { } } List<ReferencedStateDescription> expectedStateDescriptions = asList(new ReferencedStateDescription("word count"), new ReferencedStateDescription("word count")); given(stateDescriptionFactory.createDescriptions(TestComponent.class)).willReturn(expectedStateDescriptions ); factory.createDescription(TestComponent.class); }