diff --git a/GQURLDispatcher/GQURLDispatcher/GQURLDispatcher.h b/GQURLDispatcher/GQURLDispatcher/GQURLDispatcher.h index ee61b4e..b067f0f 100644 --- a/GQURLDispatcher/GQURLDispatcher/GQURLDispatcher.h +++ b/GQURLDispatcher/GQURLDispatcher/GQURLDispatcher.h @@ -17,6 +17,8 @@ - (BOOL)dispatchURL:(NSURL *)url withObject:(id)anObject; +- (NSArray *)responders; + - (void)registerResponder:(id )responder; - (void)unregisterResponder:(id )responder; diff --git a/GQURLDispatcher/GQURLDispatcher/GQURLDispatcher.m b/GQURLDispatcher/GQURLDispatcher/GQURLDispatcher.m index 0c2f98b..63291d5 100644 --- a/GQURLDispatcher/GQURLDispatcher/GQURLDispatcher.m +++ b/GQURLDispatcher/GQURLDispatcher/GQURLDispatcher.m @@ -10,9 +10,7 @@ @interface GQURLDispatcher () -+ (instancetype)sharedInstance; - -@property (nonatomic, strong) NSMutableArray *responders; +@property (nonatomic, strong) NSMutableArray *responderList; @end @@ -35,7 +33,7 @@ - (id)init self = [super init]; if (self) { - self.responders = [NSMutableArray array]; + self.responderList = [NSMutableArray array]; } return self; @@ -67,18 +65,23 @@ - (BOOL)dispatchURL:(NSURL *)url withObject:(id)anObject } +- (NSArray *)responders +{ + return [self.responderList copy]; +} + - (void)registerResponder:(id )responder { if ([self.responders containsObject:responder]) { [self unregisterResponder:responder]; } - [self.responders addObject:responder]; + [self.responderList addObject:responder]; } - (void)unregisterResponder:(id )responder { - [self.responders removeObject:responder]; + [self.responderList removeObject:responder]; } @end diff --git a/GQURLDispatcher/GQURLDispatcherTests/GQURLDispatcherTests.m b/GQURLDispatcher/GQURLDispatcherTests/GQURLDispatcherTests.m index fa04ee3..4e972fa 100644 --- a/GQURLDispatcher/GQURLDispatcherTests/GQURLDispatcherTests.m +++ b/GQURLDispatcher/GQURLDispatcherTests/GQURLDispatcherTests.m @@ -7,9 +7,13 @@ // #import +#import "GQURLDispatcher.h" +#import "GQURLResponder.h" +#import @interface GQURLDispatcherTests : XCTestCase +@property (nonatomic, strong) GQURLDispatcher *testURLDispatcher; @end @implementation GQURLDispatcherTests @@ -18,17 +22,59 @@ - (void)setUp { [super setUp]; // Put setup code here. This method is called before the invocation of each test method in the class. + + self.testURLDispatcher = [[GQURLDispatcher alloc] init]; } - (void)tearDown { // Put teardown code here. This method is called after the invocation of each test method in the class. [super tearDown]; + + self.testURLDispatcher = nil; } -- (void)testExample +- (void)testSharedInstance { - XCTFail(@"No implementation for \"%s\"", __PRETTY_FUNCTION__); + XCTAssertEqual([GQURLDispatcher sharedInstance], [GQURLDispatcher sharedInstance], @""); +} + +- (void)testRegisterResponder +{ + XCTAssertEqual(0, [[self.testURLDispatcher responders] count], @""); + + id responder1 = OCMProtocolMock(@protocol(GQURLResponder)); + + [self.testURLDispatcher registerResponder:responder1]; + + XCTAssertEqual(1, [[self.testURLDispatcher responders] count], @""); + + [self.testURLDispatcher registerResponder:responder1]; + + XCTAssertEqual(1, [[self.testURLDispatcher responders] count], @""); + + id responder2 = OCMProtocolMock(@protocol(GQURLResponder)); + + [self.testURLDispatcher registerResponder:responder2]; + + XCTAssertEqual(2, [[self.testURLDispatcher responders] count], @""); +} + +- (void)testUnregisterResponder +{ + id responder1 = OCMProtocolMock(@protocol(GQURLResponder)); + + id responder2 = OCMProtocolMock(@protocol(GQURLResponder)); + + [self.testURLDispatcher registerResponder:responder1]; + + [self.testURLDispatcher unregisterResponder:responder2]; + + XCTAssertEqual(1, [[self.testURLDispatcher responders] count], @""); + + [self.testURLDispatcher unregisterResponder:responder1]; + + XCTAssertEqual(0, [[self.testURLDispatcher responders] count], @""); } @end diff --git a/Podfile b/Podfile index 956bcd3..90be6fb 100644 --- a/Podfile +++ b/Podfile @@ -2,5 +2,5 @@ workspace 'GQURLDispatcher' xcodeproj 'GQURLDispatcher/GQURLDispatcher.xcodeproj' target :GQURLDispatcherTests, :exclusive => true do - pod 'OCMock', '~> 2.2.4' + pod 'OCMock', '~> 3.1.1' end diff --git a/Podfile.lock b/Podfile.lock index 605dde2..a718b91 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -1,10 +1,10 @@ PODS: - - OCMock (2.2.4) + - OCMock (3.1.1) DEPENDENCIES: - - OCMock (~> 2.2.4) + - OCMock (~> 3.1.1) SPEC CHECKSUMS: - OCMock: 6db79185520e24f9f299548f2b8b07e41d881bd5 + OCMock: f6cb8c162ab9d5620dddf411282c7b2c0ee78854 COCOAPODS: 0.33.1