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 static org.junit.jupiter.api.Assertions.assertFalse;
20  import static org.junit.jupiter.api.Assertions.assertTrue;
21  
22  import org.junit.jupiter.api.Test;
23  
24  /**
25   * Tests {@link ISINValidator}.
26   */
27  public class ISINValidatorTest {
28  
29      private static final ISINValidator VALIDATOR_TRUE = ISINValidator.getInstance(true);
30  
31      private static final ISINValidator VALIDATOR_FALSE = ISINValidator.getInstance(false);
32  
33      // @formatter:off
34      private final String[] validFormat = {
35              "US0378331005",
36              "BMG8571G1096",
37              "AU0000XVGZA3",
38              "GB0002634946",
39              "FR0004026250",
40              "DK0009763344",
41              "GB00B03MLX29",
42              "US7562071065",
43              "US56845T3059",
44              "LU0327357389",
45              "US032511BN64",
46              "INE112A01023",
47              "EZ0000000003", // Invented; for use in ISINValidator
48              "EU000A0VUCF1",
49              "XA2053913989",
50              "XB0000000008",
51              "XC0009698371",
52              "XD0000000006",
53              "XF0000000004",
54              "QS0000000008",
55              "QT0000000007",
56              "QW0000000002",
57              "XS0000000009", };
58  
59      private final String[] invalidFormat = { null, "", // empty
60              "   ", // empty
61              "US037833100O", // proper check digit is '5', see above
62              "BMG8571G109D", // proper check digit is '6', see above
63              "AU0000XVGZAD", // proper check digit is '3', see above
64              "GB000263494I", // proper check digit is '6', see above
65              "FR000402625C", // proper check digit is '0', see above
66              "DK000976334H", // proper check digit is '4', see above
67              "3133EHHF3", // see VALIDATOR-422 Valid check-digit, but not valid ISIN
68              "AU0000xvgzA3", // disallow lower case NSIN
69              "gb0002634946", // disallow lower case ISO code
70      };
71  
72      // Invalid codes if country checking is enabled
73      private final String[] invalidFormatTrue = { "AB0000000006", // Invalid country code
74      };
75  
76      @Test
77      public void testInvalidFalse() {
78          for (final String f : invalidFormat) {
79              assertFalse(VALIDATOR_FALSE.isValid(f), f);
80          }
81      }
82  
83      @Test
84      public void testInvalidTrue() {
85          for (final String f : invalidFormat) {
86              assertFalse(VALIDATOR_TRUE.isValid(f), f);
87          }
88          for (final String f : invalidFormatTrue) {
89              assertFalse(VALIDATOR_TRUE.isValid(f), f);
90          }
91      }
92  
93      @Test
94      public void testIsValidFalse() {
95          for (final String f : validFormat) {
96              assertTrue(VALIDATOR_FALSE.isValid(f), f);
97          }
98      }
99  
100     @Test
101     public void testIsValidTrue() {
102         for (final String f : validFormat) {
103             assertTrue(VALIDATOR_TRUE.isValid(f), f);
104         }
105     }
106 
107 }