@Test public void onStart_isSuccess() { Context context = RuntimeEnvironment.application.getApplicationContext(); RateThisApp.onStart(context); SharedPreferences sharedPreferences = RuntimeEnvironment.application.getSharedPreferences( PREF_NAME, Context.MODE_PRIVATE); // check if install date is stored long expectedInstallDate = 0L; PackageManager packMan = context.getPackageManager(); try { PackageInfo pkgInfo = packMan.getPackageInfo(context.getPackageName(), 0); expectedInstallDate = new Date(pkgInfo.firstInstallTime).getTime(); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } Assert.assertEquals(expectedInstallDate, sharedPreferences.getLong(KEY_INSTALL_DATE, 0L)); // check if launch time is incremented Assert.assertEquals(1, sharedPreferences.getInt(KEY_LAUNCH_TIMES, 0)); }
@Test public void shouldRateDialogIfNeeded_LaunchTimeIsCorrect() { Context context = RuntimeEnvironment.application.getApplicationContext(); RateThisApp.init(new RateThisApp.Config(1, 3)); RateThisApp.onStart(context); Assert.assertFalse(RateThisApp.shouldShowRateDialog()); RateThisApp.onStart(context); Assert.assertFalse(RateThisApp.shouldShowRateDialog()); RateThisApp.onStart(context); Assert.assertTrue(RateThisApp.shouldShowRateDialog()); RateThisApp.onStart(context); Assert.assertTrue(RateThisApp.shouldShowRateDialog()); }
@Test public void getLaunchCount_IsCorrect() { Context context = RuntimeEnvironment.application.getApplicationContext(); Assert.assertEquals(0, RateThisApp.getLaunchCount(context)); RateThisApp.onStart(context); Assert.assertEquals(1, RateThisApp.getLaunchCount(context)); RateThisApp.onStart(context); Assert.assertEquals(2, RateThisApp.getLaunchCount(context)); }