FBErrorBuilderTests.m 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /**
  2. * Copyright (c) 2015-present, Facebook, Inc.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the BSD-style license found in the
  6. * LICENSE file in the root directory of this source tree. An additional grant
  7. * of patent rights can be found in the PATENTS file in the same directory.
  8. */
  9. #import <XCTest/XCTest.h>
  10. #import "FBErrorBuilder.h"
  11. @interface FBErrorBuilderTests : XCTestCase
  12. @end
  13. @implementation FBErrorBuilderTests
  14. - (void)testErrorWithDescription
  15. {
  16. NSString *expectedDescription = @"Magic description";
  17. NSError *error =
  18. [[[FBErrorBuilder builder]
  19. withDescription:expectedDescription]
  20. build];
  21. XCTAssertNotNil(error);
  22. XCTAssertEqualObjects([error localizedDescription], expectedDescription);
  23. }
  24. - (void)testErrorWithDescriptionFormat
  25. {
  26. NSError *error =
  27. [[[FBErrorBuilder builder]
  28. withDescriptionFormat:@"Magic %@", @"bob"]
  29. build];
  30. XCTAssertEqualObjects([error localizedDescription], @"Magic bob");
  31. }
  32. - (void)testInnerError
  33. {
  34. NSError *innerError = [NSError errorWithDomain:@"Domain" code:1 userInfo:@{}];
  35. NSError *error =
  36. [[[FBErrorBuilder builder]
  37. withInnerError:innerError]
  38. build];
  39. XCTAssertEqual(error.userInfo[NSUnderlyingErrorKey], innerError);
  40. }
  41. - (void)testBuildWithError
  42. {
  43. NSString *expectedDescription = @"Magic description";
  44. NSError *error;
  45. BOOL result =
  46. [[[FBErrorBuilder builder]
  47. withDescription:expectedDescription]
  48. buildError:&error];
  49. XCTAssertNotNil(error);
  50. XCTAssertEqualObjects(error.localizedDescription, expectedDescription);
  51. XCTAssertFalse(result);
  52. }
  53. @end