@@ -14,40 +14,44 @@ @interface FLTSavePhotoDelegateTests : XCTestCase
1414
1515@implementation FLTSavePhotoDelegateTests
1616
17- - (void )testHandlePhotoCaptureResult_mustSendErrorIfFailedToCapture {
18- NSError *error = [NSError errorWithDomain: @" test" code: 0 userInfo: nil ];
19- dispatch_queue_t ioQueue = dispatch_queue_create (" test" , NULL );
20- id mockResult = OCMClassMock ([FLTThreadSafeFlutterResult class ]);
21- FLTSavePhotoDelegate *delegate = [[FLTSavePhotoDelegate alloc ] initWithPath: @" test"
22- result: mockResult
23- ioQueue: ioQueue];
17+ - (void )testHandlePhotoCaptureResult_mustCompleteWithErrorIfFailedToCapture {
18+ XCTestExpectation *completionExpectation =
19+ [self expectationWithDescription: @" Must complete with error if failed to capture photo." ];
2420
25- [delegate handlePhotoCaptureResultWithError: error
21+ NSError *captureError = [NSError errorWithDomain: @" test" code: 0 userInfo: nil ];
22+ dispatch_queue_t ioQueue = dispatch_queue_create (" test" , NULL );
23+ FLTSavePhotoDelegate *delegate = [[FLTSavePhotoDelegate alloc ]
24+ initWithPath: @" test"
25+ ioQueue: ioQueue
26+ completionHandler: ^(NSString *_Nullable path, NSError *_Nullable error) {
27+ XCTAssertEqualObjects (captureError, error);
28+ XCTAssertNil (path);
29+ [completionExpectation fulfill ];
30+ }];
31+
32+ [delegate handlePhotoCaptureResultWithError: captureError
2633 photoDataProvider: ^NSData * {
2734 return nil ;
2835 }];
29- OCMVerify ([mockResult sendError: error]) ;
36+ [ self waitForExpectationsWithTimeout: 1 handler: nil ] ;
3037}
3138
32- - (void )testHandlePhotoCaptureResult_mustSendErrorIfFailedToWrite {
33- XCTestExpectation *resultExpectation =
34- [self expectationWithDescription: @" Must send IOError to the result if failed to write file." ];
39+ - (void )testHandlePhotoCaptureResult_mustCompleteWithErrorIfFailedToWrite {
40+ XCTestExpectation *completionExpectation =
41+ [self expectationWithDescription: @" Must complete with error if failed to write file." ];
3542 dispatch_queue_t ioQueue = dispatch_queue_create (" test" , NULL );
36- id mockResult = OCMClassMock ([FLTThreadSafeFlutterResult class ]);
3743
3844 NSError *ioError = [NSError errorWithDomain: @" IOError"
3945 code: 0
4046 userInfo: @{NSLocalizedDescriptionKey : @" Localized IO Error" }];
41-
42- OCMStub ([mockResult sendErrorWithCode: @" IOError"
43- message: @" Unable to write file"
44- details: ioError.localizedDescription])
45- .andDo (^(NSInvocation *invocation) {
46- [resultExpectation fulfill ];
47- });
48- FLTSavePhotoDelegate *delegate = [[FLTSavePhotoDelegate alloc ] initWithPath: @" test"
49- result: mockResult
50- ioQueue: ioQueue];
47+ FLTSavePhotoDelegate *delegate = [[FLTSavePhotoDelegate alloc ]
48+ initWithPath: @" test"
49+ ioQueue: ioQueue
50+ completionHandler: ^(NSString *_Nullable path, NSError *_Nullable error) {
51+ XCTAssertEqualObjects (ioError, error);
52+ XCTAssertNil (path);
53+ [completionExpectation fulfill ];
54+ }];
5155
5256 // We can't use OCMClassMock for NSData because some XCTest APIs uses NSData (e.g.
5357 // `XCTRunnerIDESession::logDebugMessage:`) on a private queue.
@@ -63,23 +67,25 @@ - (void)testHandlePhotoCaptureResult_mustSendErrorIfFailedToWrite {
6367 [self waitForExpectationsWithTimeout: 1 handler: nil ];
6468}
6569
66- - (void )testHandlePhotoCaptureResult_mustSendSuccessIfSuccessToWrite {
67- XCTestExpectation *resultExpectation = [ self
68- expectationWithDescription: @" Must send file path to the result if success to write file." ];
70+ - (void )testHandlePhotoCaptureResult_mustCompleteWithFilePathIfSuccessToWrite {
71+ XCTestExpectation *completionExpectation =
72+ [ self expectationWithDescription: @" Must complete with file path if success to write file." ];
6973
7074 dispatch_queue_t ioQueue = dispatch_queue_create (" test" , NULL );
71- id mockResult = OCMClassMock ([FLTThreadSafeFlutterResult class ]);
72- FLTSavePhotoDelegate *delegate = [[FLTSavePhotoDelegate alloc ] initWithPath: @" test"
73- result: mockResult
74- ioQueue: ioQueue];
75- OCMStub ([mockResult sendSuccessWithData: delegate.path]).andDo (^(NSInvocation *invocation) {
76- [resultExpectation fulfill ];
77- });
75+ NSString *filePath = @" test" ;
76+ FLTSavePhotoDelegate *delegate = [[FLTSavePhotoDelegate alloc ]
77+ initWithPath: filePath
78+ ioQueue: ioQueue
79+ completionHandler: ^(NSString *_Nullable path, NSError *_Nullable error) {
80+ XCTAssertNil (error);
81+ XCTAssertEqualObjects (filePath, path);
82+ [completionExpectation fulfill ];
83+ }];
7884
7985 // We can't use OCMClassMock for NSData because some XCTest APIs uses NSData (e.g.
8086 // `XCTRunnerIDESession::logDebugMessage:`) on a private queue.
8187 id mockData = OCMPartialMock ([NSData data ]);
82- OCMStub ([mockData writeToFile: OCMOCK_ANY options: NSDataWritingAtomic error: [OCMArg setTo: nil ]])
88+ OCMStub ([mockData writeToFile: filePath options: NSDataWritingAtomic error: [OCMArg setTo: nil ]])
8389 .andReturn (YES );
8490
8591 [delegate handlePhotoCaptureResultWithError: nil
@@ -94,16 +100,12 @@ - (void)testHandlePhotoCaptureResult_bothProvideDataAndSaveFileMustRunOnIOQueue
94100 [self expectationWithDescription: @" Data provider must run on io queue." ];
95101 XCTestExpectation *writeFileQueueExpectation =
96102 [self expectationWithDescription: @" File writing must run on io queue" ];
97- XCTestExpectation *resultExpectation = [ self
98- expectationWithDescription: @" Must send file path to the result if success to write file." ];
103+ XCTestExpectation *completionExpectation =
104+ [ self expectationWithDescription: @" Must complete with file path if success to write file." ];
99105
100106 dispatch_queue_t ioQueue = dispatch_queue_create (" test" , NULL );
101107 const char *ioQueueSpecific = " io_queue_specific" ;
102108 dispatch_queue_set_specific (ioQueue, ioQueueSpecific, (void *)ioQueueSpecific, NULL );
103- id mockResult = OCMClassMock ([FLTThreadSafeFlutterResult class ]);
104- OCMStub ([mockResult sendSuccessWithData: OCMOCK_ANY]).andDo (^(NSInvocation *invocation) {
105- [resultExpectation fulfill ];
106- });
107109
108110 // We can't use OCMClassMock for NSData because some XCTest APIs uses NSData (e.g.
109111 // `XCTRunnerIDESession::logDebugMessage:`) on a private queue.
@@ -116,9 +118,14 @@ - (void)testHandlePhotoCaptureResult_bothProvideDataAndSaveFileMustRunOnIOQueue
116118 })
117119 .andReturn (YES );
118120
119- FLTSavePhotoDelegate *delegate = [[FLTSavePhotoDelegate alloc ] initWithPath: @" test"
120- result: mockResult
121- ioQueue: ioQueue];
121+ NSString *filePath = @" test" ;
122+ FLTSavePhotoDelegate *delegate = [[FLTSavePhotoDelegate alloc ]
123+ initWithPath: filePath
124+ ioQueue: ioQueue
125+ completionHandler: ^(NSString *_Nullable path, NSError *_Nullable error) {
126+ [completionExpectation fulfill ];
127+ }];
128+
122129 [delegate handlePhotoCaptureResultWithError: nil
123130 photoDataProvider: ^NSData * {
124131 if (dispatch_get_specific (ioQueueSpecific)) {
0 commit comments