From e64510d0bbaa03411be26200a98992e811d9ab48 Mon Sep 17 00:00:00 2001 From: Sam Stern Date: Thu, 3 Jan 2019 10:55:38 -0800 Subject: [PATCH 1/3] Differentiate between FragmentActivity and AppCompatActivity Change-Id: I826cdfca1e5ed0c33ebcba7314e3a41ddd0913b0 --- ...> AppCompatActivityPermissionsHelper.java} | 5 +- .../helper/PermissionHelper.java | 6 +- .../EasyPermissionsLowApiTest.java | 12 +- .../easypermissions/EasyPermissionsTest.java | 117 +++++++++++------- ...tivity.java => TestAppCompatActivity.java} | 2 +- .../TestSupportFragmentActivity.java | 47 +++++++ 6 files changed, 129 insertions(+), 60 deletions(-) rename easypermissions/src/main/java/pub/devrel/easypermissions/helper/{FragmentActivityPermissionHelper.java => AppCompatActivityPermissionsHelper.java} (81%) rename easypermissions/src/test/java/pub/devrel/easypermissions/testhelper/{TestSupportActivity.java => TestAppCompatActivity.java} (95%) create mode 100644 easypermissions/src/test/java/pub/devrel/easypermissions/testhelper/TestSupportFragmentActivity.java diff --git a/easypermissions/src/main/java/pub/devrel/easypermissions/helper/FragmentActivityPermissionHelper.java b/easypermissions/src/main/java/pub/devrel/easypermissions/helper/AppCompatActivityPermissionsHelper.java similarity index 81% rename from easypermissions/src/main/java/pub/devrel/easypermissions/helper/FragmentActivityPermissionHelper.java rename to easypermissions/src/main/java/pub/devrel/easypermissions/helper/AppCompatActivityPermissionsHelper.java index eb8f4a5..3ed5f12 100644 --- a/easypermissions/src/main/java/pub/devrel/easypermissions/helper/FragmentActivityPermissionHelper.java +++ b/easypermissions/src/main/java/pub/devrel/easypermissions/helper/AppCompatActivityPermissionsHelper.java @@ -3,16 +3,15 @@ import android.content.Context; import android.support.annotation.NonNull; import android.support.v4.app.ActivityCompat; -import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; import android.support.v7.app.AppCompatActivity; /** * Permissions helper for {@link AppCompatActivity}. */ -class FragmentActivityPermissionHelper extends BaseSupportPermissionsHelper { +class AppCompatActivityPermissionsHelper extends BaseSupportPermissionsHelper { - public FragmentActivityPermissionHelper(FragmentActivity host) { + public AppCompatActivityPermissionsHelper(AppCompatActivity host) { super(host); } diff --git a/easypermissions/src/main/java/pub/devrel/easypermissions/helper/PermissionHelper.java b/easypermissions/src/main/java/pub/devrel/easypermissions/helper/PermissionHelper.java index 36875d1..460dbeb 100644 --- a/easypermissions/src/main/java/pub/devrel/easypermissions/helper/PermissionHelper.java +++ b/easypermissions/src/main/java/pub/devrel/easypermissions/helper/PermissionHelper.java @@ -6,7 +6,7 @@ import android.support.annotation.NonNull; import android.support.annotation.StyleRes; import android.support.v4.app.Fragment; -import android.support.v4.app.FragmentActivity; +import android.support.v7.app.AppCompatActivity; import java.util.List; @@ -23,8 +23,8 @@ public static PermissionHelper newInstance(Activity host) { return new LowApiPermissionsHelper<>(host); } - if (host instanceof FragmentActivity) - return new FragmentActivityPermissionHelper((FragmentActivity) host); + if (host instanceof AppCompatActivity) + return new AppCompatActivityPermissionsHelper((AppCompatActivity) host); else { return new ActivityPermissionHelper(host); } diff --git a/easypermissions/src/test/java/pub/devrel/easypermissions/EasyPermissionsLowApiTest.java b/easypermissions/src/test/java/pub/devrel/easypermissions/EasyPermissionsLowApiTest.java index 7fd93c4..6d2f9c8 100644 --- a/easypermissions/src/test/java/pub/devrel/easypermissions/EasyPermissionsLowApiTest.java +++ b/easypermissions/src/test/java/pub/devrel/easypermissions/EasyPermissionsLowApiTest.java @@ -21,7 +21,7 @@ import pub.devrel.easypermissions.testhelper.TestActivity; import pub.devrel.easypermissions.testhelper.TestFragment; -import pub.devrel.easypermissions.testhelper.TestSupportActivity; +import pub.devrel.easypermissions.testhelper.TestAppCompatActivity; import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.times; @@ -39,10 +39,10 @@ public class EasyPermissionsLowApiTest { Manifest.permission.READ_SMS, Manifest.permission.ACCESS_FINE_LOCATION}; private TestActivity spyActivity; - private TestSupportActivity spySupportActivity; + private TestAppCompatActivity spySupportActivity; private TestFragment spyFragment; private ActivityController activityController; - private ActivityController supportActivityController; + private ActivityController supportActivityController; private SupportFragmentController supportController; @Captor private ArgumentCaptor integerCaptor; @@ -84,11 +84,11 @@ public void shouldCallbackOnPermissionGranted_whenRequestFromActivity() { @Test public void shouldCallbackOnPermissionGranted_whenRequestFromSupportActivity() { - EasyPermissions.requestPermissions(spySupportActivity, RATIONALE, TestSupportActivity.REQUEST_CODE, ALL_PERMS); + EasyPermissions.requestPermissions(spySupportActivity, RATIONALE, TestAppCompatActivity.REQUEST_CODE, ALL_PERMS); verify(spySupportActivity, times(1)) .onPermissionsGranted(integerCaptor.capture(), listCaptor.capture()); - assertThat(integerCaptor.getValue()).isEqualTo(TestSupportActivity.REQUEST_CODE); + assertThat(integerCaptor.getValue()).isEqualTo(TestAppCompatActivity.REQUEST_CODE); assertThat(listCaptor.getValue()).containsAllIn(ALL_PERMS); } @@ -105,7 +105,7 @@ public void shouldCallbackOnPermissionGranted_whenRequestFromFragment() { private void setUpActivityAndFragment() { activityController = Robolectric.buildActivity(TestActivity.class) .create().start().resume(); - supportActivityController = Robolectric.buildActivity(TestSupportActivity.class) + supportActivityController = Robolectric.buildActivity(TestAppCompatActivity.class) .create().start().resume(); supportController = SupportFragmentController.of(new TestFragment()) .create().start().resume(); diff --git a/easypermissions/src/test/java/pub/devrel/easypermissions/EasyPermissionsTest.java b/easypermissions/src/test/java/pub/devrel/easypermissions/EasyPermissionsTest.java index 342f2a5..96fd926 100644 --- a/easypermissions/src/test/java/pub/devrel/easypermissions/EasyPermissionsTest.java +++ b/easypermissions/src/test/java/pub/devrel/easypermissions/EasyPermissionsTest.java @@ -28,8 +28,9 @@ import java.util.Collections; import pub.devrel.easypermissions.testhelper.TestActivity; +import pub.devrel.easypermissions.testhelper.TestAppCompatActivity; import pub.devrel.easypermissions.testhelper.TestFragment; -import pub.devrel.easypermissions.testhelper.TestSupportActivity; +import pub.devrel.easypermissions.testhelper.TestSupportFragmentActivity; import static com.google.common.truth.Truth.assertThat; import static junit.framework.Assert.fail; @@ -57,10 +58,12 @@ public class EasyPermissionsTest { PackageManager.PERMISSION_DENIED, PackageManager.PERMISSION_GRANTED}; private Application app; private TestActivity spyActivity; - private TestSupportActivity spySupportActivity; + private TestSupportFragmentActivity spySupportFragmentActivity; + private TestAppCompatActivity spyAppCompatActivity; private TestFragment spyFragment; private ActivityController activityController; - private ActivityController supportActivityController; + private ActivityController supportFragmentActivityController; + private ActivityController appCompatActivityController; private SupportFragmentController fragmentController; @Captor private ArgumentCaptor integerCaptor; @@ -254,75 +257,75 @@ public void shouldNotHavePermissionPermanentlyDenied_whenShowRationaleFromActivi } @Test - public void shouldCorrectlyCallback_whenOnRequestPermissionResultCalledFromSupportActivity() { - EasyPermissions.onRequestPermissionsResult(TestSupportActivity.REQUEST_CODE, ALL_PERMS, SMS_DENIED_RESULT, spySupportActivity); + public void shouldCorrectlyCallback_whenOnRequestPermissionResultCalledFromAppCompatActivity() { + EasyPermissions.onRequestPermissionsResult(TestAppCompatActivity.REQUEST_CODE, ALL_PERMS, SMS_DENIED_RESULT, spyAppCompatActivity); - verify(spySupportActivity, times(1)) + verify(spyAppCompatActivity, times(1)) .onPermissionsGranted(integerCaptor.capture(), listCaptor.capture()); - assertThat(integerCaptor.getValue()).isEqualTo(TestSupportActivity.REQUEST_CODE); + assertThat(integerCaptor.getValue()).isEqualTo(TestAppCompatActivity.REQUEST_CODE); assertThat(listCaptor.getValue()) .containsAllIn(new ArrayList<>(Collections.singletonList(Manifest.permission.ACCESS_FINE_LOCATION))); - verify(spySupportActivity, times(1)) + verify(spyAppCompatActivity, times(1)) .onPermissionsDenied(integerCaptor.capture(), listCaptor.capture()); - assertThat(integerCaptor.getValue()).isEqualTo(TestSupportActivity.REQUEST_CODE); + assertThat(integerCaptor.getValue()).isEqualTo(TestAppCompatActivity.REQUEST_CODE); assertThat(listCaptor.getValue()) .containsAllIn(new ArrayList<>(Collections.singletonList(Manifest.permission.READ_SMS))); - verify(spySupportActivity, never()).afterPermissionGranted(); + verify(spyAppCompatActivity, never()).afterPermissionGranted(); } @Test - public void shouldCallbackOnPermissionGranted_whenRequestAlreadyGrantedPermissionsFromSupportActivity() { + public void shouldCallbackOnPermissionGranted_whenRequestAlreadyGrantedPermissionsFromAppCompatActivity() { grantPermissions(ALL_PERMS); - EasyPermissions.requestPermissions(spySupportActivity, RATIONALE, TestSupportActivity.REQUEST_CODE, ALL_PERMS); + EasyPermissions.requestPermissions(spyAppCompatActivity, RATIONALE, TestAppCompatActivity.REQUEST_CODE, ALL_PERMS); - verify(spySupportActivity, times(1)) + verify(spyAppCompatActivity, times(1)) .onPermissionsGranted(integerCaptor.capture(), listCaptor.capture()); - verify(spySupportActivity, never()).requestPermissions(any(String[].class), anyInt()); - assertThat(integerCaptor.getValue()).isEqualTo(TestSupportActivity.REQUEST_CODE); + verify(spyAppCompatActivity, never()).requestPermissions(any(String[].class), anyInt()); + assertThat(integerCaptor.getValue()).isEqualTo(TestAppCompatActivity.REQUEST_CODE); assertThat(listCaptor.getValue()).containsAllIn(ALL_PERMS); } @Test - public void shouldCallbackAfterPermissionGranted_whenRequestAlreadyGrantedPermissionsFromSupportActivity() { + public void shouldCallbackAfterPermissionGranted_whenRequestAlreadyGrantedPermissionsFromAppCompatActivity() { grantPermissions(ALL_PERMS); - EasyPermissions.requestPermissions(spySupportActivity, RATIONALE, TestSupportActivity.REQUEST_CODE, ALL_PERMS); + EasyPermissions.requestPermissions(spyAppCompatActivity, RATIONALE, TestAppCompatActivity.REQUEST_CODE, ALL_PERMS); // Called 2 times because this is a spy and library implementation invokes super classes annotated methods as well - verify(spySupportActivity, times(2)).afterPermissionGranted(); + verify(spyAppCompatActivity, times(2)).afterPermissionGranted(); } @Test - public void shouldNotCallbackAfterPermissionGranted_whenRequestNotGrantedPermissionsFromSupportActivity() { + public void shouldNotCallbackAfterPermissionGranted_whenRequestNotGrantedPermissionsFromAppCompatActivity() { grantPermissions(ONE_PERM); - EasyPermissions.requestPermissions(spySupportActivity, RATIONALE, TestSupportActivity.REQUEST_CODE, ALL_PERMS); + EasyPermissions.requestPermissions(spyAppCompatActivity, RATIONALE, TestAppCompatActivity.REQUEST_CODE, ALL_PERMS); - verify(spySupportActivity, never()).afterPermissionGranted(); + verify(spyAppCompatActivity, never()).afterPermissionGranted(); } @Test - public void shouldRequestPermissions_whenMissingPermissionAndNotShowRationaleFromSupportActivity() { + public void shouldRequestPermissions_whenMissingPermissionAndNotShowRationaleFromAppCompatActivity() { grantPermissions(ONE_PERM); showRationale(false, ALL_PERMS); - EasyPermissions.requestPermissions(spySupportActivity, RATIONALE, TestSupportActivity.REQUEST_CODE, ALL_PERMS); + EasyPermissions.requestPermissions(spyAppCompatActivity, RATIONALE, TestAppCompatActivity.REQUEST_CODE, ALL_PERMS); - verify(spySupportActivity, times(1)) - .requestPermissions(ALL_PERMS, TestSupportActivity.REQUEST_CODE); + verify(spyAppCompatActivity, times(1)) + .requestPermissions(ALL_PERMS, TestAppCompatActivity.REQUEST_CODE); } @Test - public void shouldShowCorrectDialog_whenMissingPermissionsAndShowRationaleFromSupportActivity() { + public void shouldShowCorrectDialog_whenMissingPermissionsAndShowRationaleFromAppCompatActivity() { grantPermissions(ONE_PERM); showRationale(true, ALL_PERMS); - EasyPermissions.requestPermissions(spySupportActivity, RATIONALE, TestSupportActivity.REQUEST_CODE, ALL_PERMS); + EasyPermissions.requestPermissions(spyAppCompatActivity, RATIONALE, TestAppCompatActivity.REQUEST_CODE, ALL_PERMS); - android.support.v4.app.Fragment dialogFragment = spySupportActivity.getSupportFragmentManager() + android.support.v4.app.Fragment dialogFragment = spyAppCompatActivity.getSupportFragmentManager() .findFragmentByTag(RationaleDialogFragmentCompat.TAG); assertThat(dialogFragment).isInstanceOf(RationaleDialogFragmentCompat.class); @@ -331,11 +334,26 @@ public void shouldShowCorrectDialog_whenMissingPermissionsAndShowRationaleFromSu } @Test - public void shouldShowCorrectDialogUsingRequest_whenMissingPermissionsAndShowRationaleFromSupportActivity() { + public void shouldShowCorrectDialog_whenMissingPermissionsAndShowRationaleFromSupportFragmentActivity() { grantPermissions(ONE_PERM); showRationale(true, ALL_PERMS); - PermissionRequest request = new PermissionRequest.Builder(spySupportActivity, TestSupportActivity.REQUEST_CODE, ALL_PERMS) + EasyPermissions.requestPermissions(spySupportFragmentActivity, RATIONALE, TestSupportFragmentActivity.REQUEST_CODE, ALL_PERMS); + + Fragment dialogFragment = spySupportFragmentActivity.getFragmentManager() + .findFragmentByTag(RationaleDialogFragment.TAG); + assertThat(dialogFragment).isInstanceOf(RationaleDialogFragment.class); + + Dialog dialog = ((RationaleDialogFragment) dialogFragment).getDialog(); + assertThatHasExpectedRationale(dialog, RATIONALE); + } + + @Test + public void shouldShowCorrectDialogUsingRequest_whenMissingPermissionsAndShowRationaleFromAppCompatActivity() { + grantPermissions(ONE_PERM); + showRationale(true, ALL_PERMS); + + PermissionRequest request = new PermissionRequest.Builder(spyAppCompatActivity, TestAppCompatActivity.REQUEST_CODE, ALL_PERMS) .setPositiveButtonText(android.R.string.ok) .setNegativeButtonText(android.R.string.cancel) .setRationale(android.R.string.unknownName) @@ -343,7 +361,7 @@ public void shouldShowCorrectDialogUsingRequest_whenMissingPermissionsAndShowRat .build(); EasyPermissions.requestPermissions(request); - android.support.v4.app.Fragment dialogFragment = spySupportActivity.getSupportFragmentManager() + android.support.v4.app.Fragment dialogFragment = spyAppCompatActivity.getSupportFragmentManager() .findFragmentByTag(RationaleDialogFragmentCompat.TAG); assertThat(dialogFragment).isInstanceOf(RationaleDialogFragmentCompat.class); @@ -353,45 +371,45 @@ public void shouldShowCorrectDialogUsingRequest_whenMissingPermissionsAndShowRat } @Test - public void shouldHaveSomePermissionDenied_whenShowRationaleFromSupportActivity() { + public void shouldHaveSomePermissionDenied_whenShowRationaleFromAppCompatActivity() { showRationale(true, ALL_PERMS); - assertThat(EasyPermissions.somePermissionDenied(spySupportActivity, ALL_PERMS)).isTrue(); + assertThat(EasyPermissions.somePermissionDenied(spyAppCompatActivity, ALL_PERMS)).isTrue(); } @Test - public void shouldNotHaveSomePermissionDenied_whenNotShowRationaleFromSupportActivity() { + public void shouldNotHaveSomePermissionDenied_whenNotShowRationaleFromAppCompatActivity() { showRationale(false, ALL_PERMS); - assertThat(EasyPermissions.somePermissionDenied(spySupportActivity, ALL_PERMS)).isFalse(); + assertThat(EasyPermissions.somePermissionDenied(spyAppCompatActivity, ALL_PERMS)).isFalse(); } @Test - public void shouldHaveSomePermissionPermanentlyDenied_whenNotShowRationaleFromSupportActivity() { + public void shouldHaveSomePermissionPermanentlyDenied_whenNotShowRationaleFromAppCompatActivity() { showRationale(false, ALL_PERMS); - assertThat(EasyPermissions.somePermissionPermanentlyDenied(spySupportActivity, Arrays.asList(ALL_PERMS))).isTrue(); + assertThat(EasyPermissions.somePermissionPermanentlyDenied(spyAppCompatActivity, Arrays.asList(ALL_PERMS))).isTrue(); } @Test - public void shouldNotHaveSomePermissionPermanentlyDenied_whenShowRationaleFromSupportActivity() { + public void shouldNotHaveSomePermissionPermanentlyDenied_whenShowRationaleFromAppCompatActivity() { showRationale(true, ALL_PERMS); - assertThat(EasyPermissions.somePermissionPermanentlyDenied(spySupportActivity, Arrays.asList(ALL_PERMS))).isFalse(); + assertThat(EasyPermissions.somePermissionPermanentlyDenied(spyAppCompatActivity, Arrays.asList(ALL_PERMS))).isFalse(); } @Test - public void shouldHavePermissionPermanentlyDenied_whenNotShowRationaleFromSupportActivity() { + public void shouldHavePermissionPermanentlyDenied_whenNotShowRationaleFromAppCompatActivity() { showRationale(false, Manifest.permission.READ_SMS); - assertThat(EasyPermissions.permissionPermanentlyDenied(spySupportActivity, Manifest.permission.READ_SMS)).isTrue(); + assertThat(EasyPermissions.permissionPermanentlyDenied(spyAppCompatActivity, Manifest.permission.READ_SMS)).isTrue(); } @Test - public void shouldNotHavePermissionPermanentlyDenied_whenShowRationaleFromSupportActivity() { + public void shouldNotHavePermissionPermanentlyDenied_whenShowRationaleFromAppCompatActivity() { showRationale(true, Manifest.permission.READ_SMS); - assertThat(EasyPermissions.permissionPermanentlyDenied(spySupportActivity, Manifest.permission.READ_SMS)).isFalse(); + assertThat(EasyPermissions.permissionPermanentlyDenied(spyAppCompatActivity, Manifest.permission.READ_SMS)).isFalse(); } @Test @@ -575,19 +593,23 @@ private void assertThatHasExpectedRationale(Dialog dialog, String rationale) { private void setUpActivityAndFragment() { activityController = Robolectric.buildActivity(TestActivity.class) .create().start().resume(); - supportActivityController = Robolectric.buildActivity(TestSupportActivity.class) + supportFragmentActivityController = Robolectric.buildActivity(TestSupportFragmentActivity.class) + .create().start().resume(); + appCompatActivityController = Robolectric.buildActivity(TestAppCompatActivity.class) .create().start().resume(); fragmentController = SupportFragmentController.of(new TestFragment()) .create().start().resume(); spyActivity = Mockito.spy(activityController.get()); - spySupportActivity = Mockito.spy(supportActivityController.get()); + spySupportFragmentActivity = Mockito.spy(supportFragmentActivityController.get()); + spyAppCompatActivity = Mockito.spy(appCompatActivityController.get()); spyFragment = Mockito.spy(fragmentController.get()); } private void tearDownActivityAndFragment() { activityController.pause().stop().destroy(); - supportActivityController.pause().stop().destroy(); + supportFragmentActivityController.pause().stop().destroy(); + appCompatActivityController.pause().stop().destroy(); fragmentController.pause().stop().destroy(); } @@ -598,7 +620,8 @@ private void grantPermissions(String[] perms) { private void showRationale(boolean show, String... perms) { for (String perm : perms) { when(spyActivity.shouldShowRequestPermissionRationale(perm)).thenReturn(show); - when(spySupportActivity.shouldShowRequestPermissionRationale(perm)).thenReturn(show); + when(spySupportFragmentActivity.shouldShowRequestPermissionRationale(perm)).thenReturn(show); + when(spyAppCompatActivity.shouldShowRequestPermissionRationale(perm)).thenReturn(show); when(spyFragment.shouldShowRequestPermissionRationale(perm)).thenReturn(show); } } diff --git a/easypermissions/src/test/java/pub/devrel/easypermissions/testhelper/TestSupportActivity.java b/easypermissions/src/test/java/pub/devrel/easypermissions/testhelper/TestAppCompatActivity.java similarity index 95% rename from easypermissions/src/test/java/pub/devrel/easypermissions/testhelper/TestSupportActivity.java rename to easypermissions/src/test/java/pub/devrel/easypermissions/testhelper/TestAppCompatActivity.java index 0be1314..11fc738 100644 --- a/easypermissions/src/test/java/pub/devrel/easypermissions/testhelper/TestSupportActivity.java +++ b/easypermissions/src/test/java/pub/devrel/easypermissions/testhelper/TestAppCompatActivity.java @@ -11,7 +11,7 @@ import pub.devrel.easypermissions.EasyPermissions; import pub.devrel.easypermissions.R; -public class TestSupportActivity extends AppCompatActivity +public class TestAppCompatActivity extends AppCompatActivity implements EasyPermissions.PermissionCallbacks, EasyPermissions.RationaleCallbacks { public static final int REQUEST_CODE = 3; diff --git a/easypermissions/src/test/java/pub/devrel/easypermissions/testhelper/TestSupportFragmentActivity.java b/easypermissions/src/test/java/pub/devrel/easypermissions/testhelper/TestSupportFragmentActivity.java new file mode 100644 index 0000000..707c3a1 --- /dev/null +++ b/easypermissions/src/test/java/pub/devrel/easypermissions/testhelper/TestSupportFragmentActivity.java @@ -0,0 +1,47 @@ +package pub.devrel.easypermissions.testhelper; + +import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.support.v4.app.FragmentActivity; + +import java.util.List; + +import pub.devrel.easypermissions.AfterPermissionGranted; +import pub.devrel.easypermissions.EasyPermissions; + +public class TestSupportFragmentActivity extends FragmentActivity + implements EasyPermissions.PermissionCallbacks, EasyPermissions.RationaleCallbacks { + + public static final int REQUEST_CODE = 5; + + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + } + + @Override + public void onPermissionsGranted(int requestCode, @NonNull List perms) { + + } + + @Override + public void onPermissionsDenied(int requestCode, @NonNull List perms) { + + } + + @AfterPermissionGranted(REQUEST_CODE) + public void afterPermissionGranted() { + + } + + @Override + public void onRationaleAccepted(int requestCode) { + + } + + @Override + public void onRationaleDenied(int requestCode) { + + } +} From 454051384bdede67b2298ef0a63572de5b3e58df Mon Sep 17 00:00:00 2001 From: Sam Stern Date: Tue, 15 Jan 2019 14:10:16 -0800 Subject: [PATCH 2/3] Respond to review comments Change-Id: Ie03a23b5b04af5146b887101566d765315cad356 --- build.gradle | 2 +- .../easypermissions/EasyPermissionsLowApiTest.java | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/build.gradle b/build.gradle index 93ae46b..e8c967d 100644 --- a/build.gradle +++ b/build.gradle @@ -31,7 +31,7 @@ ext { mavenGroup = 'pub.devrel' mavenArtifactId = 'easypermissions' - mavenVersion = '2.0.0' + mavenVersion = '2.0.1-SNAPSHOT' bintrayOrg = 'easygoogle' diff --git a/easypermissions/src/test/java/pub/devrel/easypermissions/EasyPermissionsLowApiTest.java b/easypermissions/src/test/java/pub/devrel/easypermissions/EasyPermissionsLowApiTest.java index 6d2f9c8..e40d107 100644 --- a/easypermissions/src/test/java/pub/devrel/easypermissions/EasyPermissionsLowApiTest.java +++ b/easypermissions/src/test/java/pub/devrel/easypermissions/EasyPermissionsLowApiTest.java @@ -39,10 +39,10 @@ public class EasyPermissionsLowApiTest { Manifest.permission.READ_SMS, Manifest.permission.ACCESS_FINE_LOCATION}; private TestActivity spyActivity; - private TestAppCompatActivity spySupportActivity; + private TestAppCompatActivity spyAppCompatActivity; private TestFragment spyFragment; private ActivityController activityController; - private ActivityController supportActivityController; + private ActivityController appCompatActivityController; private SupportFragmentController supportController; @Captor private ArgumentCaptor integerCaptor; @@ -84,9 +84,9 @@ public void shouldCallbackOnPermissionGranted_whenRequestFromActivity() { @Test public void shouldCallbackOnPermissionGranted_whenRequestFromSupportActivity() { - EasyPermissions.requestPermissions(spySupportActivity, RATIONALE, TestAppCompatActivity.REQUEST_CODE, ALL_PERMS); + EasyPermissions.requestPermissions(spyAppCompatActivity, RATIONALE, TestAppCompatActivity.REQUEST_CODE, ALL_PERMS); - verify(spySupportActivity, times(1)) + verify(spyAppCompatActivity, times(1)) .onPermissionsGranted(integerCaptor.capture(), listCaptor.capture()); assertThat(integerCaptor.getValue()).isEqualTo(TestAppCompatActivity.REQUEST_CODE); assertThat(listCaptor.getValue()).containsAllIn(ALL_PERMS); @@ -105,19 +105,19 @@ public void shouldCallbackOnPermissionGranted_whenRequestFromFragment() { private void setUpActivityAndFragment() { activityController = Robolectric.buildActivity(TestActivity.class) .create().start().resume(); - supportActivityController = Robolectric.buildActivity(TestAppCompatActivity.class) + appCompatActivityController = Robolectric.buildActivity(TestAppCompatActivity.class) .create().start().resume(); supportController = SupportFragmentController.of(new TestFragment()) .create().start().resume(); spyActivity = Mockito.spy(activityController.get()); - spySupportActivity = Mockito.spy(supportActivityController.get()); + spyAppCompatActivity = Mockito.spy(appCompatActivityController.get()); spyFragment = Mockito.spy(supportController.get()); } private void tearDownActivityAndFragment() { activityController.pause().stop().destroy(); - supportActivityController.pause().stop().destroy(); + appCompatActivityController.pause().stop().destroy(); supportController.pause().stop().destroy(); } } From 97e1429afd5f253891d8e5bd31b55e9541b8cf3b Mon Sep 17 00:00:00 2001 From: Sam Stern Date: Tue, 15 Jan 2019 14:20:38 -0800 Subject: [PATCH 3/3] Add test Change-Id: I4e94b9c7264effcf1ba7beb2022be9b5d6a65fdf --- .../EasyPermissionsLowApiTest.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) 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()); }