Skip to content

Commit 10bd887

Browse files
committed
cvvValidatorTest
1 parent 93bb0b1 commit 10bd887

File tree

2 files changed

+68
-1
lines changed

2 files changed

+68
-1
lines changed

raveandroid/src/main/java/com/flutterwave/raveandroid/validators/CvvValidator.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
public class CvvValidator {
44

55
public boolean isCvvValid(String cvv){
6-
return cvv.length() >= 3;
6+
7+
try{
8+
Integer.parseInt(cvv);
9+
return cvv.length() == 3 || cvv.length() == 4;
10+
}catch (NumberFormatException e){
11+
return false;
12+
}
13+
714
}
815
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package com.flutterwave.raveandroid.validators;
2+
3+
import org.junit.Before;
4+
import org.junit.Test;
5+
6+
import static org.hamcrest.CoreMatchers.is;
7+
import static org.junit.Assert.*;
8+
9+
public class CvvValidatorTest {
10+
11+
private CvvValidator SUT;
12+
13+
@Before
14+
public void setUp() throws Exception {
15+
SUT = new CvvValidator();
16+
}
17+
18+
@Test
19+
public void isCvvValid_CorrectCvvPassed_returnsTrue(){
20+
String cvv = "345";
21+
boolean isValid = SUT.isCvvValid(cvv);
22+
assertThat(true, is(isValid));
23+
}
24+
25+
@Test
26+
public void isCvvValid_4digitCvvPassed_returnsTrue(){
27+
String cvv = "3455";
28+
boolean isValid = SUT.isCvvValid(cvv);
29+
assertThat(true, is(isValid));
30+
}
31+
32+
@Test
33+
public void isCvvValid_CvvPassedLongerThan4_returnsFalse(){
34+
String cvv = "34554";
35+
boolean isValid = SUT.isCvvValid(cvv);
36+
assertThat(false, is(isValid));
37+
}
38+
39+
@Test
40+
public void isCvvValid_CvvPassedLessThan3_returnsFalse(){
41+
String cvv = "34";
42+
boolean isValid = SUT.isCvvValid(cvv);
43+
assertThat(false, is(isValid));
44+
}
45+
46+
@Test
47+
public void isCvvValid_CvvPassedIsNotDigits_returnsFalse(){
48+
String cvv = "aas";
49+
boolean isValid = SUT.isCvvValid(cvv);
50+
assertThat(false, is(isValid));
51+
}
52+
53+
@Test
54+
public void isCvvValid_CvvPassedIsEmpty_returnsFalse(){
55+
String cvv = "";
56+
boolean isValid = SUT.isCvvValid(cvv);
57+
assertThat(false, is(isValid));
58+
}
59+
60+
}

0 commit comments

Comments
 (0)