1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.nuiton.validator.xwork2.field;
23
24 import org.junit.Test;
25 import org.nuiton.validator.model.Contact;
26
27
28
29
30
31 public class FrenchPhoneNumberFieldValidatorTest extends AbstractFieldValidatorTest<Contact> {
32
33 public FrenchPhoneNumberFieldValidatorTest() {
34 super(Contact.class);
35 }
36
37 @Test
38 @Override
39 public void testValidator() throws Exception {
40
41 assertNull(bean.getPhone());
42
43
44 bean.setPhone("0000000000");
45 assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
46 false);
47
48
49 bean.setPhone("00 00 00 00 00");
50 assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
51 false);
52
53
54 bean.setPhone("00-00-00-00-00");
55 assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
56 false);
57
58
59 bean.setPhone("00.00.00.00.00");
60 assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
61 false);
62
63
64 bean.setPhone("00 00 00 00 00 00");
65 assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
66 true);
67
68
69 bean.setPhone("00-00-00-00-00-00");
70 assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
71 true);
72
73
74 bean.setPhone("000000000000");
75 assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
76 true);
77
78
79 bean.setPhone("00.00.00.00.00.00");
80 assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
81 true);
82
83
84 bean.setPhone("00.00.00.00");
85 assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
86 true);
87
88
89 bean.setPhone("00000000");
90 assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
91 true);
92
93
94 bean.setPhone("00-00-00-00");
95 assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
96 true);
97
98
99 bean.setPhone("00 00 00 00");
100 assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
101 true);
102
103
104 bean.setPhone("00 00 ab 00 00");
105 assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
106 true);
107
108
109 bean.setPhone("0000ab0000");
110 assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
111 true);
112
113
114 bean.setPhone("00.00.ab.00.00");
115 assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
116 true);
117
118
119 bean.setPhone("00-00-ab-00-00");
120 assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
121 true);
122
123 bean.setPhone("");
124 assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
125 false);
126
127 bean.setPhone(null);
128 assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
129 false);
130
131 }
132 }