Skip to content

Instantly share code, notes, and snippets.

@IvanShafran
Last active August 22, 2019 10:41
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/fd8e1e1be54168cc486ef8ae03271435 to your computer and use it in GitHub Desktop.
Save IvanShafran/fd8e1e1be54168cc486ef8ae03271435 to your computer and use it in GitHub Desktop.
public class ShowRateUsLogicTest {
// property declaration is skipped
@Before public void setUp() {
rateUsPreferences = new RateUsPreferencesMock();
buyPreferences = new BuyPreferencesMock();
time = new TimeMock();
showRateUsLogic = new ShowRateUsLogic(rateUsPreferences, buyPreferences, time);
}
@Test public void onFirstCheckAndOneClickItShouldNotShow() {
buyPreferences.incrementBuyCount();
Assert.assertFalse(showRateUsLogic.shouldShowRateUs());
}
@Test public void onThreeClicksAndItShouldShow() {
// clicked three times
buyPreferences.incrementBuyCount();
buyPreferences.incrementBuyCount();
buyPreferences.incrementBuyCount();
// set first dialog show time
final Calendar calendar = Calendar.getInstance();
calendar.set(2019, Calendar.JULY, 7);
rateUsPreferences.setLastShownTimeMillis(calendar.getTimeInMillis());
// set current time to be 90 days after first show
time.setCurrentTimeMillis(calendar.getTimeInMillis() + TimeUnit.DAYS.toMillis(90));
Assert.assertTrue(showRateUsLogic.shouldShowRateUs());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment