|
|
@@ -1,86 +1,93 @@
|
|
1
|
1
|
import org.junit.Ignore;
|
|
|
2
|
+import org.junit.Before;
|
|
2
|
3
|
import org.junit.Test;
|
|
3
|
4
|
|
|
4
|
5
|
import static org.junit.Assert.assertFalse;
|
|
5
|
6
|
import static org.junit.Assert.assertTrue;
|
|
6
|
7
|
|
|
7
|
8
|
public class LuhnValidatorTest {
|
|
|
9
|
+ private LuhnValidator luhnValidator;
|
|
|
10
|
+
|
|
|
11
|
+ @Before
|
|
|
12
|
+ public void setUp() {
|
|
|
13
|
+ luhnValidator = new LuhnValidator();
|
|
|
14
|
+ }
|
|
8
|
15
|
|
|
9
|
16
|
@Test
|
|
10
|
17
|
public void testThatSingleDigitStringIsNotValid() {
|
|
11
|
|
- assertFalse(new LuhnValidator().isValid("1"));
|
|
|
18
|
+ assertFalse(luhnValidator.isValid("1"));
|
|
12
|
19
|
}
|
|
13
|
20
|
|
|
14
|
21
|
@Ignore
|
|
15
|
22
|
@Test
|
|
16
|
23
|
public void testThatTheStringConsistingOfASingleZeroIsInvalid() {
|
|
17
|
|
- assertFalse(new LuhnValidator().isValid("0"));
|
|
|
24
|
+ assertFalse(luhnValidator.isValid("0"));
|
|
18
|
25
|
}
|
|
19
|
26
|
|
|
20
|
27
|
@Ignore
|
|
21
|
28
|
@Test
|
|
22
|
29
|
public void testThatASimpleValidNumberIsIdentifiedAsValid() {
|
|
23
|
|
- assertTrue(new LuhnValidator().isValid(" 5 9 "));
|
|
|
30
|
+ assertTrue(luhnValidator.isValid(" 5 9 "));
|
|
24
|
31
|
}
|
|
25
|
32
|
|
|
26
|
33
|
@Ignore
|
|
27
|
34
|
@Test
|
|
28
|
35
|
public void testThatAValidCanadianSocialInsuranceNumberIsIdentifiedAsValidV1() {
|
|
29
|
|
- assertTrue(new LuhnValidator().isValid("046 454 286"));
|
|
|
36
|
+ assertTrue(luhnValidator.isValid("046 454 286"));
|
|
30
|
37
|
}
|
|
31
|
38
|
|
|
32
|
39
|
@Ignore
|
|
33
|
40
|
@Test
|
|
34
|
41
|
public void testThatAValidCanadianSocialInsuranceNumberIsIdentifiedAsValidV2() {
|
|
35
|
|
- assertTrue(new LuhnValidator().isValid("055 444 285"));
|
|
|
42
|
+ assertTrue(luhnValidator.isValid("055 444 285"));
|
|
36
|
43
|
}
|
|
37
|
44
|
|
|
38
|
45
|
@Ignore
|
|
39
|
46
|
@Test
|
|
40
|
47
|
public void testThatAnInvalidCanadianSocialInsuranceNumberIsIdentifiedAsInvalid() {
|
|
41
|
|
- assertFalse(new LuhnValidator().isValid("046 454 287"));
|
|
|
48
|
+ assertFalse(luhnValidator.isValid("046 454 287"));
|
|
42
|
49
|
}
|
|
43
|
50
|
|
|
44
|
51
|
@Ignore
|
|
45
|
52
|
@Test
|
|
46
|
53
|
public void testThatAnInvalidCreditCardIsIdentifiedAsInvalid() {
|
|
47
|
|
- assertFalse(new LuhnValidator().isValid("8273 1232 7352 0569"));
|
|
|
54
|
+ assertFalse(luhnValidator.isValid("8273 1232 7352 0569"));
|
|
48
|
55
|
}
|
|
49
|
56
|
|
|
50
|
57
|
@Ignore
|
|
51
|
58
|
@Test
|
|
52
|
59
|
public void testThatAddingANonDigitCharacterToAValidStringInvalidatesTheString() {
|
|
53
|
|
- assertFalse(new LuhnValidator().isValid("046a 454 286"));
|
|
|
60
|
+ assertFalse(luhnValidator.isValid("046a 454 286"));
|
|
54
|
61
|
}
|
|
55
|
62
|
|
|
56
|
63
|
@Ignore
|
|
57
|
64
|
@Test
|
|
58
|
65
|
public void testThatStringContainingPunctuationIsInvalid() {
|
|
59
|
|
- assertFalse(new LuhnValidator().isValid("055-444-285"));
|
|
|
66
|
+ assertFalse(luhnValidator.isValid("055-444-285"));
|
|
60
|
67
|
}
|
|
61
|
68
|
|
|
62
|
69
|
@Ignore
|
|
63
|
70
|
@Test
|
|
64
|
71
|
public void testThatStringContainingSymbolsIsInvalid() {
|
|
65
|
|
- assertFalse(new LuhnValidator().isValid("055£ 444$ 285"));
|
|
|
72
|
+ assertFalse(luhnValidator.isValid("055£ 444$ 285"));
|
|
66
|
73
|
}
|
|
67
|
74
|
|
|
68
|
75
|
@Ignore
|
|
69
|
76
|
@Test
|
|
70
|
77
|
public void testThatTheStringConsistingOfASpaceAndASingleZeroIsInvalid() {
|
|
71
|
|
- assertFalse(new LuhnValidator().isValid(" 0"));
|
|
|
78
|
+ assertFalse(luhnValidator.isValid(" 0"));
|
|
72
|
79
|
}
|
|
73
|
80
|
|
|
74
|
81
|
@Ignore
|
|
75
|
82
|
@Test
|
|
76
|
83
|
public void testThatStringContainingMultipleZerosIsValid() {
|
|
77
|
|
- assertTrue(new LuhnValidator().isValid(" 00000"));
|
|
|
84
|
+ assertTrue(luhnValidator.isValid(" 00000"));
|
|
78
|
85
|
}
|
|
79
|
86
|
|
|
80
|
87
|
@Ignore
|
|
81
|
88
|
@Test
|
|
82
|
89
|
public void testThatDoublingNineIsHandledCorrectly() {
|
|
83
|
|
- assertTrue(new LuhnValidator().isValid("091"));
|
|
|
90
|
+ assertTrue(luhnValidator.isValid("091"));
|
|
84
|
91
|
}
|
|
85
|
92
|
|
|
86
|
93
|
}
|