diff --git a/easypermissions/src/test/java/pub/devrel/easypermissions/EasyPermissionsLowApiTest.java b/easypermissions/src/test/java/pub/devrel/easypermissions/EasyPermissionsLowApiTest.java index e40d107..9a87954 100644 --- a/easypermissions/src/test/java/pub/devrel/easypermissions/EasyPermissionsLowApiTest.java +++ b/easypermissions/src/test/java/pub/devrel/easypermissions/EasyPermissionsLowApiTest.java @@ -22,6 +22,7 @@ import pub.devrel.easypermissions.testhelper.TestActivity; import pub.devrel.easypermissions.testhelper.TestFragment; import pub.devrel.easypermissions.testhelper.TestAppCompatActivity; +import pub.devrel.easypermissions.testhelper.TestSupportFragmentActivity; import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.times; @@ -39,9 +40,11 @@ public class EasyPermissionsLowApiTest { Manifest.permission.READ_SMS, Manifest.permission.ACCESS_FINE_LOCATION}; private TestActivity spyActivity; + private TestSupportFragmentActivity spySupportFragmentActivity; private TestAppCompatActivity spyAppCompatActivity; private TestFragment spyFragment; private ActivityController activityController; + private ActivityController supportFragmentActivityController; private ActivityController appCompatActivityController; private SupportFragmentController supportController; @Captor @@ -83,7 +86,18 @@ public void shouldCallbackOnPermissionGranted_whenRequestFromActivity() { // ------ From Support Activity ------ @Test - public void shouldCallbackOnPermissionGranted_whenRequestFromSupportActivity() { + public void shouldCallbackOnPermissionGranted_whenRequestFromSupportFragmentActivity() { + EasyPermissions.requestPermissions(spySupportFragmentActivity, RATIONALE, TestSupportFragmentActivity.REQUEST_CODE, ALL_PERMS); + + verify(spySupportFragmentActivity, times(1)) + .onPermissionsGranted(integerCaptor.capture(), listCaptor.capture()); + assertThat(integerCaptor.getValue()).isEqualTo(TestSupportFragmentActivity.REQUEST_CODE); + assertThat(listCaptor.getValue()).containsAllIn(ALL_PERMS); + } + + + @Test + public void shouldCallbackOnPermissionGranted_whenRequestFromAppCompatActivity() { EasyPermissions.requestPermissions(spyAppCompatActivity, RATIONALE, TestAppCompatActivity.REQUEST_CODE, ALL_PERMS); verify(spyAppCompatActivity, times(1)) @@ -105,12 +119,15 @@ public void shouldCallbackOnPermissionGranted_whenRequestFromFragment() { private void setUpActivityAndFragment() { activityController = Robolectric.buildActivity(TestActivity.class) .create().start().resume(); + supportFragmentActivityController = Robolectric.buildActivity(TestSupportFragmentActivity.class) + .create().start().resume(); appCompatActivityController = Robolectric.buildActivity(TestAppCompatActivity.class) .create().start().resume(); supportController = SupportFragmentController.of(new TestFragment()) .create().start().resume(); spyActivity = Mockito.spy(activityController.get()); + spySupportFragmentActivity = Mockito.spy(supportFragmentActivityController.get()); spyAppCompatActivity = Mockito.spy(appCompatActivityController.get()); spyFragment = Mockito.spy(supportController.get()); }