2121
2222import pub .devrel .easypermissions .testhelper .TestActivity ;
2323import 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 ;
2526
2627import static com .google .common .truth .Truth .assertThat ;
2728import static org .mockito .Mockito .times ;
@@ -39,10 +40,12 @@ public class EasyPermissionsLowApiTest {
3940 Manifest .permission .READ_SMS , Manifest .permission .ACCESS_FINE_LOCATION };
4041
4142 private TestActivity spyActivity ;
42- private TestSupportActivity spySupportActivity ;
43+ private TestSupportFragmentActivity spySupportFragmentActivity ;
44+ private TestAppCompatActivity spyAppCompatActivity ;
4345 private TestFragment spyFragment ;
4446 private ActivityController <TestActivity > activityController ;
45- private ActivityController <TestSupportActivity > supportActivityController ;
47+ private ActivityController <TestSupportFragmentActivity > supportFragmentActivityController ;
48+ private ActivityController <TestAppCompatActivity > appCompatActivityController ;
4649 private SupportFragmentController <TestFragment > supportController ;
4750 @ Captor
4851 private ArgumentCaptor <Integer > integerCaptor ;
@@ -83,12 +86,23 @@ public void shouldCallbackOnPermissionGranted_whenRequestFromActivity() {
8386 // ------ From Support Activity ------
8487
8588 @ 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 );
8891
89- verify (spySupportActivity , times (1 ))
92+ verify (spySupportFragmentActivity , times (1 ))
9093 .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 );
92106 assertThat (listCaptor .getValue ()).containsAllIn (ALL_PERMS );
93107 }
94108
@@ -105,19 +119,22 @@ public void shouldCallbackOnPermissionGranted_whenRequestFromFragment() {
105119 private void setUpActivityAndFragment () {
106120 activityController = Robolectric .buildActivity (TestActivity .class )
107121 .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 )
109125 .create ().start ().resume ();
110126 supportController = SupportFragmentController .of (new TestFragment ())
111127 .create ().start ().resume ();
112128
113129 spyActivity = Mockito .spy (activityController .get ());
114- spySupportActivity = Mockito .spy (supportActivityController .get ());
130+ spySupportFragmentActivity = Mockito .spy (supportFragmentActivityController .get ());
131+ spyAppCompatActivity = Mockito .spy (appCompatActivityController .get ());
115132 spyFragment = Mockito .spy (supportController .get ());
116133 }
117134
118135 private void tearDownActivityAndFragment () {
119136 activityController .pause ().stop ().destroy ();
120- supportActivityController .pause ().stop ().destroy ();
137+ appCompatActivityController .pause ().stop ().destroy ();
121138 supportController .pause ().stop ().destroy ();
122139 }
123140}
0 commit comments