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