Skip to content

Commit

Permalink
Add type parameter for Accept/Reject-all validators
Browse files Browse the repository at this point in the history
  • Loading branch information
iay committed Oct 3, 2017
1 parent b16ab8e commit 23ffd04
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@
* A {@link Validator} which accepts any value, returning
* {@link net.shibboleth.metadata.validate.Validator.Action#DONE}
* to terminate any validator sequence.
*
* @param <V> type of the object to be validated
*/
public class AcceptAllValidator extends BaseValidator implements Validator<Object> {
public class AcceptAllValidator<V> extends BaseValidator implements Validator<V> {

@Override
public Action validate(@Nonnull final Object e, @Nonnull final Item<?> item, @Nonnull final String stageId) {
public Action validate(@Nonnull final V e, @Nonnull final Item<?> item, @Nonnull final String stageId) {
return Action.DONE;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@
*
* An error status is added using the value of the given property as a format string.
* The message defaults to a simple rejection message including the object's string value.
*
* @param <V> type of the object to be validated
*/
public class RejectAllValidator extends BaseValidator implements Validator<Object> {
public class RejectAllValidator<V> extends BaseValidator implements Validator<V> {

/**
* Message format string.
Expand Down Expand Up @@ -66,7 +68,7 @@ public void setMessage(@Nonnull final String newMessage) {
}

@Override
public Action validate(@Nonnull final Object e, @Nonnull final Item<?> item, @Nonnull final String stageId) {
public Action validate(@Nonnull final V e, @Nonnull final Item<?> item, @Nonnull final String stageId) {
final String mess = String.format(message, e);
addError(mess, item, stageId);
return Action.DONE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class AcceptAllValidatorTest {

@Test
public void validate() throws Exception {
final AcceptAllValidator v = new AcceptAllValidator();
final AcceptAllValidator<String> v = new AcceptAllValidator<>();
v.setId("comp");
v.initialize();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class RejectAllValidatorTest {

@Test
public void validate() throws Exception {
final RejectAllValidator v = new RejectAllValidator();
final RejectAllValidator<String> v = new RejectAllValidator<>();
v.setId("comp");
v.initialize();

Expand All @@ -34,7 +34,7 @@ public void validate() throws Exception {

@Test
public void validateWithMessage() throws Exception {
final RejectAllValidator v = new RejectAllValidator();
final RejectAllValidator<Double> v = new RejectAllValidator<>();
v.setId("comp");
v.setMessage("decimal %.2f");
v.initialize();
Expand Down

0 comments on commit 23ffd04

Please sign in to comment.