Skip to content

Instantly share code, notes, and snippets.

@BumpeiShimada
Last active November 21, 2018 19:22
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 BumpeiShimada/177ba4cb2aa22db5bf84cb9a0bdc34b1 to your computer and use it in GitHub Desktop.
Save BumpeiShimada/177ba4cb2aa22db5bf84cb9a0bdc34b1 to your computer and use it in GitHub Desktop.
class LoginLogicUnitTest extends Specification {
private CandidateLoginLogic logic
def setup(){
logic = new CandidateLoginLogic()
// Mocking autowired methods
OriginalTimeManager timeManager = Mock()
logic.metaClass.setAttribute(logic, "timeManager", timeManager)
}
@Unroll
def "IsAfterServiceGraduateDate currentDate: #currentDate"() {
setup:
// stubbing mocked test's retun value
logic.timeManager.getCurrentLocalDate() >> currentDate
when:
def result = logic.isAfterServiceGraduateDate(graduateYear)
then:
result == flg
where:
// In this case the test are executed three times
// Every tests are executed with the assigned values below
currentDate | graduateYear | flg
LocalDate.of(2018, 3, 31) | 2018 | false
LocalDate.of(2018, 4, 1) | 2018 | true
LocalDate.of(2018, 4, 2) | 2018 | true
}
def "isAfterServiceGraduateDate NullPointerException throwability"() {
setup:
logic.timeManager.getCurrentLocalDate() >> LocalDate.of(2018, 4, 2)
when:
logic.isAfterServiceGraduateDate(null)
then:
thrown NullPointerException
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment