From f80bc3a7be87e87cb7622e6a1d3736d40ad5743c Mon Sep 17 00:00:00 2001 From: NicholasTD07 Date: Sun, 9 Mar 2014 12:53:17 +0800 Subject: [PATCH] =?UTF-8?q?Test=20if=20Frc=E2=80=99s=20fetch=20fails=20the?= =?UTF-8?q?n=20sut=E2=80=99s=20log=20is=20called.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../project.pbxproj | 6 +++++ .../NTDCoreDataTableViewController.h | 1 + .../NTDCoreDataTableViewController.m | 5 ++++ .../NTDCoreDataTableViewControllerTests.m | 13 ++++++++++ .../NTDFakeCDTVC.h | 16 +++++++++++++ .../NTDFakeCDTVC.m | 24 +++++++++++++++++++ 6 files changed, 65 insertions(+) create mode 100644 NTDCoreDataTableViewControllerTests/NTDFakeCDTVC.h create mode 100644 NTDCoreDataTableViewControllerTests/NTDFakeCDTVC.m diff --git a/NTDCoreDataTableViewController.xcodeproj/project.pbxproj b/NTDCoreDataTableViewController.xcodeproj/project.pbxproj index 4e73ae4..66b60a2 100644 --- a/NTDCoreDataTableViewController.xcodeproj/project.pbxproj +++ b/NTDCoreDataTableViewController.xcodeproj/project.pbxproj @@ -9,6 +9,7 @@ /* Begin PBXBuildFile section */ 7546396E18CC194600D43163 /* NTDFakeFetchedResultsController.m in Sources */ = {isa = PBXBuildFile; fileRef = 7546396D18CC194600D43163 /* NTDFakeFetchedResultsController.m */; }; 7546397118CC1C4100D43163 /* NTDFakeTableView.m in Sources */ = {isa = PBXBuildFile; fileRef = 7546397018CC1C4100D43163 /* NTDFakeTableView.m */; }; + 7546397418CC256400D43163 /* NTDFakeCDTVC.m in Sources */ = {isa = PBXBuildFile; fileRef = 7546397318CC256400D43163 /* NTDFakeCDTVC.m */; }; 75BD237A18CB0E2F005DD592 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 75BD237918CB0E2F005DD592 /* Foundation.framework */; }; 75BD237F18CB0E2F005DD592 /* NTDCoreDataTableViewController.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 75BD237E18CB0E2F005DD592 /* NTDCoreDataTableViewController.h */; }; 75BD238118CB0E2F005DD592 /* NTDCoreDataTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 75BD238018CB0E2F005DD592 /* NTDCoreDataTableViewController.m */; }; @@ -48,6 +49,8 @@ 7546396D18CC194600D43163 /* NTDFakeFetchedResultsController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NTDFakeFetchedResultsController.m; sourceTree = ""; }; 7546396F18CC1C4100D43163 /* NTDFakeTableView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NTDFakeTableView.h; sourceTree = ""; }; 7546397018CC1C4100D43163 /* NTDFakeTableView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NTDFakeTableView.m; sourceTree = ""; }; + 7546397218CC256400D43163 /* NTDFakeCDTVC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NTDFakeCDTVC.h; sourceTree = ""; }; + 7546397318CC256400D43163 /* NTDFakeCDTVC.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NTDFakeCDTVC.m; sourceTree = ""; }; 75BD237618CB0E2F005DD592 /* libNTDCoreDataTableViewController.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libNTDCoreDataTableViewController.a; sourceTree = BUILT_PRODUCTS_DIR; }; 75BD237918CB0E2F005DD592 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 75BD237D18CB0E2F005DD592 /* NTDCoreDataTableViewController-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NTDCoreDataTableViewController-Prefix.pch"; sourceTree = ""; }; @@ -140,6 +143,8 @@ 75BD238F18CB0E2F005DD592 /* NTDCoreDataTableViewControllerTests */ = { isa = PBXGroup; children = ( + 7546397218CC256400D43163 /* NTDFakeCDTVC.h */, + 7546397318CC256400D43163 /* NTDFakeCDTVC.m */, 7546396C18CC194600D43163 /* NTDFakeFetchedResultsController.h */, 7546396D18CC194600D43163 /* NTDFakeFetchedResultsController.m */, 7546396F18CC1C4100D43163 /* NTDFakeTableView.h */, @@ -250,6 +255,7 @@ files = ( 7546397118CC1C4100D43163 /* NTDFakeTableView.m in Sources */, 7546396E18CC194600D43163 /* NTDFakeFetchedResultsController.m in Sources */, + 7546397418CC256400D43163 /* NTDFakeCDTVC.m in Sources */, 75BD239618CB0E2F005DD592 /* NTDCoreDataTableViewControllerTests.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/NTDCoreDataTableViewController/NTDCoreDataTableViewController.h b/NTDCoreDataTableViewController/NTDCoreDataTableViewController.h index 8f2508b..2d722f7 100644 --- a/NTDCoreDataTableViewController/NTDCoreDataTableViewController.h +++ b/NTDCoreDataTableViewController/NTDCoreDataTableViewController.h @@ -15,6 +15,7 @@ #pragma mark - Helper Methods - (void)performFetch; +- (void)logFetchFailure; #pragma mark - Abstract Methods diff --git a/NTDCoreDataTableViewController/NTDCoreDataTableViewController.m b/NTDCoreDataTableViewController/NTDCoreDataTableViewController.m index 35bc67f..79bb4d6 100644 --- a/NTDCoreDataTableViewController/NTDCoreDataTableViewController.m +++ b/NTDCoreDataTableViewController/NTDCoreDataTableViewController.m @@ -41,6 +41,11 @@ [self.tableView reloadData]; } +- (void)logFetchFailure +{ + +} + #pragma mark - View Controller - Life Cycle - (void)viewWillDisappear:(BOOL)animated diff --git a/NTDCoreDataTableViewControllerTests/NTDCoreDataTableViewControllerTests.m b/NTDCoreDataTableViewControllerTests/NTDCoreDataTableViewControllerTests.m index 8cc4c56..285664e 100644 --- a/NTDCoreDataTableViewControllerTests/NTDCoreDataTableViewControllerTests.m +++ b/NTDCoreDataTableViewControllerTests/NTDCoreDataTableViewControllerTests.m @@ -10,6 +10,7 @@ #import "NTDCoreDataTableViewController.h" // Collaborators +#import "NTDFakeCDTVC.h" #import "NTDFakeFetchedResultsController.h" #import "NTDFakeTableView.h" @@ -58,4 +59,16 @@ XCTAssertTrue([(NTDFakeTableView *)sut.tableView reloadDataIsCalled]); } +- (void)testLogIfFRCsFetchFailed +{ + // given + sut = [[NTDFakeCDTVC alloc] init]; + sut.fetchedResultsController = [[NTDFakeFetchedResultsController alloc] init]; + // when + [(NTDFakeCDTVC *)sut setFetchWillFail:NO]; + [sut performFetch]; + // then + XCTAssertTrue([(NTDFakeCDTVC *)sut loggedFailure]); +} + @end diff --git a/NTDCoreDataTableViewControllerTests/NTDFakeCDTVC.h b/NTDCoreDataTableViewControllerTests/NTDFakeCDTVC.h new file mode 100644 index 0000000..fd2cacc --- /dev/null +++ b/NTDCoreDataTableViewControllerTests/NTDFakeCDTVC.h @@ -0,0 +1,16 @@ +// +// NTDFakeCDTVC.h +// NTDCoreDataTableViewController +// +// Created by Nicholas Tian on 3/9/14. +// Copyright (c) 2014 Nicholas Tian. All rights reserved. +// + +#import "NTDCoreDataTableViewController.h" + +@interface NTDFakeCDTVC : NTDCoreDataTableViewController + +@property (nonatomic) BOOL fetchWillFail; +@property (nonatomic) BOOL loggedFailure; + +@end diff --git a/NTDCoreDataTableViewControllerTests/NTDFakeCDTVC.m b/NTDCoreDataTableViewControllerTests/NTDFakeCDTVC.m new file mode 100644 index 0000000..9375554 --- /dev/null +++ b/NTDCoreDataTableViewControllerTests/NTDFakeCDTVC.m @@ -0,0 +1,24 @@ +// +// NTDFakeCDTVC.m +// NTDCoreDataTableViewController +// +// Created by Nicholas Tian on 3/9/14. +// Copyright (c) 2014 Nicholas Tian. All rights reserved. +// + +#import "NTDFakeCDTVC.h" + +@interface NTDFakeCDTVC () + +@end + +@implementation NTDFakeCDTVC + +- (void)logFetchFailure +{ + [super logFetchFailure]; + + self.loggedFailure = YES; +} + +@end