3536373839404142
public Reply<?> onError(List<Exception> exceptions) { return onErrorBuilder(exceptions).reply(); } public Reply<?> onSuccess(T pojo) { return new FormResponseBuilder() .reply(); }
404142434445464748
return new FormResponseBuilder() .reply(); } public Reply<?> onSuccess(T pojo, String url) { return new FormResponseBuilder() .redirectTo(url) .reply(); }
4647484950515253545556575859
.redirectTo(url) .reply(); } private FormResponseBuilder onErrorBuilder(List<Exception> exceptions) { FormResponseBuilder builder = new FormResponseBuilder(); for (Exception exception : exceptions) { String message = exception.getMessage(); builder.addMessage(message); } return builder; }
3233343536373839404142
*/ @Test public class FormResponseBuilderTest { public void default_response() { FormResponse res = new FormResponseBuilder() .get(); assertThat(res.isValid(), equalTo(true)); List<Error> errors = res.getErrors();
4445464748495051525354
assertThat(res.getRedirectUrl(), nullValue()); } public void invalid_response() { FormResponse res = new FormResponseBuilder() .addMessage("a").toField("f") .get();
6364656667686970717273
assertThat(res.getRedirectUrl(), nullValue()); } public void redirect_url() { FormResponse res = new FormResponseBuilder() .redirectTo("http://localhost/whatever") .get();
7374757677787980818283
assertThat(res.getRedirectUrl(), equalTo("http://localhost/whatever")); } public void form_message() { FormResponse res = new FormResponseBuilder() .addMessage("a").toForm() .get();
90919293949596979899100
assertThat(e0.getName(), nullValue()); assertThat(e0.getMessage(), equalTo("a")); } public void form_message_template() { FormResponse res = new FormResponseBuilder() .addMessage("%s:%d", "a", Integer.valueOf(1)).toField("f") .get();