-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathPreferencesHandlerTest.java
More file actions
76 lines (56 loc) · 2.17 KB
/
PreferencesHandlerTest.java
File metadata and controls
76 lines (56 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package de.dotwee.micropinner.tools;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import androidx.test.rule.ActivityTestRule;
import androidx.test.runner.AndroidJUnit4;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import de.dotwee.micropinner.view.MainDialog;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/**
* Created by lukas on 11.08.2016.
*/
@RunWith(AndroidJUnit4.class)
public class PreferencesHandlerTest {
/**
* Preferred JUnit 4 mechanism of specifying the
* activity to be launched before each test
*/
@Rule
public ActivityTestRule<MainDialog> activityTestRule =
new ActivityTestRule<>(MainDialog.class);
private PreferencesHandler preferencesHandler;
@Before
public void setUp() {
// Removes all previous preferences entries
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(activityTestRule.getActivity());
sharedPreferences.edit().clear().apply();
preferencesHandler = PreferencesHandler.getInstance(activityTestRule.getActivity());
}
@Test
public void testIsFirstUse() throws Exception {
// should be enabled since preferences has been cleared
assertTrue(preferencesHandler.isFirstUse());
}
@Test
public void testIsAdvancedUsed() throws Exception {
// should be disabled by default
assertFalse(preferencesHandler.isAdvancedUsed());
// tell preference handler to enable the advanced layout
preferencesHandler.setAdvancedUse(true);
// should be enabled now
assertTrue(preferencesHandler.isAdvancedUsed());
}
@Test
public void testIsNotificationActionsEnabled() throws Exception {
// should be disabled by default
assertFalse(preferencesHandler.isNotificationActionsEnabled());
// tell preference handler to enable the advanced layout
preferencesHandler.setNotificationActionsEnabled(true);
// should be enabled now
assertTrue(preferencesHandler.isNotificationActionsEnabled());
}
}