View Javadoc
1   /*
2    * #%L
3    * Nuiton Validator
4    * %%
5    * Copyright (C) 2013 - 2014 Code Lutin, Tony Chemit
6    * %%
7    * This program is free software: you can redistribute it and/or modify
8    * it under the terms of the GNU Lesser General Public License as 
9    * published by the Free Software Foundation, either version 3 of the 
10   * License, or (at your option) any later version.
11   * 
12   * This program is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   * GNU General Lesser Public License for more details.
16   * 
17   * You should have received a copy of the GNU General Lesser Public 
18   * License along with this program.  If not, see
19   * <http://www.gnu.org/licenses/lgpl-3.0.html>.
20   * #L%
21   */
22  package org.nuiton.validator.xwork2.field;
23  
24  import org.junit.Test;
25  import org.nuiton.validator.model.Contact;
26  
27  /**
28   * @author Jean Couteau - couteau@codelutin.com
29   * @since 2.3
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          // Valid phone Number
44          bean.setPhone("0000000000");
45          assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
46                             false);
47  
48          // Valid phone Number
49          bean.setPhone("00 00 00 00 00");
50          assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
51                             false);
52  
53          // Valid phone Number
54          bean.setPhone("00-00-00-00-00");
55          assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
56                             false);
57  
58          // Valid phone Number
59          bean.setPhone("00.00.00.00.00");
60          assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
61                             false);
62  
63          // Too long phone Number
64          bean.setPhone("00 00 00 00 00 00");
65          assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
66                             true);
67  
68          // Too long phone Number
69          bean.setPhone("00-00-00-00-00-00");
70          assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
71                             true);
72  
73          // Too long phone Number
74          bean.setPhone("000000000000");
75          assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
76                             true);
77  
78          // Too long phone Number
79          bean.setPhone("00.00.00.00.00.00");
80          assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
81                             true);
82  
83          // Too short phone Number
84          bean.setPhone("00.00.00.00");
85          assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
86                             true);
87  
88          // Too short phone Number
89          bean.setPhone("00000000");
90          assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
91                             true);
92  
93          // Too short phone Number
94          bean.setPhone("00-00-00-00");
95          assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
96                             true);
97  
98          // Too short phone Number
99          bean.setPhone("00 00 00 00");
100         assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
101                            true);
102 
103         // Invalid character in phone Number
104         bean.setPhone("00 00 ab 00 00");
105         assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
106                            true);
107 
108         // Invalid character in phone Number
109         bean.setPhone("0000ab0000");
110         assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
111                            true);
112 
113         // Invalid character in phone Number
114         bean.setPhone("00.00.ab.00.00");
115         assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
116                            true);
117 
118         // Invalid character in phone Number
119         bean.setPhone("00-00-ab-00-00");
120         assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
121                            true);
122         //Use required string validator for this case
123         bean.setPhone("");
124         assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
125                            false);
126         //Use required validator for this case
127         bean.setPhone(null);
128         assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
129                            false);
130 
131     }
132 }