TestPreferenceManager.java 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package com.nextcloud.client.preferences;
  2. import android.content.Context;
  3. import android.content.SharedPreferences;
  4. import org.junit.Before;
  5. import org.junit.Test;
  6. import org.junit.runner.RunWith;
  7. import org.mockito.InOrder;
  8. import org.mockito.Mock;
  9. import static org.mockito.Mockito.*;
  10. import org.mockito.junit.MockitoJUnitRunner;
  11. @RunWith(MockitoJUnitRunner.class)
  12. public class TestPreferenceManager {
  13. @Mock
  14. private Context testContext;
  15. @Mock
  16. private SharedPreferences sharedPreferences;
  17. @Mock
  18. private SharedPreferences.Editor editor;
  19. private PreferenceManager appPreferences;
  20. @Before
  21. public void setUp() {
  22. when(editor.remove(anyString())).thenReturn(editor);
  23. when(sharedPreferences.edit()).thenReturn(editor);
  24. appPreferences = new PreferenceManager(testContext, sharedPreferences);
  25. }
  26. @Test
  27. public void removeLegacyPreferences() {
  28. appPreferences.removeLegacyPreferences();
  29. InOrder inOrder = inOrder(editor);
  30. inOrder.verify(editor).remove("instant_uploading");
  31. inOrder.verify(editor).remove("instant_video_uploading");
  32. inOrder.verify(editor).remove("instant_upload_path");
  33. inOrder.verify(editor).remove("instant_upload_path_use_subfolders");
  34. inOrder.verify(editor).remove("instant_upload_on_wifi");
  35. inOrder.verify(editor).remove("instant_upload_on_charging");
  36. inOrder.verify(editor).remove("instant_video_upload_path");
  37. inOrder.verify(editor).remove("instant_video_upload_path_use_subfolders");
  38. inOrder.verify(editor).remove("instant_video_upload_on_wifi");
  39. inOrder.verify(editor).remove("instant_video_uploading");
  40. inOrder.verify(editor).remove("instant_video_upload_on_charging");
  41. inOrder.verify(editor).remove("prefs_instant_behaviour");
  42. inOrder.verify(editor).apply();
  43. }
  44. }