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