1
1
package net .osmtracker .layouts ;
2
2
3
- import android .Manifest ;
4
- import androidx .test .rule .ActivityTestRule ;
5
- import androidx .test .rule .GrantPermissionRule ;
6
-
7
- import net .osmtracker .R ;
8
- import net .osmtracker .activity .ButtonsPresets ;
9
- import net .osmtracker .activity .Preferences ;
10
- import net .osmtracker .util .CustomLayoutsUtils ;
11
- import net .osmtracker .util .TestUtils ;
12
-
13
- import org .junit .Rule ;
14
- import org .junit .Test ;
15
-
16
- import java .io .IOException ;
17
- import java .util .ArrayList ;
18
-
19
3
import static androidx .test .espresso .Espresso .onView ;
20
4
import static androidx .test .espresso .action .ViewActions .click ;
21
5
import static androidx .test .espresso .action .ViewActions .longClick ;
26
10
import static net .osmtracker .util .TestUtils .getStringResource ;
27
11
import static net .osmtracker .util .TestUtils .injectMockLayout ;
28
12
import static net .osmtracker .util .TestUtils .listFiles ;
13
+ import static org .apache .commons .io .FileUtils .deleteDirectory ;
29
14
import static org .hamcrest .Matchers .equalToIgnoringCase ;
30
15
import static org .junit .Assert .assertFalse ;
31
- import static org .apache .commons .io .FileUtils .deleteDirectory ;
32
16
17
+ import android .Manifest ;
18
+
19
+ import androidx .test .ext .junit .rules .ActivityScenarioRule ;
20
+ import androidx .test .rule .GrantPermissionRule ;
21
+
22
+ import net .osmtracker .R ;
23
+ import net .osmtracker .activity .ButtonsPresets ;
24
+ import net .osmtracker .activity .Preferences ;
25
+ import net .osmtracker .util .CustomLayoutsUtils ;
26
+
27
+ import org .junit .Before ;
28
+ import org .junit .Rule ;
29
+ import org .junit .Test ;
30
+
31
+ import java .io .IOException ;
32
+ import java .util .ArrayList ;
33
33
34
34
public class DeleteLayoutTest {
35
35
36
36
@ Rule
37
37
public GrantPermissionRule storagePermission = GrantPermissionRule .grant (Manifest .permission .WRITE_EXTERNAL_STORAGE );
38
38
39
39
@ Rule
40
- public ActivityTestRule <ButtonsPresets > mRule = new ActivityTestRule (ButtonsPresets .class ) {
41
- @ Override
42
- protected void beforeActivityLaunched () {
43
- //Makes sure that only the mock layout exists
40
+ public ActivityScenarioRule <ButtonsPresets > mRule = new ActivityScenarioRule <>(ButtonsPresets .class );
41
+
42
+ private static String layoutName = "mock" ;
43
+ private static String ISOLanguageCode = "es" ;
44
+
45
+ @ Before
46
+ public void setup () {
47
+ // Makes sure that only the mock layout exists
44
48
try {
45
49
deleteDirectory (getLayoutsDirectory ());
46
50
injectMockLayout (layoutName , ISOLanguageCode );
47
-
48
51
} catch (IOException e ) {
49
52
e .printStackTrace ();
50
53
}
51
54
}
52
- };
53
-
54
- private static String layoutName = "mock" ;
55
- private static String ISOLanguageCode = "es" ;
56
55
57
56
/**
58
57
* Assumes being in the ButtonsPresets activity
59
58
* Deletes the layout with the received name
60
59
*/
61
- private void deleteLayout (String layoutName ){
60
+ private void deleteLayout (String layoutName ) {
62
61
onView (withText (layoutName )).perform (longClick ());
63
62
onView (withText (getStringResource (R .string .buttons_presets_context_menu_delete ))).perform (click ());
64
63
String textToMatch = getStringResource (R .string .buttons_presets_delete_positive_confirmation );
@@ -73,8 +72,7 @@ private void deleteLayout(String layoutName){
73
72
* - The icons directory is deleted
74
73
*/
75
74
@ Test
76
- public void layoutDeletionTest (){
77
-
75
+ public void layoutDeletionTest () {
78
76
deleteLayout (layoutName );
79
77
80
78
// Check the informative Toast is shown
@@ -91,7 +89,6 @@ public void layoutDeletionTest(){
91
89
assertFalse (filesAfterDeletion .contains (layoutFileName ));
92
90
93
91
// Check the icons folder was deleted
94
- assertFalse (filesAfterDeletion .contains (layoutName + Preferences .ICONS_DIR_SUFFIX ));
95
-
92
+ assertFalse (filesAfterDeletion .contains (layoutName + Preferences .ICONS_DIR_SUFFIX ));
96
93
}
97
94
}
0 commit comments