Last active
November 21, 2018 19:22
-
-
Save BumpeiShimada/177ba4cb2aa22db5bf84cb9a0bdc34b1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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