DefaultValidator extends AbstractValidator { public void add(Message message) { if (message instanceof I18nMessage && !((I18nMessage) message).hasBundle()) { ((I18nMessage) message).setLazyBundle(new LocalizationSupplier()); } errors.add(message); } DefaultValidator(); @Inject  DefaultValidator(Result result, ValidationViewsFactory factory, Outjector outjector, Proxifier proxifier, BeanValidator beanValidator, Localization localization); void checking(Validations validations); void validate(Object object, Class<?>... groups); void validateProperties(Object object, String... properties); void validateProperty(Object object, String property, Class<?>... groups); T onErrorUse(Class<T> view); void addAll(Collection<? extends Message> messages); void add(Message message); boolean hasErrors(); List<Message> getErrors();  }
@Test public void outjectsTheRequestParameters() { try { validator.add(A_MESSAGE); validator.onErrorForwardTo(MyComponent.class).logic(); } catch (ValidationException e) { } verify(outjector).outjectRequestMap(); }
@Test public void addsTheErrorsOnTheResult() { try { validator.add(A_MESSAGE); validator.onErrorForwardTo(MyComponent.class).logic(); } catch (ValidationException e) { } verify(result).include(eq("errors"), argThat(is(not(empty())))); }
@Test public void forwardToCustomOnErrorPage() { try { when(logicResult.forwardTo(MyComponent.class)).thenReturn(instance); validator.add(A_MESSAGE); validator.onErrorForwardTo(MyComponent.class).logic(); fail("should stop flow"); } catch (ValidationException e) { verify(instance).logic(); } }
@Test public void shouldSetBundleOnI18nMessagesLazily() throws Exception { I18nMessage message = new I18nMessage("cat", "msg"); when(localization.getBundle()).thenThrow(new AssertionError("should only call this method when calling I18nMessage's methods")); validator.add(message); doReturn(new SingletonResourceBundle("msg", "hoooooray!")).when(localization).getBundle(); assertThat(message.getMessage(), is("hoooooray!")); }
@Test public void shouldOnlySetBundleOnI18nMessagesThatHasNotBeenSetBefore() throws Exception { I18nMessage message = mock(I18nMessage.class); when(message.hasBundle()).thenReturn(true); validator.add(message); verify(message, never()).setBundle(any(ResourceBundle.class)); }