GetImageFragment extends WolmoFragment<T> { protected void takePicture(@NonNull final OnImageReturnCallback onImageReturnCallback) { permissionManager.requestPermission(this, new PermissionListener() { @Override public void onPermissionsGranted() { mImageCallback = onImageReturnCallback; mPictureTakenFile = mImageProvider .getImageFromCamera(GetImageFragment.this, INTENT_CODE_IMAGE_CAMERA, pictureTakenFilename(), ImageProvider.PNG, cameraErrorResId()); } @Override public void onPermissionsDenied(@NonNull String[] deniedPermissions) { onImageReturnCallback.error(Error.PERMISSION_DENIED); } }, CAMERA_PERMISSIONS); }  @Override void onActivityResult(int requestCode, int resultCode, Intent data);  }
@Test public void takePictureSuccessShouldCallDependencies() { GetImageFragment.OnImageReturnCallback callbackMock = mock(GetImageFragment.OnImageReturnCallback.class); getImageFromCameraSuccess(); mGetImageFragmentSpy.takePicture(callbackMock); verify(mPermissionManagerMock, times(1)).requestPermission(eq(mGetImageFragmentSpy), any(PermissionListener.class), eq(CAMERA_PERMISSIONS[0]), eq(CAMERA_PERMISSIONS[1])); verify(mImageProviderMock, times(1)).getImageFromCamera(eq(mGetImageFragmentSpy), eq(INTENT_CODE_IMAGE_CAMERA), eq(CAMERA_FILENAME), eq(ImageProvider.PNG), eq(CAMERA_ERROR_RES_ID)); verify(callbackMock, times(0)).error(any(GetImageFragment.Error.class)); verify(callbackMock, times(0)).success(any(File.class)); }
@Test public void takePictureErrorShouldNotifyCallback() { GetImageFragment.OnImageReturnCallback callbackMock = mock(GetImageFragment.OnImageReturnCallback.class); doAnswer(invocation -> { ((PermissionListener) invocation.getArgument(1)).onPermissionsDenied(new String[1]); return null; }).when(mPermissionManagerMock).requestPermission(any(Fragment.class), any(PermissionListener.class), eq(CAMERA_PERMISSIONS[0]), eq(CAMERA_PERMISSIONS[1])); mGetImageFragmentSpy.takePicture(callbackMock); verify(mPermissionManagerMock, times(1)).requestPermission(eq(mGetImageFragmentSpy), any(PermissionListener.class), eq(CAMERA_PERMISSIONS[0]), eq(CAMERA_PERMISSIONS[1])); verify(mImageProviderMock, times(0)).getImageFromGallery(any(Fragment.class), anyInt(), anyInt()); verify(callbackMock, times(1)).error(eq(GetImageFragment.Error.PERMISSION_DENIED)); verify(callbackMock, times(0)).success(any(File.class)); }