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
20
21
22
23
24
25
26 public class ISBNCheckDigitTest extends AbstractCheckDigitTest {
27
28
29
30
31
32 public ISBNCheckDigitTest(String name) {
33 super(name);
34 }
35
36
37
38
39 @Override
40 protected void setUp() throws Exception {
41 super.setUp();
42 routine = ISBNCheckDigit.ISBN_CHECK_DIGIT;
43 valid = new String[] {
44 "9780072129519",
45 "9780764558313",
46 "1930110995",
47 "020163385X",
48 "1590596277",
49 "9781590596272"
50 };
51 missingMessage = "ISBN Code is missing";
52 zeroSum = "000000000000";
53 }
54
55
56
57
58 public void testInvalidLength() {
59 assertFalse("isValid() Lth 9 ", routine.isValid("123456789"));
60 assertFalse("isValid() Lth 11", routine.isValid("12345678901"));
61 assertFalse("isValid() Lth 12", routine.isValid("123456789012"));
62 assertFalse("isValid() Lth 14", routine.isValid("12345678901234"));
63
64 try {
65 routine.calculate("12345678");
66 fail("calculate() Lth 8 - expected exception");
67 } catch (Exception e) {
68 assertEquals("calculate() Lth 8", "Invalid ISBN Length = 8", e.getMessage());
69 }
70
71 try {
72 routine.calculate("1234567890");
73 fail("calculate() Lth 10 - expected exception");
74 } catch (Exception e) {
75 assertEquals("calculate() Lth 10", "Invalid ISBN Length = 10", e.getMessage());
76 }
77
78 try {
79 routine.calculate("12345678901");
80 fail("calculate() Lth 11 - expected exception");
81 } catch (Exception e) {
82 assertEquals("calculate() Lth 11", "Invalid ISBN Length = 11", e.getMessage());
83 }
84
85 try {
86 routine.calculate("1234567890123");
87 fail("calculate() Lth 13 - expected exception");
88 } catch (Exception e) {
89 assertEquals("calculate() Lth 13", "Invalid ISBN Length = 13", e.getMessage());
90 }
91 }
92
93
94 }