@@ -1672,6 +1672,8 @@ - (void)testStoreDataWithCallbackAndNoQueue
16721672 XCTAssertFalse (result);
16731673}
16741674
1675+ #pragma mark Test Dispatching Empty and Error Responses
1676+
16751677- (void )testDispatchEmptyResponseWithNilCallbackDoesNothing
16761678{
16771679 SPTPersistentCacheForUnitTests * const cache = [self createCacheWithTimeCallback: ^ NSTimeInterval (){
@@ -1708,6 +1710,50 @@ - (void)testDispatchEmptyResponse
17081710 XCTAssertTrue (cache.test_didDispatchBlock );
17091711}
17101712
1713+ - (void )testDispatchErrorWithNilCallbackDoesNothing
1714+ {
1715+ SPTPersistentCacheForUnitTests * const cache = [self createCacheWithTimeCallback: ^ NSTimeInterval (){
1716+ return kTestEpochTime ;
1717+ } expirationTime: SPTPersistentCacheDefaultExpirationTimeSec];
1718+
1719+ [cache dispatchError: [NSError errorWithDomain: SPTPersistentCacheErrorDomain code: 0 userInfo: nil ]
1720+ result: SPTPersistentCacheResponseCodeOperationError
1721+ callback: nil
1722+ onQueue: dispatch_get_main_queue ()];
1723+
1724+ XCTAssertTrue (cache.test_didDispatchBlock == NO );
1725+ }
1726+
1727+ - (void )testDispatchError
1728+ {
1729+ SPTPersistentCacheForUnitTests * const cache = [self createCacheWithTimeCallback: ^ NSTimeInterval (){
1730+ return kTestEpochTime ;
1731+ } expirationTime: SPTPersistentCacheDefaultExpirationTimeSec];
1732+
1733+ NSError * const error = [NSError errorWithDomain: SPTPersistentCacheErrorDomain
1734+ code: SPTPersistentCacheLoadingErrorNotEnoughDataToGetHeader
1735+ userInfo: nil ];
1736+
1737+ __weak XCTestExpectation * const expectation = [self expectationWithDescription: @" callback expectation" ];
1738+ SPTPersistentCacheResponseCallback callback = ^(SPTPersistentCacheResponse *response){
1739+ XCTAssertNotNil (response);
1740+ XCTAssertEqualObjects (response.error , error);
1741+ XCTAssertNil (response.record );
1742+ XCTAssertEqual (response.result , SPTPersistentCacheResponseCodeOperationError);
1743+
1744+ [expectation fulfill ];
1745+ };
1746+
1747+ [cache dispatchError: error
1748+ result: SPTPersistentCacheResponseCodeOperationError
1749+ callback: callback
1750+ onQueue: dispatch_get_main_queue ()];
1751+
1752+ [self waitForExpectationsWithTimeout: 0.5 handler: nil ];
1753+ XCTAssertTrue (cache.test_didDispatchBlock );
1754+ }
1755+
1756+
17111757#pragma mark - Internal methods
17121758
17131759- (void )putFile : (NSString *)file
0 commit comments