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.checkdigit;
18
19 import org.junit.jupiter.api.BeforeEach;
20
21 /**
22 * EC Number Check Digit Tests.
23 */
24 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 * {@inheritDoc}
35 */
36 @Override
37 protected String removeCheckDigit(final String code) {
38 final String cde = (String) ECNumberCheckDigit.REGEX_VALIDATOR.validate(code);
39 if (cde == null || cde.length() <= checkDigitLth) {
40 return null;
41 }
42 return cde.substring(0, cde.length() - checkDigitLth);
43 }
44
45 /**
46 * Sets up routine & valid codes.
47 */
48 @BeforeEach
49 protected void setUp() {
50 routine = ECNumberCheckDigit.getInstance();
51 valid = new String[] {MIN, FORMALDEHYDE, DEXAMETHASONE, ARSENIC, ASBESTOS, MAX};
52 }
53
54 }