Guest User

Untitled

a guest
May 26th, 2018
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. #import <XCTest/XCTest.h>
  2. #import "Person.h"
  3.  
  4. @interface ParsingJSONTests : XCTestCase
  5.  
  6. @end
  7.  
  8. @implementation ParsingJSONTests
  9.  
  10. - (void)testReadingJSONFile {
  11.  
  12. // Getting the path in the current bundle
  13. NSString *path = [[NSBundle mainBundle] pathForResource:@"sample" ofType:@"json" inDirectory:nil];
  14. if (path) {
  15. // create data from that path
  16. NSData *jsonData = [NSData dataWithContentsOfFile:path];
  17. NSError *error;
  18. if (jsonData) {
  19. NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:jsonData options:[] error:&error];
  20. if (error) {
  21. XCTFail(@"JSONSerialization error: %@", error.localizedDescription);
  22. } else {
  23. // create our Person object
  24. Person *person = [[Person alloc] initWithDict:dict];
  25. XCTAssertEqualObjects(person.name, @"Jane");
  26. XCTAssertEqualObjects(person.email, @"jane@jane.com");
  27. XCTAssertEqualObjects(person.phone, @"917-123-4567");
  28.  
  29. }
  30. } else {
  31. XCTFail(@"data is nil");
  32. }
  33. XCTAssertNotNil(path);
  34. } else {
  35. XCTFail(@"file NOT FOUND");
  36. }
  37.  
  38. }
  39.  
  40. @end
Add Comment
Please, Sign In to add comment