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/25f7c7d4d36e613182faa94d8c663c58 to your computer and use it in GitHub Desktop.
Save IvanShafran/25f7c7d4d36e613182faa94d8c663c58 to your computer and use it in GitHub Desktop.
public class ShowRateUsLogicTest {
// property declaration is skipped
@Before public void setUp() {
final Context mockedContext = new SPMockBuilder().createContext();
rateUsPreferences = new RateUsPreferencesImpl(mockedContext);
buyPreferences = new BuyPreferencesImpl(mockedContext);
time = Mockito.mock(Time.class);
showRateUsLogic = new ShowRateUsLogic(rateUsPreferences, buyPreferences, time);
}
// first test code leaves the same
// second test code changed only in time mocking
@Test public void onThreeClicksAndItShouldShow() {
// ...
// set current time to be 90 days after first show
Mockito.when(time.getCurrentTimeMillis()).thenReturn(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