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
fun playArtist(artist: Artist) { | |
if (artist != Artist.TAYLOR_SWIFT) { | |
return IllegalArgException() | |
} | |
addToRecentlyPlayed(artist) | |
player.play(artist.getRandomSong()) | |
} |
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
@Test | |
fun `refer friend with new referral verify referral successful`() { | |
val friendReferral = getInstance() | |
friendReferral.referFriend("testUserId", getStaleReferral()) | |
assertThat(referralList.contains("testUserId")).isTrue() | |
} | |
@Test | |
fun `refer friend with stale referral verify referral failue`() { | |
val friendReferral = getInstance() |
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
// The condition here is that the private method is made public or package-private using the `VisibleForTesting` annotation. | |
@Test | |
fun `is referral valid with new referral expected value is true`() { | |
val friendReferral = getInstance() | |
asserTrue(friendReferral.isReferralValid(…)) | |
} | |
// The condition here is that the private method is made public or package-private using the `VisibleForTesting` annotation. | |
@Test | |
fun `process referral valid with new referral verify referral successful`() { |
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
fun referFriend(userId: String, referral: Referral) { | |
if (isReferralValid(referral)) { | |
processReferral(userId) | |
} | |
} | |
private fun isReferralValid(referral: Referral): Boolean { | |
// Checks the validity of the referral. | |
} |
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
// Unit under test. | |
fun toggleFavoriteForJob(job: Job) { | |
if (job.isFavorite) { | |
cache.unfavorite(job) | |
} else { | |
cache.favorite(job) | |
} | |
} | |
// A unit test using interaction testing. |
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
// A test with relevant details abstracted out. | |
@Test | |
fun `get ML recommended jobs with new user expect predefined list`() { | |
// Test arrangements and setup. | |
val engine = new RecommendationEngine(getEnvDetails(), getLocalInfo(), getSessionProperties()) | |
val jobs = engine.getJobs(getTestUserInfo()) | |
assertThat(jobs).isEqualTo(expectedJobs) | |
} |
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
// A test with relevant details in the test itself. | |
@Test | |
fun `get ML recommended jobs with new user expect predefined list`() { | |
// Test arrangements and setup. | |
val engine = getRecommendationEngine() | |
val jobs = engine.getJobs(new User(UserStatus.FAIRLY_NEW, "testId", "Test User Name")) | |
assertThat(jobs).isEqualTo(expectedJobs) | |
} |
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
// Unit under test. | |
fun fetchJobs(user: User) : List<Job> { | |
if (user.isRegistered()) { | |
return emptyList() | |
} else { | |
val jobs = jobsApi.getJobs(user) | |
return jobs | |
} | |
} | |
// A test with a non-descriptive name. |
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
fun playArtist(artist: Artist) { | |
if (artist != Artist.TAYLOR_SWIFT) { | |
return IllegalArgException() | |
} | |
addToRecentlyPlayed(artist) | |
player.play(artist.getRandomSong()) | |
} |
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
fun referFriend(userId: String, referral: Referral) { | |
if (isReferralValid(referral)) { | |
processReferral(userId) | |
} | |
} | |
private fun isReferralValid(referral: Referral): Boolean { | |
// Checks the validity of the referral | |
} |
NewerOlder