Skip to content

Commit

Permalink
添加部分测试代码
Browse files Browse the repository at this point in the history
  • Loading branch information
gonefish committed Sep 17, 2014
1 parent 0875c29 commit 72dc0c4
Showing 5 changed files with 63 additions and 12 deletions.
2 changes: 2 additions & 0 deletions GQURLDispatcher/GQURLDispatcher/GQURLDispatcher.h
Original file line number Diff line number Diff line change
@@ -17,6 +17,8 @@

- (BOOL)dispatchURL:(NSURL *)url withObject:(id)anObject;

- (NSArray *)responders;

- (void)registerResponder:(id <GQURLResponder>)responder;

- (void)unregisterResponder:(id <GQURLResponder>)responder;
15 changes: 9 additions & 6 deletions GQURLDispatcher/GQURLDispatcher/GQURLDispatcher.m
Original file line number Diff line number Diff line change
@@ -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 <GQURLResponder>)responder
{
if ([self.responders containsObject:responder]) {
[self unregisterResponder:responder];
}

[self.responders addObject:responder];
[self.responderList addObject:responder];
}

- (void)unregisterResponder:(id <GQURLResponder>)responder
{
[self.responders removeObject:responder];
[self.responderList removeObject:responder];
}

@end
50 changes: 48 additions & 2 deletions GQURLDispatcher/GQURLDispatcherTests/GQURLDispatcherTests.m
Original file line number Diff line number Diff line change
@@ -7,9 +7,13 @@
//

#import <XCTest/XCTest.h>
#import "GQURLDispatcher.h"
#import "GQURLResponder.h"
#import <OCMock/OCMock.h>

@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
2 changes: 1 addition & 1 deletion Podfile
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions Podfile.lock
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 72dc0c4

Please sign in to comment.