21
21
22
22
import pub .devrel .easypermissions .testhelper .TestActivity ;
23
23
import pub .devrel .easypermissions .testhelper .TestFragment ;
24
- import pub .devrel .easypermissions .testhelper .TestSupportActivity ;
24
+ import pub .devrel .easypermissions .testhelper .TestAppCompatActivity ;
25
+ import pub .devrel .easypermissions .testhelper .TestSupportFragmentActivity ;
25
26
26
27
import static com .google .common .truth .Truth .assertThat ;
27
28
import static org .mockito .Mockito .times ;
@@ -39,10 +40,12 @@ public class EasyPermissionsLowApiTest {
39
40
Manifest .permission .READ_SMS , Manifest .permission .ACCESS_FINE_LOCATION };
40
41
41
42
private TestActivity spyActivity ;
42
- private TestSupportActivity spySupportActivity ;
43
+ private TestSupportFragmentActivity spySupportFragmentActivity ;
44
+ private TestAppCompatActivity spyAppCompatActivity ;
43
45
private TestFragment spyFragment ;
44
46
private ActivityController <TestActivity > activityController ;
45
- private ActivityController <TestSupportActivity > supportActivityController ;
47
+ private ActivityController <TestSupportFragmentActivity > supportFragmentActivityController ;
48
+ private ActivityController <TestAppCompatActivity > appCompatActivityController ;
46
49
private SupportFragmentController <TestFragment > supportController ;
47
50
@ Captor
48
51
private ArgumentCaptor <Integer > integerCaptor ;
@@ -83,12 +86,23 @@ public void shouldCallbackOnPermissionGranted_whenRequestFromActivity() {
83
86
// ------ From Support Activity ------
84
87
85
88
@ Test
86
- public void shouldCallbackOnPermissionGranted_whenRequestFromSupportActivity () {
87
- EasyPermissions .requestPermissions (spySupportActivity , RATIONALE , TestSupportActivity .REQUEST_CODE , ALL_PERMS );
89
+ public void shouldCallbackOnPermissionGranted_whenRequestFromSupportFragmentActivity () {
90
+ EasyPermissions .requestPermissions (spySupportFragmentActivity , RATIONALE , TestSupportFragmentActivity .REQUEST_CODE , ALL_PERMS );
88
91
89
- verify (spySupportActivity , times (1 ))
92
+ verify (spySupportFragmentActivity , times (1 ))
90
93
.onPermissionsGranted (integerCaptor .capture (), listCaptor .capture ());
91
- assertThat (integerCaptor .getValue ()).isEqualTo (TestSupportActivity .REQUEST_CODE );
94
+ assertThat (integerCaptor .getValue ()).isEqualTo (TestSupportFragmentActivity .REQUEST_CODE );
95
+ assertThat (listCaptor .getValue ()).containsAllIn (ALL_PERMS );
96
+ }
97
+
98
+
99
+ @ Test
100
+ public void shouldCallbackOnPermissionGranted_whenRequestFromAppCompatActivity () {
101
+ EasyPermissions .requestPermissions (spyAppCompatActivity , RATIONALE , TestAppCompatActivity .REQUEST_CODE , ALL_PERMS );
102
+
103
+ verify (spyAppCompatActivity , times (1 ))
104
+ .onPermissionsGranted (integerCaptor .capture (), listCaptor .capture ());
105
+ assertThat (integerCaptor .getValue ()).isEqualTo (TestAppCompatActivity .REQUEST_CODE );
92
106
assertThat (listCaptor .getValue ()).containsAllIn (ALL_PERMS );
93
107
}
94
108
@@ -105,19 +119,22 @@ public void shouldCallbackOnPermissionGranted_whenRequestFromFragment() {
105
119
private void setUpActivityAndFragment () {
106
120
activityController = Robolectric .buildActivity (TestActivity .class )
107
121
.create ().start ().resume ();
108
- supportActivityController = Robolectric .buildActivity (TestSupportActivity .class )
122
+ supportFragmentActivityController = Robolectric .buildActivity (TestSupportFragmentActivity .class )
123
+ .create ().start ().resume ();
124
+ appCompatActivityController = Robolectric .buildActivity (TestAppCompatActivity .class )
109
125
.create ().start ().resume ();
110
126
supportController = SupportFragmentController .of (new TestFragment ())
111
127
.create ().start ().resume ();
112
128
113
129
spyActivity = Mockito .spy (activityController .get ());
114
- spySupportActivity = Mockito .spy (supportActivityController .get ());
130
+ spySupportFragmentActivity = Mockito .spy (supportFragmentActivityController .get ());
131
+ spyAppCompatActivity = Mockito .spy (appCompatActivityController .get ());
115
132
spyFragment = Mockito .spy (supportController .get ());
116
133
}
117
134
118
135
private void tearDownActivityAndFragment () {
119
136
activityController .pause ().stop ().destroy ();
120
- supportActivityController .pause ().stop ().destroy ();
137
+ appCompatActivityController .pause ().stop ().destroy ();
121
138
supportController .pause ().stop ().destroy ();
122
139
}
123
140
}
0 commit comments