Skip to content

Instantly share code, notes, and snippets.

@biodunalfet
Created July 24, 2019 11:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save biodunalfet/98041cab9791d9cb902228c7654c02d4 to your computer and use it in GitHub Desktop.
Save biodunalfet/98041cab9791d9cb902228c7654c02d4 to your computer and use it in GitHub Desktop.
Specification for unit test
package com.flutterwave.raveandroid.validators;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.*;
@RunWith(JUnit4.class)
public class CvvValidatorTest {
CvvValidator SUT; //system under test
@Before
public void setUp() throws Exception {
SUT = new CvvValidator();
}
//correct cvv returns true
//incorrect cvv returns false
//UnitBeingTested_particularCase_ExpectedOutcome
@Test
public void isCvvValid_CorrectCvvPassed_returnsTrue() {
//the three As of testing
//Arrange
//Act
//Assert
String cvv = "345";
boolean isValid = SUT.isCvvValid(cvv);
assertThat(true, is(isValid));
// assertTrue(isValid);
}
@Test
public void isCvvValid_4digitCvvPassed_returnsTrue() {
//the three As of testing
//Arrange
//Act
//Assert
String cvv = "3345";
boolean isValid = SUT.isCvvValid(cvv);
assertThat(true, is(isValid));
// assertTrue(isValid);
}
@Test
public void isCvvValid_CvvPassedLongerThan4_returnsFalse() {
//the three As of testing
//Arrange
//Act
//Assert
String cvv = "33457";
boolean isValid = SUT.isCvvValid(cvv);
assertThat(false, is(isValid));
// assertTrue(isValid);
}
@Test
public void isCvvValid_CvvPassedLessThan3_returnsFalse() {
//the three As of testing
//Arrange
//Act
//Assert
String cvv = "33";
boolean isValid = SUT.isCvvValid(cvv);
assertThat(false, is(isValid));
// assertTrue(isValid);
}
@Test
public void isCvvValid_CvvPassedIsNotDigits_returnsFalse() {
//the three As of testing
//Arrange
//Act
//Assert
String cvv = "3a3";
boolean isValid = SUT.isCvvValid(cvv);
assertThat(false, is(isValid));
// assertTrue(isValid);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment