Skip to content

Commit c54f60e

Browse files
committed
Add missing test fixtures
1 parent 403a381 commit c54f60e

File tree

4 files changed

+107
-0
lines changed

4 files changed

+107
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* Copyright (c) 2013-2016, The SeedStack authors <http://seedstack.org>
3+
*
4+
* This Source Code Form is subject to the terms of the Mozilla Public
5+
* License, v. 2.0. If a copy of the MPL was not distributed with this
6+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
7+
*/
8+
package org.seedstack.validation.internal.custom;
9+
10+
public enum CaseMode {
11+
UPPER,
12+
LOWER;
13+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* Copyright (c) 2013-2016, The SeedStack authors <http://seedstack.org>
3+
*
4+
* This Source Code Form is subject to the terms of the Mozilla Public
5+
* License, v. 2.0. If a copy of the MPL was not distributed with this
6+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
7+
*/
8+
package org.seedstack.validation.internal.custom;
9+
10+
import javax.validation.Constraint;
11+
import javax.validation.Payload;
12+
import java.lang.annotation.Documented;
13+
import java.lang.annotation.Retention;
14+
import java.lang.annotation.Target;
15+
16+
import static java.lang.annotation.ElementType.*;
17+
import static java.lang.annotation.RetentionPolicy.RUNTIME;
18+
19+
@Target({FIELD, METHOD, PARAMETER, ANNOTATION_TYPE})
20+
@Retention(RUNTIME)
21+
@Constraint(validatedBy = CheckCaseValidator.class)
22+
@Documented
23+
public @interface CheckCase {
24+
25+
String message() default "{org.hibernate.validator.referenceguide.chapter06.CheckCase." +
26+
"message}";
27+
28+
Class<?>[] groups() default {};
29+
30+
Class<? extends Payload>[] payload() default {};
31+
32+
CaseMode value();
33+
34+
@Target({FIELD, METHOD, PARAMETER, ANNOTATION_TYPE})
35+
@Retention(RUNTIME)
36+
@Documented
37+
@interface List {
38+
CheckCase[] value();
39+
}
40+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* Copyright (c) 2013-2016, The SeedStack authors <http://seedstack.org>
3+
*
4+
* This Source Code Form is subject to the terms of the Mozilla Public
5+
* License, v. 2.0. If a copy of the MPL was not distributed with this
6+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
7+
*/
8+
package org.seedstack.validation.internal.custom;
9+
10+
import javax.validation.ConstraintValidator;
11+
import javax.validation.ConstraintValidatorContext;
12+
13+
public class CheckCaseValidator implements ConstraintValidator<CheckCase, String> {
14+
15+
private CaseMode caseMode;
16+
17+
@Override
18+
public void initialize(CheckCase constraintAnnotation) {
19+
this.caseMode = constraintAnnotation.value();
20+
}
21+
22+
@Override
23+
public boolean isValid(String object, ConstraintValidatorContext constraintContext) {
24+
if (object == null) {
25+
return true;
26+
}
27+
28+
if (caseMode == CaseMode.UPPER) {
29+
return object.equals(object.toUpperCase());
30+
} else {
31+
return object.equals(object.toLowerCase());
32+
}
33+
}
34+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* Copyright (c) 2013-2016, The SeedStack authors <http://seedstack.org>
3+
*
4+
* This Source Code Form is subject to the terms of the Mozilla Public
5+
* License, v. 2.0. If a copy of the MPL was not distributed with this
6+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
7+
*/
8+
package org.seedstack.validation.internal.pojo;
9+
10+
import org.seedstack.validation.internal.custom.CaseMode;
11+
import org.seedstack.validation.internal.custom.CheckCase;
12+
13+
public class CustomPojo {
14+
@CheckCase(CaseMode.UPPER)
15+
private final String item;
16+
17+
public CustomPojo(String item) {
18+
this.item = item;
19+
}
20+
}

0 commit comments

Comments
 (0)