### Question:
StellaNITValidator implements Validator, StateHolder { public void validate(FacesContext facesContext, UIComponent uiComponent, Object value) throws ValidatorException { ResourceBundle bundle = resourceBundleFinder.getForCurrentLocale(facesContext); ResourceBundleMessageProducer producer = new ResourceBundleMessageProducer(bundle); NITValidator validator = new NITValidator(producer, formatted); try { validator.assertValid(value.toString()); } catch (InvalidStateException e) { List<ValidationMessage> messages = e.getInvalidMessages(); String firstErrorMessage = messages.remove(0).getMessage(); registerAllMessages(facesContext, uiComponent, messages); throw new ValidatorException(new FacesMessage(firstErrorMessage)); } }  void setFormatted(boolean formatted); void validate(FacesContext facesContext, UIComponent uiComponent, Object value); void restoreState(FacesContext ctx, Object state); Object saveState(FacesContext ctx); boolean isTransient(); void setTransient(boolean transientValue); static final String VALIDATOR_ID; }### Answer:
@Test public void shouldNotThrowValidatorExceptionForValidNIT() throws Exception { final FacesContext context = mockery.mock(FacesContext.class); final UIComponent component = mockery.mock(UIComponent.class); facesContextMocker.mockMessageBundle(context, "messages", Locale.getDefault()); validator.validate(context, component, "34608514300"); mockery.assertIsSatisfied(); }
@Test public void shouldGiveMessagesFromBrazilianResourceBundleForInvalidNITAndPtBRLocale() throws Exception { final FacesContext context = mockery.mock(FacesContext.class); final UIComponent component = mockery.mock(UIComponent.class); facesContextMocker.mockMessageBundle(context, "messages", new Locale("pt", "BR")); try { validator.validate(context, component, "1234567765"); fail(); } catch (ValidatorException e) { FacesMessage message = e.getFacesMessage(); assertEquals("NIT Invalido", message.getSummary()); mockery.assertIsSatisfied(); } }
@Test public void shouldGiveMessagesFromDefaultResourceBundleForInvalidNITAndEnUSLocale() throws Exception { final FacesContext context = mockery.mock(FacesContext.class); final UIComponent component = mockery.mock(UIComponent.class); facesContextMocker.mockMessageBundle(context, "messages", new Locale("en")); try { validator.validate(context, component, "1234567765"); fail(); } catch (ValidatorException e) { FacesMessage message = e.getFacesMessage(); assertEquals("Invalid NIT", message.getSummary()); mockery.assertIsSatisfied(); } }