View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.validator.routines;
18  
19  import junit.framework.TestCase;
20  
21  /**
22   * ISINValidator Test Case.
23   *
24   * @since 1.7
25   */
26  public class ISINValidatorTest extends TestCase {
27  
28      private static final ISINValidator VALIDATOR_TRUE = ISINValidator.getInstance(true);
29      
30      private static final ISINValidator VALIDATOR_FALSE = ISINValidator.getInstance(false);
31  
32      private final String[] validFormat = new String[] {
33              "US0378331005",
34              "BMG8571G1096",
35              "AU0000XVGZA3",
36              "GB0002634946",
37              "FR0004026250",
38              "DK0009763344",
39              "GB00B03MLX29",
40              "US7562071065",
41              "US56845T3059",
42              "LU0327357389",
43              "US032511BN64",
44              "INE112A01023",
45              "EZ0000000003", // Invented; for use in ISINValidator
46              "XS0000000009",
47              };
48  
49      private final String[] invalidFormat = new String[] {
50              null,
51              "",                        // empty
52              "   ",                     // empty
53              "US037833100O", // proper check digit is '5', see above
54              "BMG8571G109D", // proper check digit is '6', see above
55              "AU0000XVGZAD", // proper check digit is '3', see above
56              "GB000263494I", // proper check digit is '6', see above
57              "FR000402625C", // proper check digit is '0', see above
58              "DK000976334H", // proper check digit is '4', see above            
59              "3133EHHF3", // see VALIDATOR-422 Valid check-digit, but not valid ISIN
60              "AU0000xvgzA3", // disallow lower case NSIN
61              "gb0002634946", // disallow lower case ISO code
62              };
63  
64      // Invalid codes if country checking is enabled
65      private final String[] invalidFormatTrue = new String[] {
66              "AA0000000006", // Invalid country code            
67              };
68  
69      public ISINValidatorTest(String name) {
70          super(name);
71      }
72  
73      public void testIsValidTrue() {
74          for(String f : validFormat) {
75              assertTrue(f, VALIDATOR_TRUE.isValid(f));            
76          }
77      }
78  
79      public void testInvalidTrue() {
80          for(String f : invalidFormat) {
81              assertFalse(f, VALIDATOR_TRUE.isValid(f));            
82          }
83          for(String f : invalidFormatTrue) {
84              assertFalse(f, VALIDATOR_TRUE.isValid(f));            
85          }
86      }
87  
88      public void testIsValidFalse() {
89          for(String f : validFormat) {
90              assertTrue(f, VALIDATOR_FALSE.isValid(f));            
91          }
92      }
93  
94      public void testInvalidFalse() {
95          for(String f : invalidFormat) {
96              assertFalse(f, VALIDATOR_FALSE.isValid(f));            
97          }
98      }
99  
100 }