Skip to content

Commit

Permalink
Removing validate/validateProperty/validateProperties methods. Closes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
garcia-jj committed Sep 21, 2013
1 parent d0c24f1 commit fcd5254
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 145 deletions.
31 changes: 0 additions & 31 deletions vraptor-core/src/main/java/br/com/caelum/vraptor/Validator.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,37 +38,6 @@ public interface Validator {
*/
Validator check(boolean expression, Message message);


/**
* Validate an object using some Bean Validation engine. If the object is null,
* the validation will be skipped.
*
* @param object The object to be validated.
* @param groups The groups to be validated.
* @since vraptor3.1.2
*/
void validate(Object object, Class<?>... groups);

/**
* Validate the specifics propeties of an object using some Bean Validation engine. If the object is null,
* the validation will be skipped.
*
* @param object The object to be validated.
* @param properties The names of properties to be validated.
*/
void validateProperties(Object object, String... properties);


/**
* Validate the specific property of an object using some Bean Validation engine. If the object is null,
* the validation will be skipped.
*
* @param object The object to be validated.
* @param property The name of property to be validated.
* @param groups The groups to be validated.
*/
void validateProperty(Object object, String property, Class<?>... groups);

/**
* If validator has errors, you can use this method to define what to do. WARN: this method don't stop the flow.
* @param view
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,6 @@ public Validator check(boolean condition, Message message) {
return this;
}

@Override
public void validate(Object object, Class<?>... groups) {
}

@Override
public void validateProperties(Object object, String... properties) {
}

@Override
public void validateProperty(Object object, String property, Class<?>... groups) {
}

@Override
public <T extends View> T onErrorUse(Class<T> view) {
if(!this.errors.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public class DefaultValidator extends AbstractValidator {
private Result result;
private List<Message> errors = new ArrayList<>();
private ValidationViewsFactory viewsFactory;
private BeanValidator beanValidator;
private Outjector outjector;
private Proxifier proxifier;
private Localization localization;
Expand All @@ -62,12 +61,11 @@ public DefaultValidator() {
}

@Inject
public DefaultValidator(Result result, ValidationViewsFactory factory, Outjector outjector, Proxifier proxifier, BeanValidator beanValidator, Localization localization) {
public DefaultValidator(Result result, ValidationViewsFactory factory, Outjector outjector, Proxifier proxifier, Localization localization) {
this.result = result;
this.viewsFactory = factory;
this.outjector = outjector;
this.proxifier = proxifier;
this.beanValidator = beanValidator;
this.localization = localization;
}

Expand All @@ -80,21 +78,6 @@ public Validator check(boolean condition, Message message) {
return this;
}

@Override
public void validate(Object object, Class<?>... groups) {
addAll(beanValidator.validate(object, groups));
}

@Override
public void validateProperties(Object object, String... properties) {
addAll(beanValidator.validateProperties(object, properties));
}

@Override
public void validateProperty(Object object, String property, Class<?>... groups) {
addAll(beanValidator.validateProperty(object, property, groups));
}

@Override
public <T extends View> T onErrorUse(Class<T> view) {
if (!hasErrors()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.ResourceBundle;

import org.junit.Before;
Expand Down Expand Up @@ -73,7 +71,7 @@ public class DefaultValidatorTest {
@Before
public void setup() {
Proxifier proxifier = new JavassistProxifier(new ObjenesisInstanceCreator());
this.validator = new DefaultValidator(result, new DefaultValidationViewsFactory(result, proxifier), outjector, proxifier, beanValidator, localization);
this.validator = new DefaultValidator(result, new DefaultValidationViewsFactory(result, proxifier), outjector, proxifier, localization);
when(result.use(LogicResult.class)).thenReturn(logicResult);
when(result.use(PageResult.class)).thenReturn(pageResult);
when(logicResult.forwardTo(MyComponent.class)).thenReturn(instance);
Expand Down Expand Up @@ -124,34 +122,6 @@ public void shouldNotRedirectIfHasNotErrors() {
}
}

@Test
public void shouldAddBeanValidatorErrorsIfPossible() {
List<Message> messages = new ArrayList<>();

when(beanValidator.validate(any())).thenReturn(messages);
validator.validate(new Object());
assertThat(validator.getErrors(), hasSize(0));

messages.add(new ValidationMessage("", ""));
when(beanValidator.validate(any())).thenReturn(messages);
validator.validate(new Object());
assertThat(validator.getErrors(), hasSize(1));
}

@Test
public void shouldAddBeanValidatorErrorsIfPossibleForSpecificProperties() {
List<Message> messages = new ArrayList<>();

when(beanValidator.validateProperties(any())).thenReturn(messages);
validator.validateProperties(new Object());
assertThat(validator.getErrors(), hasSize(0));

messages.add(new ValidationMessage("", ""));
when(beanValidator.validateProperties(any())).thenReturn(messages);
validator.validateProperties(new Object());
assertThat(validator.getErrors(), hasSize(1));
}

@Test
public void testThatValidatorGoToRedirectsToTheErrorPageImmediatellyAndNotBeforeThis() {
try {
Expand Down Expand Up @@ -209,15 +179,15 @@ public void doNothingIfCheckingSuccess() {
Client c = new Client();
c.name = "The name";

validator.check(c.name == null, new ValidationMessage("not null", "client.name"));
validator.check(c.name != null, new ValidationMessage("not null", "client.name"));
assertThat(validator.getErrors(), hasSize(0));
}

@Test
public void shouldAddMessageIfCheckingFails() {
Client c = new Client();

validator.check(c.name == null, new ValidationMessage("not null", "client.name"));
validator.check(c.name != null, new ValidationMessage("not null", "client.name"));
assertThat(validator.getErrors(), hasSize(1));
assertThat(validator.getErrors().get(0).getMessage(), containsString("not null"));
}
Expand Down

0 comments on commit fcd5254

Please sign in to comment.