@Test public void validInputShouldPassRepeated() throws Exception { SimpleModelUnderValidation model = new SimpleModelUnderValidation(Robolectric.application); model.txtAmount.setText("10"); model.editMessage.setText("0123456789"); boolean result = FormValidator.validate(Robolectric.application, model, null); assertTrue(result); TestValidationCallback callback = new TestValidationCallback(0, 2); result = FormValidator.validate(Robolectric.application, model, callback); assertTrue(result); }
@Test public void testTrimmedInput() { final SimpleModelUnderValidation model = new SimpleModelUnderValidation(Robolectric.application); model.txtAmount.setText(" "); model.editMessage.setText("0123456789"); final boolean[] called = new boolean[1]; boolean result = FormValidator.validate( Robolectric.application, model, new IValidationCallback() { @Override public void validationComplete( boolean result, List<FormValidator.ValidationFail> failedValidations, List<View> passedValidations) { called[0] = true; assertEquals(1, failedValidations.size()); assertEquals(1, passedValidations.size()); assertEquals(model.txtAmount, failedValidations.get(0).view); } }); assertTrue(called[0]); assertFalse(result); }
@Test public void invalidMinValueInputShouldNotPass() throws Exception { SimpleModelUnderValidation model = new SimpleModelUnderValidation(Robolectric.application); model.txtAmount.setText("0"); model.editMessage.setText("0123456789"); TestValidationCallback callback = new TestValidationCallback(1, 1); boolean result = FormValidator.validate(Robolectric.application, model, callback); assertFalse(result); }
@Test public void emptyInputShouldNotPass() throws Exception { SimpleModelUnderValidation model = new SimpleModelUnderValidation(Robolectric.application); model.txtAmount.setText(""); model.editMessage.setText(null); TestValidationCallback callback = new TestValidationCallback(2, 0); boolean result = FormValidator.validate(Robolectric.application, model, callback); assertFalse(result); assertTrue(callback.called); }
@Test public void invalidValueOnInvisibleFieldShouldPass() { SimpleModelUnderValidation model = new SimpleModelUnderValidation(Robolectric.application); model.txtAmount.setText(""); model.editMessage.setText("0123456789"); model.txtAmount.setVisibility(View.GONE); TestValidationCallback callback = new TestValidationCallback(0, 1); boolean result = FormValidator.validate(Robolectric.application, model, callback); assertTrue(result); }
private void onSaveButtonClicked() { if (FormValidator.validate(this, new SimpleErrorPopupCallback(this))) { AddAnnouncementParams params = new AddAnnouncementParams( titleEdit.getText().toString(), contentEdit.getText().toString(), anonymousCheckBox.isChecked(), new RequestParams(LoginActivity.accountName)); String paramsJson = gson.toJson(params); try { RoomiesRestClient.postJson(this, "announcements/add", paramsJson); } catch (UnsupportedEncodingException e) { CoreUtils.logWebServiceConnectionError(ADD_ANNOUNCEMENT_ACTIVITY_TAG, e); } } }