Skip to content

Commit

Permalink
Merge pull request jsonmodel#75 from BB9z/STAssert
Browse files Browse the repository at this point in the history
Replace all NSAssert with STAssert in unit tests.
  • Loading branch information
icanzilb committed Aug 21, 2013
2 parents a05fc1f + 1f3662f commit 51f4a8e
Show file tree
Hide file tree
Showing 14 changed files with 175 additions and 185 deletions.
14 changes: 7 additions & 7 deletions JSONModelDemoTests/UnitTests/ArrayTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@ -(void)setUp
NSString* filePath = [[NSBundle bundleForClass:[JSONModel class]].resourcePath stringByAppendingPathComponent:@"github-iphone.json"];
NSString* jsonContents = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];

NSAssert(jsonContents, @"Can't fetch test data file contents.");
STAssertNotNil(jsonContents, @"Can't fetch test data file contents.");

NSError* err;
repos = [[ReposModel alloc] initWithString: jsonContents error:&err];
NSAssert(!err, [err localizedDescription]);
STAssertNil(err, [err localizedDescription]);

NSAssert(repos, @"Could not load the test data file.");
STAssertNotNil(repos, @"Could not load the test data file.");

}

-(void)testLoading
{
NSAssert([repos.repositories isMemberOfClass:[JSONModelArray class]], @".properties is not a JSONModelArray");
NSAssert([repos.repositories[0] isMemberOfClass:[GitHubRepoModel class]], @".properties[0] is not a GitHubRepoModel");
STAssertTrue([repos.repositories isMemberOfClass:[JSONModelArray class]], @".properties is not a JSONModelArray");
STAssertTrue([repos.repositories[0] isMemberOfClass:[GitHubRepoModel class]], @".properties[0] is not a GitHubRepoModel");
}

