Skip to content

Commit 351a810

Browse files
committed
Adding a test to verify that overwriting a Float with a Double works as intended.
1 parent 80c3540 commit 351a810

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

firebase-perf/src/test/java/com/google/firebase/perf/config/DeviceCacheManagerTest.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ public void getDouble_firebaseAppNotExist_returnsEmpty() {
224224
}
225225

226226
@Test
227-
public void setValueFloat_setTwice_canGetLatestValue() {
227+
public void setValueDouble_setTwice_canGetLatestValue() {
228228
deviceCacheManager.setContext(appContext);
229229
fakeScheduledExecutorService.runAll();
230230
deviceCacheManager.setValue("some_key", 1.01);
@@ -235,13 +235,27 @@ public void setValueFloat_setTwice_canGetLatestValue() {
235235
}
236236

237237
@Test
238-
public void setValueFloat_contextNotSet_returnsEmpty() {
238+
public void setValueDouble_wasSetAsFloat_canGetLatestValue() {
239+
deviceCacheManager.setContext(appContext);
240+
fakeScheduledExecutorService.runAll();
241+
242+
// Manually setting a Float to simulate it being cached from a previous SDK version.
243+
SharedPreferences sharedPreferences =
244+
appContext.getSharedPreferences(Constants.PREFS_NAME, Context.MODE_PRIVATE);
245+
sharedPreferences.edit().putFloat("some_key", 1.2f).apply();
246+
247+
deviceCacheManager.setValue("some_key", 0.01);
248+
assertThat(deviceCacheManager.getDouble("some_key").get()).isEqualTo(0.01);
249+
}
250+
251+
@Test
252+
public void setValueDouble_contextNotSet_returnsEmpty() {
239253
deviceCacheManager.setValue("some_key", 100.0);
240254
assertThat(deviceCacheManager.getDouble("some_key").isAvailable()).isFalse();
241255
}
242256

243257
@Test
244-
public void setValueFloat_keyIsNull_returnsFalse() {
258+
public void setValueDouble_keyIsNull_returnsFalse() {
245259
deviceCacheManager.setContext(appContext);
246260
fakeScheduledExecutorService.runAll();
247261
assertThat(deviceCacheManager.setValue(null, 10.0)).isFalse();

0 commit comments

Comments
 (0)