added additional error checking and unit test

This commit is contained in:
mnbogner
2025-03-25 16:50:01 -07:00
committed by Torsten Grote
parent 17125ffcc9
commit 26e1e1f183
2 changed files with 36 additions and 11 deletions

View File

@@ -20,6 +20,7 @@ package org.fdroid.fdroid;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import android.content.Context;
@@ -35,6 +36,7 @@ import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.shadows.ShadowLog;
import java.util.HashMap;
import java.util.Map;
@RunWith(RobolectricTestRunner.class)
@@ -157,4 +159,16 @@ public class PreferencesTest {
assertNotEquals(Long.parseLong(defaults.getString(Preferences.PREF_KEEP_CACHE_TIME, null)),
Preferences.get().getKeepCacheTime());
}
@Test
public void testMirrorErrorMethods() {
Preferences.setupForTests(CONTEXT);
Preferences preferences = Preferences.get();
// serialize an empty map
preferences.setMirrorErrorData(new HashMap<>(0));
HashMap<String, Integer> result = preferences.getMirrorErrorData();
// deserializing should return an empty map without throwing any exceptions
assertNotNull(result);
assertEquals(result.size(), 0);
}
}