Skip to content

Commit 12a3e7c

Browse files
committed
Refactored tests to expose private interface in separate test header.
Refactored the existing unit tests to expose private interfaces in a separate test header instead of an inline interface. This was first introduced in the google_sign_in plugin (flutter#4157) and after that also applied in the camera plugin (flutter#4426) and the webview_flutter plugin (flutter#4480).
1 parent a5b97ea commit 12a3e7c

File tree

8 files changed

+49
-14
lines changed

8 files changed

+49
-14
lines changed

packages/image_picker/image_picker/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.8.4+6
2+
3+
* Refactores unit test to expose private interface via a separate test header instead of the inline declaration.
4+
15
## 0.8.4+5
26

37
* Improves the documentation on handling MainActivity being killed by the Android OS.

packages/image_picker/image_picker/example/ios/RunnerTests/ImagePickerPluginTests.m

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#import "ImagePickerTestImages.h"
66

77
@import image_picker;
8+
@import image_picker.Test;
89
@import XCTest;
910
#import <OCMock/OCMock.h>
1011

@@ -21,12 +22,6 @@ - (UIViewController *)presentedViewController {
2122

2223
@end
2324

24-
@interface FLTImagePickerPlugin (Test)
25-
@property(copy, nonatomic) FlutterResult result;
26-
- (void)handleSavedPathList:(NSMutableArray *)pathList;
27-
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker;
28-
@end
29-
3025
@interface ImagePickerPluginTests : XCTestCase
3126
@property(readonly, nonatomic) id mockUIImagePicker;
3227
@property(readonly, nonatomic) id mockAVCaptureDevice;
@@ -49,7 +44,7 @@ - (void)testPluginPickImageDeviceBack {
4944
OCMStub(ClassMethod(
5045
[_mockUIImagePicker isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear]))
5146
.andReturn(YES);
52-
47+
5348
// AVAuthorizationStatusAuthorized is supported
5449
OCMStub([_mockAVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo])
5550
.andReturn(AVAuthorizationStatusAuthorized);
@@ -77,7 +72,7 @@ - (void)testPluginPickImageDeviceFront {
7772
OCMStub(ClassMethod([_mockUIImagePicker
7873
isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront]))
7974
.andReturn(YES);
80-
75+
8176
// AVAuthorizationStatusAuthorized is supported
8277
OCMStub([_mockAVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo])
8378
.andReturn(AVAuthorizationStatusAuthorized);
@@ -105,7 +100,7 @@ - (void)testPluginPickVideoDeviceBack {
105100
OCMStub(ClassMethod(
106101
[_mockUIImagePicker isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear]))
107102
.andReturn(YES);
108-
103+
109104
// AVAuthorizationStatusAuthorized is supported
110105
OCMStub([_mockAVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo])
111106
.andReturn(AVAuthorizationStatusAuthorized);
@@ -133,7 +128,7 @@ - (void)testPluginPickVideoDeviceFront {
133128
OCMStub(ClassMethod([_mockUIImagePicker
134129
isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront]))
135130
.andReturn(YES);
136-
131+
137132
// AVAuthorizationStatusAuthorized is supported
138133
OCMStub([_mockAVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo])
139134
.andReturn(AVAuthorizationStatusAuthorized);

packages/image_picker/image_picker/ios/Classes/FLTImagePickerPlugin.m

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// found in the LICENSE file.
44

55
#import "FLTImagePickerPlugin.h"
6+
#import "FLTImagePickerPlugin_Test.h"
67

78
#import <AVFoundation/AVFoundation.h>
89
#import <MobileCoreServices/MobileCoreServices.h>
@@ -21,8 +22,6 @@ @interface FLTImagePickerPlugin () <UINavigationControllerDelegate,
2122
PHPickerViewControllerDelegate,
2223
UIAdaptivePresentationControllerDelegate>
2324

24-
@property(copy, nonatomic) FlutterResult result;
25-
2625
@property(assign, nonatomic) int maxImagesAllowed;
2726

2827
@property(copy, nonatomic) NSDictionary *arguments;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
// This header is available in the Test module. Import via "@import image_picker.Test;"
6+
7+
#import <image_picker/FLTImagePickerPlugin.h>
8+
9+
/// Methods exposed for unit testing.
10+
@interface FLTImagePickerPlugin ()
11+
12+
@property(copy, nonatomic) FlutterResult result;
13+
- (void)handleSavedPathList:(NSArray *)pathList;
14+
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker;
15+
16+
@end
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
framework module image_picker {
2+
umbrella header "image_picker-umbrella.h"
3+
4+
export *
5+
module * { export * }
6+
7+
explicit module Test {
8+
header "FLTImagePickerPlugin_Test.h"
9+
}
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#import <Foundation/Foundation.h>
6+
#import <image_picker/FLTImagePickerImageUtil.h>
7+
#import <image_picker/FLTImagePickerMetaDataUtil.h>
8+
#import <image_picker/FLTImagePickerPhotoAssetUtil.h>
9+
#import <image_picker/FLTImagePickerPlugin.h>
10+
#import <image_picker/FLTPHPickerSaveImageToPathOperation.h>

packages/image_picker/image_picker/ios/image_picker.podspec

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ Downloaded by pub (not CocoaPods).
1414
s.author = { 'Flutter Dev Team' => '[email protected]' }
1515
s.source = { :http => 'https://github.com/flutter/plugins/tree/main/packages/image_picker' }
1616
s.documentation_url = 'https://pub.dev/packages/image_picker'
17-
s.source_files = 'Classes/**/*'
17+
s.source_files = 'Classes/**/*.{h,m}'
1818
s.public_header_files = 'Classes/**/*.h'
19+
s.module_map = 'Classes/ImagePickerPlugin.modulemap'
1920
s.dependency 'Flutter'
2021
s.platform = :ios, '9.0'
2122
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386' }

packages/image_picker/image_picker/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description: Flutter plugin for selecting images from the Android and iOS image
33
library, and taking new pictures with the camera.
44
repository: https://github.com/flutter/plugins/tree/main/packages/image_picker/image_picker
55
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+image_picker%22
6-
version: 0.8.4+5
6+
version: 0.8.4+6
77

88
environment:
99
sdk: ">=2.14.0 <3.0.0"

0 commit comments

Comments
 (0)