@Test public void selectImageFromGallerySuccessShouldCallDependencies() { GetImageFragment.OnImageReturnCallback callbackMock = mock(GetImageFragment.OnImageReturnCallback.class); doAnswer(invocation -> { ((PermissionListener) invocation.getArgument(1)).onPermissionsGranted(); return null; }).when(mPermissionManagerMock).requestPermission(any(Fragment.class), any(PermissionListener.class), eq(Manifest.permission.READ_EXTERNAL_STORAGE)); mGetImageFragmentSpy.selectImageFromGallery(callbackMock); verify(mPermissionManagerMock, times(1)).requestPermission(eq(mGetImageFragmentSpy), any(PermissionListener.class), eq(Manifest.permission.READ_EXTERNAL_STORAGE)); verify(mImageProviderMock, times(1)).getImageFromGallery(eq(mGetImageFragmentSpy), eq(INTENT_CODE_IMAGE_GALLERY), eq(GALLERY_ERROR_RES_ID)); verify(callbackMock, times(0)).error(any(GetImageFragment.Error.class)); verify(callbackMock, times(0)).success(any(File.class)); }
protected void selectImageFromGallery( @NonNull final OnImageReturnCallback onImageReturnCallback) { permissionManager.requestPermission(this, new PermissionListener() { @Override public void onPermissionsGranted() { mImageCallback = onImageReturnCallback; mImageProvider.getImageFromGallery(GetImageFragment.this, INTENT_CODE_IMAGE_GALLERY, galleryErrorResId()); } @Override public void onPermissionsDenied(@NonNull String[] deniedPermissions) { onImageReturnCallback.error(Error.PERMISSION_DENIED); } }, GALLERY_PERMISSIONS); }
GetImageFragment extends WolmoFragment<T> { protected void selectImageFromGallery( @NonNull final OnImageReturnCallback onImageReturnCallback) { permissionManager.requestPermission(this, new PermissionListener() { @Override public void onPermissionsGranted() { mImageCallback = onImageReturnCallback; mImageProvider.getImageFromGallery(GetImageFragment.this, INTENT_CODE_IMAGE_GALLERY, galleryErrorResId()); } @Override public void onPermissionsDenied(@NonNull String[] deniedPermissions) { onImageReturnCallback.error(Error.PERMISSION_DENIED); } }, GALLERY_PERMISSIONS); } }
GetImageFragment extends WolmoFragment<T> { protected void selectImageFromGallery( @NonNull final OnImageReturnCallback onImageReturnCallback) { permissionManager.requestPermission(this, new PermissionListener() { @Override public void onPermissionsGranted() { mImageCallback = onImageReturnCallback; mImageProvider.getImageFromGallery(GetImageFragment.this, INTENT_CODE_IMAGE_GALLERY, galleryErrorResId()); } @Override public void onPermissionsDenied(@NonNull String[] deniedPermissions) { onImageReturnCallback.error(Error.PERMISSION_DENIED); } }, GALLERY_PERMISSIONS); }  }
GetImageFragment extends WolmoFragment<T> { protected void selectImageFromGallery( @NonNull final OnImageReturnCallback onImageReturnCallback) { permissionManager.requestPermission(this, new PermissionListener() { @Override public void onPermissionsGranted() { mImageCallback = onImageReturnCallback; mImageProvider.getImageFromGallery(GetImageFragment.this, INTENT_CODE_IMAGE_GALLERY, galleryErrorResId()); } @Override public void onPermissionsDenied(@NonNull String[] deniedPermissions) { onImageReturnCallback.error(Error.PERMISSION_DENIED); } }, GALLERY_PERMISSIONS); }  @Override void onActivityResult(int requestCode, int resultCode, Intent data); }
GetImageFragment extends WolmoFragment<T> { protected void selectImageFromGallery( @NonNull final OnImageReturnCallback onImageReturnCallback) { permissionManager.requestPermission(this, new PermissionListener() { @Override public void onPermissionsGranted() { mImageCallback = onImageReturnCallback; mImageProvider.getImageFromGallery(GetImageFragment.this, INTENT_CODE_IMAGE_GALLERY, galleryErrorResId()); } @Override public void onPermissionsDenied(@NonNull String[] deniedPermissions) { onImageReturnCallback.error(Error.PERMISSION_DENIED); } }, GALLERY_PERMISSIONS); }  @Override void onActivityResult(int requestCode, int resultCode, Intent data);  }