/*
Expand All @@ -44,7 +44,7 @@ -(void)testLoading
-(void)testArrayReverseTransformGitHubIssue_14
{
NSDictionary* dict = [repos toDictionary];
NSAssert(dict, @"Could not convert ReposModel back to an NSDictionary");
STAssertNotNil(dict, @"Could not convert ReposModel back to an NSDictionary");
}

/*
Expand All @@ -53,7 +53,7 @@ -(void)testArrayReverseTransformGitHubIssue_14
-(void)testArrayReverseTransformGitHubIssue_15
{
NSString* string = [repos toJSONString];
NSAssert(string, @"Could not convert ReposModel back to a string");
STAssertNotNil(string, @"Could not convert ReposModel back to a string");
}

@end
35 changes: 17 additions & 18 deletions JSONModelDemoTests/UnitTests/BuiltInConversionsTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,23 @@ -(void)setUp
NSString* filePath = [[NSBundle bundleForClass:[JSONModel class]].resourcePath stringByAppendingPathComponent:@"converts.json"];
NSString* jsonContents = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];

NSAssert(jsonContents, @"Can't fetch test data file contents.");
STAssertNotNil(jsonContents, @"Can't fetch test data file contents.");

NSError* err;
b = [[BuiltInConversionsModel alloc] initWithString: jsonContents error:&err];
NSAssert(!err, [err localizedDescription]);

NSAssert(b, @"Could not load the test data file.");
STAssertNil(err, [err localizedDescription]);
STAssertNotNil(b, @"Could not load the test data file.");
}

-(void)testConversions
{
NSAssert(b.isItYesOrNo==YES, @"isItYesOrNo value is not YES");
STAssertTrue(b.isItYesOrNo==YES, @"isItYesOrNo value is not YES");

NSAssert([b.unorderedList isKindOfClass:[NSSet class]], @"unorderedList is not an NSSet object");
NSAssert([b.unorderedList anyObject], @"unorderedList don't have any objects");
STAssertTrue([b.unorderedList isKindOfClass:[NSSet class]], @"unorderedList is not an NSSet object");
STAssertTrue([b.unorderedList anyObject], @"unorderedList don't have any objects");

NSAssert([b.dynamicUnorderedList isKindOfClass:[NSMutableSet class]], @"dynamicUnorderedList is not an NSMutableSet object");
NSAssert([b.dynamicUnorderedList anyObject], @"dynamicUnorderedList don't have any objects");
STAssertTrue([b.dynamicUnorderedList isKindOfClass:[NSMutableSet class]], @"dynamicUnorderedList is not an NSMutableSet object");
STAssertTrue([b.dynamicUnorderedList anyObject], @"dynamicUnorderedList don't have any objects");

#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED
int nrOfObjects = [b.dynamicUnorderedList allObjects].count;
Expand All @@ -47,24 +46,24 @@ -(void)testConversions
#endif

[b.dynamicUnorderedList addObject:@"ADDED"];
NSAssert(nrOfObjects + 1 == [b.dynamicUnorderedList allObjects].count, @"dynamicUnorderedList didn't add an object");
STAssertTrue(nrOfObjects + 1 == [b.dynamicUnorderedList allObjects].count, @"dynamicUnorderedList didn't add an object");

NSAssert([b.stringFromNumber isKindOfClass:[NSString class]], @"stringFromNumber is not an NSString");
NSAssert([b.stringFromNumber isEqualToString:@"19.95"], @"stringFromNumber's value is not 19.95");
STAssertTrue([b.stringFromNumber isKindOfClass:[NSString class]], @"stringFromNumber is not an NSString");
STAssertTrue([b.stringFromNumber isEqualToString:@"19.95"], @"stringFromNumber's value is not 19.95");

NSAssert([b.numberFromString isKindOfClass:[NSNumber class]], @"numberFromString is not an NSNumber");
STAssertTrue([b.numberFromString isKindOfClass:[NSNumber class]], @"numberFromString is not an NSNumber");

//TODO: I had to hardcode the float epsilon below, bcz actually [NSNumber floatValue] was returning a bigger deviation than FLT_EPSILON
// IDEAS?
NSAssert(fabsf([b.numberFromString floatValue]-1230.99)<0.001, @"numberFromString's value is not 1230.99");
STAssertTrue(fabsf([b.numberFromString floatValue]-1230.99)<0.001, @"numberFromString's value is not 1230.99");

NSAssert([b.importantEvent isKindOfClass:[NSDate class]], @"importantEvent is not an NSDate");
NSAssert((long)[b.importantEvent timeIntervalSince1970] == 1353916801, @"importantEvent value was not read properly");
STAssertTrue([b.importantEvent isKindOfClass:[NSDate class]], @"importantEvent is not an NSDate");
STAssertTrue((long)[b.importantEvent timeIntervalSince1970] == 1353916801, @"importantEvent value was not read properly");

//test for a valid URL
//https://github.com/icanzilb/JSONModel/pull/60
NSAssert(b.websiteURL, @"URL parsing did return nil");
NSAssert(b.websiteURL.query, @"key1=test");
STAssertNotNil(b.websiteURL, @"URL parsing did return nil");
STAssertNotNil(b.websiteURL.query, @"key1=test");
}

@end
13 changes: 6 additions & 7 deletions JSONModelDemoTests/UnitTests/CustomPropsTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,25 @@ -(void)setUp
NSString* filePath = [[NSBundle bundleForClass:[JSONModel class]].resourcePath stringByAppendingPathComponent:@"colors.json"];
NSString* jsonContents = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];

NSAssert(jsonContents, @"Can't fetch test data file contents.");
STAssertNotNil(jsonContents, @"Can't fetch test data file contents.");

NSError* err;
c = [[CustomPropertyModel alloc] initWithString: jsonContents error:&err];
NSAssert(!err, [err localizedDescription]);

NSAssert(c, @"Could not load the test data file.");
STAssertNil(err, [err localizedDescription]);
STAssertNotNil(c, @"Could not load the test data file.");
}

-(void)testColors
{
#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED
NSAssert([c.redColor isKindOfClass:[UIColor class]], @"redColor is not a Color instance");
STAssertTrue([c.redColor isKindOfClass:[UIColor class]], @"redColor is not a Color instance");
CGColorRef redColor = [UIColor redColor].CGColor;
#else
NSAssert([c.redColor isKindOfClass:[NSColor class]], @"redColor is not a Color instance");
STAssertTrue([c.redColor isKindOfClass:[NSColor class]], @"redColor is not a Color instance");
CGColorRef redColor = [NSColor redColor].CGColor;
#endif

NSAssert(CGColorEqualToColor(c.redColor.CGColor, redColor), @"redColor's value is not red color");
STAssertTrue(CGColorEqualToColor(c.redColor.CGColor, redColor), @"redColor's value is not red color");
}


Expand Down
16 changes: 8 additions & 8 deletions JSONModelDemoTests/UnitTests/IdPropertyTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ -(void)setUp
NSString* filePath = [[NSBundle bundleForClass:[JSONModel class]].resourcePath stringByAppendingPathComponent:@"post.json"];
NSString* jsonContents = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];

NSAssert(jsonContents, @"Can't fetch test data file contents.");
STAssertNotNil(jsonContents, @"Can't fetch test data file contents.");

NSError* err;
posts = [[PostsModel alloc] initWithString: jsonContents error:&err];
NSAssert(!err, [err localizedDescription]);
STAssertTrue(!err, [err localizedDescription]);

NSAssert(posts, @"Could not load the test data file.");
STAssertNotNil(posts, @"Could not load the test data file.");
}

-(void)testEquality
Expand All @@ -39,17 +39,17 @@ -(void)testEquality
PostsModel* posts1 = [[PostsModel alloc] initWithString: jsonContents error:nil];
PostModel* post = posts.posts[0];

NSAssert([post isEqual:posts1.posts[0]], @"Equal to another different model object");
STAssertTrue([post isEqual:posts1.posts[0]], @"Equal to another different model object");

NSAssert([posts.posts indexOfObject: posts1.posts[1]]==1, @"NSArray searching for a model object failed" );
STAssertTrue([posts.posts indexOfObject: posts1.posts[1]]==1, @"NSArray searching for a model object failed" );
}

-(void)testCompareInequality
{
PostModel* post = posts.posts[0];
NSAssert(![post isEqual:nil], @"Equal to nil object");
NSAssert(![post isEqual:[NSNull null]], @"Equal to NSNull object");
NSAssert(![post isEqual:posts.posts[1]], @"Equal to another different model object");
STAssertTrue(![post isEqual:nil], @"Equal to nil object");
STAssertTrue(![post isEqual:[NSNull null]], @"Equal to NSNull object");
STAssertTrue(![post isEqual:posts.posts[1]], @"Equal to another different model object");
}


Expand Down
8 changes: 4 additions & 4 deletions JSONModelDemoTests/UnitTests/InitFromWebTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ -(void)setUp
NSString* filePath = [[NSBundle bundleForClass:[JSONModel class]].resourcePath stringByAppendingPathComponent:@"nestedData.json"];
jsonContents = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];

NSAssert(jsonContents, @"Can't fetch test data file contents.");
STAssertNotNil(jsonContents, @"Can't fetch test data file contents.");
}

-(void)testInitFromWeb
Expand All @@ -44,14 +44,14 @@ -(void)testInitFromWeb
__block NestedModel* nested = [[NestedModel alloc] initFromURLWithString:jsonURLString
completion:^(NestedModel *model, JSONModelError *err) {

NSAssert(nested==model, @"async initialization didn't work");
NSAssert(model.images.count>0, @"content not initialized from async init");
STAssertTrue(nested==model, @"async initialization didn't work");
STAssertTrue(model.images.count>0, @"content not initialized from async init");

[NSURLConnection setResponseDelay:0];
[[MTTestSemaphor semaphore] lift: semaphorKey];
}];

NSAssert(nested.isLoading, @"isLoading property not set during load");
STAssertTrue(nested.isLoading, @"isLoading property not set during load");
[[MTTestSemaphor semaphore] waitForKey: semaphorKey];
}

Expand Down
30 changes: 15 additions & 15 deletions JSONModelDemoTests/UnitTests/JSONAPITests.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ -(void)testBaseURL

NSURLRequest* request = [NSURLConnection lastRequest];
NSString* absString = [request.URL absoluteString];
NSAssert([absString hasPrefix: apiBaseUrlString], @"URL request not start with base URL");
STAssertTrue([absString hasPrefix: apiBaseUrlString], @"URL request not start with base URL");

[[MTTestSemaphor semaphore] lift: semaphorKey];

Expand All @@ -52,7 +52,7 @@ -(void)testContentType
completion:^(NSDictionary *json, JSONModelError *err) {

NSURLRequest* request = [NSURLConnection lastRequest];
NSAssert([[request valueForHTTPHeaderField:@"Content-type"] hasPrefix:ctype], @"request content type was not MyCustomType");
STAssertTrue([[request valueForHTTPHeaderField:@"Content-type"] hasPrefix:ctype], @"request content type was not MyCustomType");

[[MTTestSemaphor semaphore] lift: semaphorKey];
[JSONHTTPClient setRequestContentType:kContentTypeAutomatic];
Expand Down Expand Up @@ -80,7 +80,7 @@ -(void)testGetAPIRequests
NSURLRequest* request = [NSURLConnection lastRequest];
NSString* absString = [request.URL absoluteString];
NSString* desiredString = @"http://localhost/test.json/testGetAPIRequests";
NSAssert( [absString isEqualToString: desiredString] , @"URL does not match");
STAssertTrue( [absString isEqualToString: desiredString] , @"URL does not match");

[[MTTestSemaphor semaphore] lift: semaphorKey];

Expand All @@ -95,7 +95,7 @@ -(void)testGetAPIRequests
NSURLRequest* request = [NSURLConnection lastRequest];
NSString* absString = [request.URL absoluteString];
NSString* desiredString = @"http://localhost/test.json/testGetAPIRequests?key1=ma%20rin&key2=marin";
NSAssert( [absString isEqualToString: desiredString] , @"URL does not match");
STAssertTrue( [absString isEqualToString: desiredString] , @"URL does not match");

[[MTTestSemaphor semaphore] lift: semaphorKey];

Expand All @@ -119,10 +119,10 @@ -(void)testPostAPIRequests
NSURLRequest* request = [NSURLConnection lastRequest];
NSString* absString = [request.URL absoluteString];
NSString* desiredString = @"http://localhost/test.json/testPostAPIRequests";
NSAssert( [absString isEqualToString: desiredString] , @"URL does not match");
STAssertTrue( [absString isEqualToString: desiredString] , @"URL does not match");

NSString* paramsSent = [[NSString alloc] initWithData:[request HTTPBody] encoding:NSUTF8StringEncoding];
NSAssert([paramsSent isEqualToString: @"key1=ma%20rin&key2=marin"], @"request body data did not match the post encoded params");
STAssertTrue([paramsSent isEqualToString: @"key1=ma%20rin&key2=marin"], @"request body data did not match the post encoded params");

[[MTTestSemaphor semaphore] lift: semaphorKey];

Expand All @@ -146,15 +146,15 @@ -(void)testRpcRequest
NSURLRequest* request = [NSURLConnection lastRequest];
NSString* absString = [request.URL absoluteString];
NSString* desiredString = @"http://localhost/test.json/";
NSAssert( [absString isEqualToString: desiredString] , @"URL does not match");
STAssertTrue([absString isEqualToString: desiredString], @"URL does not match");

NSString* jsonSent = [[NSString alloc] initWithData:[request HTTPBody] encoding:NSUTF8StringEncoding];
RpcRequestModel* jsonRequest = [[RpcRequestModel alloc] initWithString:jsonSent error:nil];
NSAssert(jsonRequest, @"RPC request is not valid");
STAssertNotNil(jsonRequest, @"RPC request is not valid");

NSAssert(jsonRequest.id, @"id is nil");
NSAssert([jsonRequest.params count]==0, @"params not an empty array");
NSAssert([jsonRequest.method isEqualToString: semaphorKey], @"method name does not match");
STAssertNotNil(jsonRequest.id, @"id is nil");
STAssertTrue([jsonRequest.params count]==0, @"params not an empty array");
STAssertTrue([jsonRequest.method isEqualToString: semaphorKey], @"method name does not match");

[[MTTestSemaphor semaphore] lift: semaphorKey];
}];
Expand All @@ -169,11 +169,11 @@ -(void)testRpcRequest
NSURLRequest* request = [NSURLConnection lastRequest];
NSString* jsonSent = [[NSString alloc] initWithData:[request HTTPBody] encoding:NSUTF8StringEncoding];
RpcRequestModel* jsonRequest = [[RpcRequestModel alloc] initWithString:jsonSent error:nil];
NSAssert(jsonRequest, @"RPC request is not valid");
STAssertNotNil(jsonRequest, @"RPC request is not valid");

NSAssert([jsonRequest.params[0] isEqualToString: @"chicken"], @"first param is not chicken");
NSAssert([jsonRequest.params[1] isEqualToNumber:@1], @"second param is not 1");
NSAssert([jsonRequest.params[2] count]==2, @"third param is not 2 element array");
STAssertTrue([jsonRequest.params[0] isEqualToString: @"chicken"], @"first param is not chicken");
STAssertTrue([jsonRequest.params[1] isEqualToNumber:@1], @"second param is not 1");
STAssertTrue([jsonRequest.params[2] count]==2, @"third param is not 2 element array");

[[MTTestSemaphor semaphore] lift: semaphorKey];
}];
Expand Down
Loading

0 comments on commit 51f4a8e

Please sign in to comment.