15
15
16
16
import java .util .List ;
17
17
18
+ import androidx .annotation .NonNull ;
18
19
import androidx .test .platform .app .InstrumentationRegistry ;
19
20
import androidx .test .uiautomator .By ;
20
21
import androidx .test .uiautomator .Direction ;
29
30
import static org .hamcrest .CoreMatchers .equalTo ;
30
31
import static org .hamcrest .CoreMatchers .is ;
31
32
import static org .hamcrest .CoreMatchers .not ;
33
+ import static org .hamcrest .MatcherAssert .assertThat ;
32
34
import static org .hamcrest .core .IsNull .notNullValue ;
33
35
34
36
/**
39
41
@ RunWith (org .junit .runners .Suite .class )
40
42
@ SuiteClasses ({
41
43
TestRepositories .class ,
42
- TestRepository .class ,
43
44
TestProfile .class
44
45
})
45
46
public class TestSuite {
@@ -74,18 +75,18 @@ private String getLauncherPackageName() {
74
75
}
75
76
76
77
/** launches the blueprint application */
77
- void startTestActivity (Context context , String className ){
78
+ void startTestActivity (@ NonNull Context context , @ NonNull String className ){
78
79
79
80
/* initialize UiDevice */
80
81
this .mDevice = UiDevice .getInstance (InstrumentationRegistry .getInstrumentation ());
81
- Assert . assertThat (this .mDevice , notNullValue ());
82
+ assertThat (this .mDevice , notNullValue ());
82
83
83
84
/* start from the home screen */
84
85
this .mDevice .pressHome ();
85
86
86
87
/* obtain the launcher package */
87
88
String launcherPackage = getLauncherPackageName ();
88
- Assert . assertThat (launcherPackage , notNullValue ());
89
+ assertThat (launcherPackage , notNullValue ());
89
90
90
91
/* wait for launcher */
91
92
this .mDevice .wait (Until .hasObject (By .pkg (launcherPackage ).depth (0 )), LAUNCH_TIMEOUT );
@@ -94,7 +95,7 @@ void startTestActivity(Context context, String className){
94
95
this .packageName = context .getPackageName ().replace (".test" , "" );
95
96
Intent intent = context .getPackageManager ().getLaunchIntentForPackage (this .packageName );
96
97
97
- if (intent != null ) {
98
+ if (intent != null ) {
98
99
99
100
intent .setComponent (new ComponentName (this .packageName , this .packageName .replace ("debug" , "activity." + className )));
100
101
intent .addFlags (Intent .FLAG_ACTIVITY_CLEAR_TASK | Intent .FLAG_ACTIVITY_NEW_TASK );
@@ -115,24 +116,24 @@ protected UiObject2 getItemById(String resourceId) {
115
116
return this .mDevice .findObject (By .res (this .packageName , resourceId ));
116
117
}
117
118
118
- /** it clicks spinner items by index */
119
+ /** It clicks spinner items by index */
119
120
public void clickSpinnerItem (String spinnerName , int itemIndex ) {
120
121
121
122
UiObject2 spinner = this .mDevice .findObject (By .res (this .packageName , spinnerName ));
122
- Assert . assertThat (spinner .isClickable (), is (equalTo (true )));
123
+ assertThat (spinner .isClickable (), is (equalTo (true )));
123
124
spinner .click ();
124
125
sleep (2000 );
125
126
126
127
List <UiObject2 > items = this .mDevice .findObjects (By .res ("android:id/text1" ));
127
- Assert . assertThat (items .size () > itemIndex , is (equalTo (true )));
128
+ assertThat (items .size () > itemIndex , is (equalTo (true )));
128
129
129
130
UiObject2 item = items .get (itemIndex );
130
- Assert . assertThat (item .isClickable (), is (equalTo (true )));
131
+ assertThat (item .isClickable (), is (equalTo (true )));
131
132
item .click (500 );
132
133
sleep (2000 );
133
134
}
134
135
135
- /** it clicks the "Allow" button on a permission request dialog */
136
+ /** It clicks the "Allow" button on a permission request dialog */
136
137
void grantPermission () {
137
138
if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .M ) {
138
139
UiObject textAllow = this .mDevice .findObject (new UiSelector ().text ("Allow" ));
@@ -147,7 +148,7 @@ void grantPermission() {
147
148
}
148
149
149
150
void flingUp (UiObject2 view , int speed , int pause ) {
150
- Assert . assertThat (view , not (equalTo (null )));
151
+ assertThat (view , not (equalTo (null )));
151
152
try {
152
153
view .fling (Direction .DOWN , speed );
153
154
} catch (StaleObjectException e ) {
0 commit comments