Skip to content

Instantly share code, notes, and snippets.

@IvanShafran
Last active August 22, 2019 10:40
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 IvanShafran/6d52c932106b6ef6fa84830af4631e40 to your computer and use it in GitHub Desktop.
Save IvanShafran/6d52c932106b6ef6fa84830af4631e40 to your computer and use it in GitHub Desktop.
class ShowRateUsLogicTest {
// property declaration and setup are skipped
private fun prepareConditions(
buyClickedTimes: Int = 0,
isNeverShownAgainClicked: Boolean = false,
isRateNowClicked: Boolean = false,
lastShownTimeMillis: Long = 0,
currentTimeMillis: Long = 0
) {
repeat(buyClickedTimes) { buyPreferences.incrementBuyCount() }
if (isNeverShownAgainClicked) rateUsPreferences.setNeverShownAgainClicked()
if (isRateNowClicked) rateUsPreferences.setRateNowClickedClicked()
rateUsPreferences.setLastShownTimeMillis(lastShownTimeMillis)
whenever(time.getCurrentTimeMillis()).thenReturn(currentTimeMillis)
}
@Test fun onFirstCheckAndOneClickItShouldNotShow() {
prepareConditions(buyClickedTimes = 1)
Assert.assertFalse(showRateUsLogic.shouldShowRateUs())
}
@Test fun onThreeClicksAndItShouldShow() {
prepareConditions(
buyClickedTimes = 3,
lastShownTimeMillis = SOME_DAY_IN_MILLIS,
currentTimeMillis = SOME_DAY_IN_MILLIS + MORE_THAN_TWO_MONTHS
)
Assert.assertTrue(showRateUsLogic.shouldShowRateUs())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment