@Test public void shouldSendSdkHeartBeat_answerIsYes() { long currentTime = System.currentTimeMillis(); assertThat(heartBeatInfoStorage.shouldSendSdkHeartBeat(testSdk, 1)).isTrue(); assertThat(sharedPreferences.getLong(testSdk, -1)).isEqualTo(1); assertThat(heartBeatInfoStorage.shouldSendSdkHeartBeat(testSdk, currentTime)).isTrue(); assertThat(sharedPreferences.getLong(testSdk, -1)).isEqualTo(currentTime); }
synchronized boolean shouldSendSdkHeartBeat(String heartBeatTag, long millis) { if (sharedPreferences.contains(heartBeatTag)) { long timeElapsed = millis - sharedPreferences.getLong(heartBeatTag, -1); if (timeElapsed >= (long) 1000 * 60 * 60 * 24) { sharedPreferences.edit().putLong(heartBeatTag, millis).apply(); return true; } return false; } else { sharedPreferences.edit().putLong(heartBeatTag, millis).apply(); return true; } }
HeartBeatInfoStorage { synchronized boolean shouldSendSdkHeartBeat(String heartBeatTag, long millis) { if (sharedPreferences.contains(heartBeatTag)) { long timeElapsed = millis - sharedPreferences.getLong(heartBeatTag, -1); if (timeElapsed >= (long) 1000 * 60 * 60 * 24) { sharedPreferences.edit().putLong(heartBeatTag, millis).apply(); return true; } return false; } else { sharedPreferences.edit().putLong(heartBeatTag, millis).apply(); return true; } } }
HeartBeatInfoStorage { synchronized boolean shouldSendSdkHeartBeat(String heartBeatTag, long millis) { if (sharedPreferences.contains(heartBeatTag)) { long timeElapsed = millis - sharedPreferences.getLong(heartBeatTag, -1); if (timeElapsed >= (long) 1000 * 60 * 60 * 24) { sharedPreferences.edit().putLong(heartBeatTag, millis).apply(); return true; } return false; } else { sharedPreferences.edit().putLong(heartBeatTag, millis).apply(); return true; } } private  HeartBeatInfoStorage(Context applicationContext); @VisibleForTesting @RestrictTo(RestrictTo.Scope.TESTS)  HeartBeatInfoStorage(SharedPreferences preferences); }
HeartBeatInfoStorage { synchronized boolean shouldSendSdkHeartBeat(String heartBeatTag, long millis) { if (sharedPreferences.contains(heartBeatTag)) { long timeElapsed = millis - sharedPreferences.getLong(heartBeatTag, -1); if (timeElapsed >= (long) 1000 * 60 * 60 * 24) { sharedPreferences.edit().putLong(heartBeatTag, millis).apply(); return true; } return false; } else { sharedPreferences.edit().putLong(heartBeatTag, millis).apply(); return true; } } private  HeartBeatInfoStorage(Context applicationContext); @VisibleForTesting @RestrictTo(RestrictTo.Scope.TESTS)  HeartBeatInfoStorage(SharedPreferences preferences);  }
HeartBeatInfoStorage { synchronized boolean shouldSendSdkHeartBeat(String heartBeatTag, long millis) { if (sharedPreferences.contains(heartBeatTag)) { long timeElapsed = millis - sharedPreferences.getLong(heartBeatTag, -1); if (timeElapsed >= (long) 1000 * 60 * 60 * 24) { sharedPreferences.edit().putLong(heartBeatTag, millis).apply(); return true; } return false; } else { sharedPreferences.edit().putLong(heartBeatTag, millis).apply(); return true; } } private  HeartBeatInfoStorage(Context applicationContext); @VisibleForTesting @RestrictTo(RestrictTo.Scope.TESTS)  HeartBeatInfoStorage(SharedPreferences preferences);   }