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   * ISINValidator Test Case.
26   *
27   * @since 1.7
28   */
29  public class ISINValidatorTest {
30  
31      private static final ISINValidator VALIDATOR_TRUE = ISINValidator.getInstance(true);
32  
33      private static final ISINValidator VALIDATOR_FALSE = ISINValidator.getInstance(false);
34  
35      private final String[] validFormat = { "US0378331005", "BMG8571G1096", "AU0000XVGZA3", "GB0002634946", "FR0004026250", "DK0009763344", "GB00B03MLX29",
36              "US7562071065", "US56845T3059", "LU0327357389", "US032511BN64", "INE112A01023", "EZ0000000003", // Invented; for use in ISINValidator
37              "XS0000000009", };
38  
39      private final String[] invalidFormat = { null, "", // empty
40              "   ", // empty
41              "US037833100O", // proper check digit is '5', see above
42              "BMG8571G109D", // proper check digit is '6', see above
43              "AU0000XVGZAD", // proper check digit is '3', see above
44              "GB000263494I", // proper check digit is '6', see above
45              "FR000402625C", // proper check digit is '0', see above
46              "DK000976334H", // proper check digit is '4', see above
47              "3133EHHF3", // see VALIDATOR-422 Valid check-digit, but not valid ISIN
48              "AU0000xvgzA3", // disallow lower case NSIN
49              "gb0002634946", // disallow lower case ISO code
50      };
51  
52      // Invalid codes if country checking is enabled
53      private final String[] invalidFormatTrue = { "AA0000000006", // Invalid country code
54      };
55  
56      @Test
57      public void testInvalidFalse() {
58          for (final String f : invalidFormat) {
59              assertFalse(VALIDATOR_FALSE.isValid(f), f);
60          }
61      }
62  
63      @Test
64      public void testInvalidTrue() {
65          for (final String f : invalidFormat) {
66              assertFalse(VALIDATOR_TRUE.isValid(f), f);
67          }
68          for (final String f : invalidFormatTrue) {
69              assertFalse(VALIDATOR_TRUE.isValid(f), f);
70          }
71      }
72  
73      @Test
74      public void testIsValidFalse() {
75          for (final String f : validFormat) {
76              assertTrue(VALIDATOR_FALSE.isValid(f), f);
77          }
78      }
79  
80      @Test
81      public void testIsValidTrue() {
82          for (final String f : validFormat) {
83              assertTrue(VALIDATOR_TRUE.isValid(f), f);
84          }
85      }
86  
87  }