1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.validator.routines.checkdigit;
18
19 import java.io.BufferedReader;
20 import java.io.InputStreamReader;
21 import java.util.ArrayList;
22 import java.util.List;
23
24 import org.junit.Assert;
25 import org.junit.jupiter.api.BeforeEach;
26 import org.junit.jupiter.api.Test;
27
28
29
30
31
32
33 public class IBANCheckDigitTest extends AbstractCheckDigitTest {
34
35 public IBANCheckDigitTest() {
36 checkDigitLth = 2;
37 }
38
39
40
41
42
43
44
45 @Override
46 protected String checkDigit(final String code) {
47 if (code == null || code.length() <= checkDigitLth) {
48 return "";
49 }
50 return code.substring(2, 4);
51 }
52
53
54
55
56
57
58
59 @Override
60 protected String[] createInvalidCodes(final String[] codes) {
61 final List<String> list = new ArrayList<>();
62
63
64 for (final String code2 : codes) {
65 final String code = removeCheckDigit(code2);
66 final String check = checkDigit(code2);
67 for (int j = 2; j <= 98; j++) {
68 final String curr = j > 9 ? "" + j : "0" + j;
69 if (!curr.equals(check)) {
70 list.add(code.substring(0, 2) + curr + code.substring(4));
71 }
72 }
73 }
74
75 return list.toArray(new String[0]);
76 }
77
78
79
80
81
82
83
84 @Override
85 protected String removeCheckDigit(final String code) {
86 return code.substring(0, 2) + "00" + code.substring(4);
87 }
88
89
90
91
92 @BeforeEach
93 protected void setUp() {
94 routine = IBANCheckDigit.IBAN_CHECK_DIGIT;
95 valid = new String[] { "AD1200012030200359100100",
96 "AE070331234567890123456",
97 "AL47212110090000000235698741",
98 "AT611904300234573201",
99 "AZ21NABZ00000000137010001944",
100 "BA391290079401028494",
101 "BE62510007547061",
102 "BE68539007547034",
103 "BG80BNBG96611020345678",
104 "BH67BMAG00001299123456",
105 "BI4210000100010000332045181",
106 "BR1800000000141455123924100C2",
107 "BY13NBRB3600900000002Z00AB00",
108 "CH3900700115201849173",
109 "CH9300762011623852957",
110 "CR05015202001026284066",
111 "CY17002001280000001200527600",
112 "CZ6508000000192000145399",
113 "DE89370400440532013000",
114 "DJ2110002010010409943020008",
115 "DK5000400440116243",
116 "DO28BAGR00000001212453611324",
117 "EE382200221020145685",
118 "ES8023100001180000012345",
119 "FI2112345600000785",
120 "FO6264600001631634",
121 "FR1420041010050500013M02606",
122 "GB29NWBK60161331926819",
123 "GI75NWBK000000007099453",
124 "GL8964710001000206",
125 "GR1601101250000000012300695",
126 "GT82TRAJ01020000001210029690",
127 "HR1210010051863000160",
128 "HU42117730161111101800000000",
129 "IE29AIBK93115212345678",
130 "IL620108000000099999999",
131 "IQ98NBIQ850123456789012",
132 "IS140159260076545510730339",
133 "IT60X0542811101000000123456",
134 "JO94CBJO0010000000000131000302",
135 "KW81CBKU0000000000001234560101",
136 "KZ86125KZT5004100100",
137 "LB62099900000001001901229114",
138 "LC55HEMM000100010012001200023015",
139 "LI21088100002324013AA",
140 "LT121000011101001000",
141 "LU280019400644750000",
142 "LV80BANK0000435195001",
143 "MC5811222000010123456789030",
144 "MD24AG000225100013104168",
145 "ME25505000012345678951",
146 "MK07250120000058984",
147 "MR1300020001010000123456753",
148 "MT84MALT011000012345MTLCAST001S",
149 "MU17BOMM0101101030300200000MUR",
150 "NL39RABO0300065264",
151 "NL91ABNA0417164300",
152 "NO9386011117947",
153 "PK36SCBL0000001123456702",
154 "PL27114020040000300201355387",
155 "PL60102010260000042270201111",
156 "PS92PALS000000000400123456702",
157 "PT50000201231234567890154",
158 "QA58DOHB00001234567890ABCDEFG",
159 "RO49AAAA1B31007593840000",
160 "RS35260005601001611379",
161 "RU0204452560040702810412345678901",
162 "SA0380000000608010167519",
163 "SC18SSCB11010000000000001497USD",
164 "SD8811123456789012",
165 "SE3550000000054910000003",
166 "SD2129010501234001",
167 "SI56191000000123438",
168 "SK3112000000198742637541",
169 "SM86U0322509800000000270100",
170 "ST68000100010051845310112",
171 "SV62CENR00000000000000700025",
172 "TL380080012345678910157",
173 "TN5910006035183598478831",
174 "TR330006100519786457841326",
175 "UA213223130000026007233566001",
176 "VA59001123000012345678",
177 "VG96VPVG0000012345678901",
178 "XK051212012345678906",
179
180
181
182
183
184
185
186 "AA0200000000053", "AA9700000000089", "AA9800000000071", "ZZ02ZZZZZZZZZZZZZZZZZZZZZZZZZ04", "ZZ97ZZZZZZZZZZZZZZZZZZZZZZZZZ40",
187 "ZZ98ZZZZZZZZZZZZZZZZZZZZZZZZZ22", };
188
189
190
191
192 invalid = new String[] { "510007+47061BE63", "IE01AIBK93118702569045", "AA0000000000089", "AA9900000000053", };
193 zeroSum = null;
194 missingMessage = "Invalid Code length=0";
195
196 }
197
198 @Test
199 public void testOther() throws Exception {
200 try (BufferedReader rdr = new BufferedReader(new InputStreamReader(this.getClass().getResourceAsStream("IBANtests.txt"), "ASCII"))) {
201 String line;
202 while ((line = rdr.readLine()) != null) {
203 if (!line.startsWith("#") && !line.isEmpty()) {
204 if (line.startsWith("-")) {
205 line = line.substring(1);
206 Assert.assertFalse(line, routine.isValid(line.replace(" ", "")));
207 } else {
208 Assert.assertTrue(line, routine.isValid(line.replace(" ", "")));
209 }
210 }
211 }
212 }
213 }
214
215
216
217
218 @Override
219 @Test
220 public void testZeroSum() {
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235 }
236 }