Skip to content

Instantly share code, notes, and snippets.

@ArunYogeshwaran
Created February 5, 2023 21:49
Show Gist options
  • Save ArunYogeshwaran/369546c0f7aef75e085c1b286d9e386f to your computer and use it in GitHub Desktop.
Save ArunYogeshwaran/369546c0f7aef75e085c1b286d9e386f to your computer and use it in GitHub Desktop.
An example of using the public APIs to test
fun referFriend(userId: String, referral: Referral) {
if (isReferralValid(referral)) {
processReferral(userId)
}
}
private fun isReferralValid(referral: Referral): Boolean {
// Checks the validity of the referral
}
//
private fun processReferral(userId: String) {
// Processes the referral
}
// The condition here is that the private method is made pubic or package-private using 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 pubic or package-private using VisibleForTesting annotation
@Test
fun `process referral valid with new referral verify referral successful`() {
val friendReferral = getInstance()
friendReferral.processReferral("testUserId")
assertThat(referralList.contains("testUserId")).isTrue()
}
@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()
friendReferral.referFriend("testUserId", getStaleReferral())
assertThat(referralList.contains("testUserId")).isFalse()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment