View Javadoc
1   package org.nuiton.validator.xwork2.field;
2   
3   /*
4    * #%L
5    * Nuiton Validator
6    * %%
7    * Copyright (C) 2013 - 2014 Code Lutin, Tony Chemit
8    * %%
9    * This program is free software: you can redistribute it and/or modify
10   * it under the terms of the GNU Lesser General Public License as 
11   * published by the Free Software Foundation, either version 3 of the 
12   * License, or (at your option) any later version.
13   * 
14   * This program is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   * GNU General Lesser Public License for more details.
18   * 
19   * You should have received a copy of the GNU General Lesser Public 
20   * License along with this program.  If not, see
21   * <http://www.gnu.org/licenses/lgpl-3.0.html>.
22   * #L%
23   */
24  
25  import org.junit.Assert;
26  import org.junit.Test;
27  
28  /**
29   * @author Sylvain Bavencoff - bavencoff@codelutin.com
30   */
31  public class FieldValidatorUtilTest extends Assert {
32  
33      @Test
34      public void TestLuhnChecksum() throws Exception {
35          // verification sur de vrai numero siret (ca doit passer :)
36          assertTrue(FieldValidatorUtil.luhnChecksum("44211670300038"));
37          assertTrue(FieldValidatorUtil.luhnChecksum("73282932000074"));
38          assertTrue(FieldValidatorUtil.luhnChecksum("2A0002879"));
39  
40          // verification avec les memes, en ne modifiant que le dernier chiffre
41          // ca doit failer
42          assertFalse(FieldValidatorUtil.luhnChecksum("44211670300030"));
43          assertFalse(FieldValidatorUtil.luhnChecksum("73282932000070"));
44          assertFalse(FieldValidatorUtil.luhnChecksum("2A0002870"));
45      }
46  
47  }