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    *      https://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  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              "EU0009652783",
59              "XAC8614YAB92",
60              "XC0001458477",
61              "XD0209061296",
62              "AN8068571086",
63          };
64  
65      private final String[] invalidFormat = { null, "", // empty
66              "   ", // empty
67              "US037833100O", // proper check digit is '5', see above
68              "BMG8571G109D", // proper check digit is '6', see above
69              "AU0000XVGZAD", // proper check digit is '3', see above
70              "GB000263494I", // proper check digit is '6', see above
71              "FR000402625C", // proper check digit is '0', see above
72              "DK000976334H", // proper check digit is '4', see above
73              "3133EHHF3", // see VALIDATOR-422 Valid check-digit, but not valid ISIN
74              "AU0000xvgzA3", // disallow lower case NSIN
75              "gb0002634946", // disallow lower case ISO code
76      };
77  
78      // Invalid codes if country checking is enabled
79      private final String[] invalidFormatTrue = { "AB0000000006", // Invalid country code
80      };
81  
82      @Test
83      void testInvalidFalse() {
84          for (final String f : invalidFormat) {
85              assertFalse(VALIDATOR_FALSE.isValid(f), f);
86          }
87      }
88  
89      @Test
90      void testInvalidTrue() {
91          for (final String f : invalidFormat) {
92              assertFalse(VALIDATOR_TRUE.isValid(f), f);
93          }
94          for (final String f : invalidFormatTrue) {
95              assertFalse(VALIDATOR_TRUE.isValid(f), f);
96          }
97      }
98  
99      @Test
100     void testIsValidFalse() {
101         for (final String f : validFormat) {
102             assertTrue(VALIDATOR_FALSE.isValid(f), f);
103         }
104     }
105 
106     @Test
107     void testIsValidTrue() {
108         for (final String f : validFormat) {
109             assertTrue(VALIDATOR_TRUE.isValid(f), f);
110         }
111     }
112 
113 }