### Question:
DefaultComponentInfo implements ComponentInfo { public boolean isValid() { for (UIComponent component : this.components) { if (!isValid(component)) { return false; } } return true; } DefaultComponentInfo(FacesContext context, List<UIComponent> components); UIComponent getComponent(); List<UIComponent> getComponents(); boolean isValid(); boolean isRequired(); String getLabel(); String getFor();  }### Answer:
@Test public void shouldBeValidIfAllValid() throws Exception { List<UIComponent> components = createComponents(4); for (UIComponent component : components) { given(((EditableValueHolder) component).isValid()).willReturn(true); } components.add(2, mock(UIComponent.class)); given(this.context.getMessages(anyString())).willReturn(EMPTY_MESSAGES); ComponentInfo info = new DefaultComponentInfo(this.context, components); assertThat(info.isValid(), is(true)); }
@Test public void shouldNotBeValidIfAnyAreNotValid() throws Exception { List<UIComponent> components = createComponents(3); for (int i = 0; i < components.size(); i++) { UIComponent component = components.get(i); given(((EditableValueHolder) component).isValid()).willReturn(i == components.size() - 1); } components.add(2, mock(UIComponent.class)); given(this.context.getMessages(anyString())).willReturn(EMPTY_MESSAGES); ComponentInfo info = new DefaultComponentInfo(this.context, components); assertThat(info.isValid(), is(false)); }
@Test public void shouldNotBeValidIfHasWarningFacesMessage() throws Exception { List<UIComponent> components = createComponentWithFacesMessage(FacesMessage.SEVERITY_WARN); ComponentInfo info = new DefaultComponentInfo(this.context, components); assertThat(info.isValid(), is(false)); }
@Test public void shouldBeValidIfHasInfoFacesMessage() throws Exception { List<UIComponent> components = createComponentWithFacesMessage(FacesMessage.SEVERITY_INFO); ComponentInfo info = new DefaultComponentInfo(this.context, components); assertThat(info.isValid(), is(true)); }