Fjalapeno has uploaded a new change for review. https://gerrit.wikimedia.org/r/223954
Change subject: Fixing unit tests for article fetcher and friends ...................................................................... Fixing unit tests for article fetcher and friends Change-Id: Icbf0a5515cc93e35580468f074b30073813e0428 --- M MediaWikiKit/MediaWikiKitTests/MWKHistoryListTests.m M WikipediaUnitTests/ArticleFetcherTests.m 2 files changed, 28 insertions(+), 25 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/apps/ios/wikipedia refs/changes/54/223954/1 diff --git a/MediaWikiKit/MediaWikiKitTests/MWKHistoryListTests.m b/MediaWikiKit/MediaWikiKitTests/MWKHistoryListTests.m index 46d5aea..549251d 100644 --- a/MediaWikiKit/MediaWikiKitTests/MWKHistoryListTests.m +++ b/MediaWikiKit/MediaWikiKitTests/MWKHistoryListTests.m @@ -90,7 +90,9 @@ } - (void)testEmptyNotDirty { - XCTAssertFalse(historyList.dirty, @"Should not be dirty initially"); + dispatchOnMainQueue(^{ + XCTAssertFalse(self->historyList.dirty, @"Should not be dirty initially"); + }); } - (void)testEmptyDirtyAfterAdd { diff --git a/WikipediaUnitTests/ArticleFetcherTests.m b/WikipediaUnitTests/ArticleFetcherTests.m index a24eb14..c11ea41 100644 --- a/WikipediaUnitTests/ArticleFetcherTests.m +++ b/WikipediaUnitTests/ArticleFetcherTests.m @@ -25,11 +25,11 @@ #import <OCHamcrest/OCHamcrest.h> @interface ArticleFetcherTests : XCTestCase - <ArticleFetcherDelegate> + @property (strong, nonatomic) MWKDataStore* tempDataStore; @property (strong, nonatomic) AFHTTPRequestOperationManager* mockRequestManager; @property (strong, nonatomic) ArticleFetcher* articleFetcher; -@property (strong, nonatomic) void (^ fetchFinished)(id, id, FetchFinalStatus, NSError*); +@property (strong, nonatomic) void (^ fetchFinished)(MWKArticle*, NSError*); @end @implementation ArticleFetcherTests @@ -51,16 +51,18 @@ MWKArticle* dummyArticle = [self.tempDataStore articleWithTitle:dummyTitle]; MKTArgumentCaptor* successCaptor = [self mockSuccessfulFetchOfArticle:dummyArticle - withManager:self.mockRequestManager]; + withManager:self.mockRequestManager + withStore:self.tempDataStore]; XCTestExpectation* responseExpectation = [self expectationWithDescription:@"articleResponse"]; - self.fetchFinished = ^(id sender, id fetchedData, FetchFinalStatus status, NSError* err) { - assertThat(@(status), is(@(FETCH_FINAL_STATUS_SUCCEEDED))); + @weakify(self) + self.fetchFinished = ^(MWKArticle* article, NSError* err) { + @strongify(self) assertThat(err, is(nilValue())); MWKArticle* savedArticle = [self.tempDataStore articleWithTitle:dummyTitle]; - assertThat(fetchedData, is(equalTo(savedArticle))); - assertThat(@([fetchedData isDeeplyEqualToArticle:savedArticle]), isTrue()); + assertThat(article, is(equalTo(savedArticle))); + assertThat(@([article isDeeplyEqualToArticle:savedArticle]), isTrue()); [responseExpectation fulfill]; }; @@ -79,9 +81,10 @@ AFHTTPRequestOperationManager* manager = mock([AFHTTPRequestOperationManager class]); MKTArgumentCaptor* successBlockCaptor = [self mockSuccessfulFetchOfArticle:dummyArticle - withManager:manager]; + withManager:manager + withStore:self.tempDataStore]; - self.fetchFinished = ^(id sender, id fetchedData, FetchFinalStatus status, NSError* err) { + self.fetchFinished = ^(MWKArticle* article, NSError* err) { [responseExpectation fulfill]; }; @@ -111,10 +114,19 @@ } - (MKTArgumentCaptor*)mockSuccessfulFetchOfArticle:(MWKArticle*)article - withManager:(AFHTTPRequestOperationManager*)manager { - (void)[[ArticleFetcher alloc] initAndFetchSectionsForArticle:article - withManager:manager - thenNotifyDelegate:self]; + withManager:(AFHTTPRequestOperationManager*)manager + withStore:(MWKDataStore*)store { + ArticleFetcher* fetcher = [[ArticleFetcher alloc] init]; + [fetcher fetchSectionsForTitle:article.title inDataStore:store withManager:manager progressBlock:NULL completionBlock:^(MWKArticle* article) { + if (self.fetchFinished) { + self.fetchFinished(article, nil); + } + } errorBlock:^(NSError* error) { + if (self.fetchFinished) { + self.fetchFinished(nil, error); + } + }]; + MKTArgumentCaptor* successCaptor = [MKTArgumentCaptor new]; [MKTVerify(manager) @@ -130,17 +142,6 @@ void (^ successBlock)(AFHTTPRequestOperation*, id response) = [captor value]; NSData* jsonData = [[self wmf_bundle] wmf_dataFromContentsOfFile:fixture ofType:@"json"]; successBlock(nil, jsonData); -} - -#pragma mark - FetchFinishedDelegate - -- (void)fetchFinished:(id)sender - fetchedData:(id)fetchedData - status:(FetchFinalStatus)status - error:(NSError*)error { - if (self.fetchFinished) { - self.fetchFinished(sender, fetchedData, status, error); - } } @end -- To view, visit https://gerrit.wikimedia.org/r/223954 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Icbf0a5515cc93e35580468f074b30073813e0428 Gerrit-PatchSet: 1 Gerrit-Project: apps/ios/wikipedia Gerrit-Branch: 5.0 Gerrit-Owner: Fjalapeno <cfl...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits