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.checkdigit;
18  
19  import org.junit.jupiter.api.BeforeEach;
20  
21  /**
22   * EC Number Check Digit Tests.
23   */
24  public class ECNumberCheckDigitTest extends AbstractCheckDigitTest {
25  
26      private static final String MIN = "000-001-6"; // theoretical
27      private static final String FORMALDEHYDE = "200-001-8"; // this is the first entry in EINECS
28      private static final String DEXAMETHASONE = "200-003-9";
29      private static final String ARSENIC = "231-148-6";
30      private static final String ASBESTOS = "603-721-4";
31      private static final String MAX = "999-999-2"; // theoretical
32  
33      /**
34       * Sets up routine & valid codes.
35       */
36      @BeforeEach
37      protected void setUp() {
38          routine = ECNumberCheckDigit.getInstance();
39          valid = new String[] {MIN, FORMALDEHYDE, DEXAMETHASONE, ARSENIC, ASBESTOS, MAX};
40      }
41  
42      /**
43       * {@inheritDoc}
44       */
45      @Override
46      protected String removeCheckDigit(final String code) {
47          final String cde = (String) ECNumberCheckDigit.REGEX_VALIDATOR.validate(code);
48          if (cde == null || cde.length() <= checkDigitLth) {
49              return null;
50          }
51          return cde.substring(0, cde.length() - checkDigitLth);
52      }
53  
54  }