Created
February 5, 2023 21:49
-
-
Save ArunYogeshwaran/369546c0f7aef75e085c1b286d9e386f to your computer and use it in GitHub Desktop.
An example of using the public APIs to test
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 | |
} | |
// | |
private fun processReferral(userId: String) { | |
// Processes 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
// 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() | |
} |
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() | |
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