File tree Expand file tree Collapse file tree 4 files changed +132
-0
lines changed
blackbox-test/src/test/java/example/avaje Expand file tree Collapse file tree 4 files changed +132
-0
lines changed Original file line number Diff line number Diff line change
1
+ package example .avaje ;
2
+
3
+ import io .avaje .validation .ValidPojo ;
4
+ import io .avaje .validation .constraints .Email ;
5
+
6
+ @ ValidPojo
7
+ public class AMyEmail {
8
+
9
+ @ Email
10
+ public final String email ;
11
+
12
+ public AMyEmail (String email ) {
13
+ this .email = email ;
14
+ }
15
+ }
Original file line number Diff line number Diff line change
1
+ package example .avaje ;
2
+
3
+ import io .avaje .validation .ConstraintViolation ;
4
+ import io .avaje .validation .ConstraintViolationException ;
5
+ import io .avaje .validation .Validator ;
6
+ import org .junit .jupiter .api .Test ;
7
+
8
+ import java .util .ArrayList ;
9
+ import java .util .Locale ;
10
+
11
+ import static org .assertj .core .api .Assertions .assertThat ;
12
+ import static org .assertj .core .api .Assertions .fail ;
13
+
14
+ class AMyEmailTest {
15
+
16
+ final Validator validator = Validator .builder ().build ();
17
+
18
+ @ Test
19
+ void valid () {
20
+ var bean =
new AMyEmail (
"[email protected] " );
21
+ validator .validate (bean );
22
+ }
23
+
24
+ @ Test
25
+ void email () {
26
+ var violation = one (new AMyEmail ("abc" ));
27
+ assertThat (violation .message ()).isEqualTo ("must be a well-formed email address" );
28
+ }
29
+
30
+ @ Test
31
+ void emailDE () {
32
+ var violation = one (new AMyEmail ("abc" ), Locale .GERMAN );
33
+ assertThat (violation .message ()).isEqualTo ("muss eine korrekt formatierte E-Mail-Adresse sein" );
34
+ }
35
+
36
+ ConstraintViolation one (Object any ) {
37
+ return one (any , Locale .ENGLISH );
38
+ }
39
+
40
+ ConstraintViolation one (Object any , Locale locale ) {
41
+ try {
42
+ validator .validate (any , locale );
43
+ fail ("not expected" );
44
+ return null ;
45
+ } catch (ConstraintViolationException e ) {
46
+ var violations = new ArrayList <>(e .violations ());
47
+ assertThat (violations ).hasSize (1 );
48
+ return violations .get (0 );
49
+ }
50
+ }
51
+ }
Original file line number Diff line number Diff line change
1
+ package example .avaje ;
2
+
3
+ import io .avaje .validation .ValidPojo ;
4
+ import io .avaje .validation .constraints .Pattern ;
5
+
6
+ @ ValidPojo
7
+ public class AMyPattern {
8
+
9
+ @ Pattern (regexp = "[0-3]+" )
10
+ public final String myPattern ;
11
+
12
+ public AMyPattern (String myPattern ) {
13
+ this .myPattern = myPattern ;
14
+ }
15
+ }
Original file line number Diff line number Diff line change
1
+ package example .avaje ;
2
+
3
+ import io .avaje .validation .ConstraintViolation ;
4
+ import io .avaje .validation .ConstraintViolationException ;
5
+ import io .avaje .validation .Validator ;
6
+ import org .junit .jupiter .api .Test ;
7
+
8
+ import java .util .ArrayList ;
9
+ import java .util .Locale ;
10
+
11
+ import static org .assertj .core .api .Assertions .assertThat ;
12
+ import static org .assertj .core .api .Assertions .fail ;
13
+
14
+ class AMyPatternTest {
15
+
16
+ final Validator validator = Validator .builder ().build ();
17
+
18
+ @ Test
19
+ void valid () {
20
+ var bean = new AMyPattern ("12" );
21
+ validator .validate (bean );
22
+ }
23
+
24
+ @ Test
25
+ void pattern () {
26
+ var violation = one (new AMyPattern ("abc" ));
27
+ assertThat (violation .message ()).isEqualTo ("must match \" [0-3]+\" " );
28
+ }
29
+
30
+ @ Test
31
+ void patternDE () {
32
+ var violation = one (new AMyPattern ("abc" ), Locale .GERMAN );
33
+ assertThat (violation .message ()).isEqualTo ("muss mit \" [0-3]+\" übereinstimmen" );
34
+ }
35
+
36
+ ConstraintViolation one (Object any ) {
37
+ return one (any , Locale .ENGLISH );
38
+ }
39
+
40
+ ConstraintViolation one (Object any , Locale locale ) {
41
+ try {
42
+ validator .validate (any , locale );
43
+ fail ("not expected" );
44
+ return null ;
45
+ } catch (ConstraintViolationException e ) {
46
+ var violations = new ArrayList <>(e .violations ());
47
+ assertThat (violations ).hasSize (1 );
48
+ return violations .get (0 );
49
+ }
50
+ }
51
+ }
You can’t perform that action at this time.
0 commit comments