YYTestBlacklistWhitelist.m 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. //
  2. // YYTestBlacklistWhitelist.m
  3. // YYModel <https://github.com/ibireme/YYModel>
  4. //
  5. // Created by ibireme on 15/11/29.
  6. // Copyright (c) 2015 ibireme.
  7. //
  8. // This source code is licensed under the MIT-style license found in the
  9. // LICENSE file in the root directory of this source tree.
  10. //
  11. #import <XCTest/XCTest.h>
  12. #import "YYModel.h"
  13. @interface YYTestBlacklistModel : NSObject
  14. @property (nonatomic, strong) NSString *a;
  15. @property (nonatomic, strong) NSString *b;
  16. @property (nonatomic, strong) NSString *c;
  17. @end
  18. @implementation YYTestBlacklistModel
  19. + (NSArray *)modelPropertyBlacklist {
  20. return @[@"a", @"d"];
  21. }
  22. @end
  23. @interface YYTestWhitelistModel : NSObject
  24. @property (nonatomic, strong) NSString *a;
  25. @property (nonatomic, strong) NSString *b;
  26. @property (nonatomic, strong) NSString *c;
  27. @end
  28. @implementation YYTestWhitelistModel
  29. + (NSArray *)modelPropertyWhitelist {
  30. return @[@"a", @"d"];
  31. }
  32. @end
  33. @interface YYTestBlackWhitelistModel : NSObject
  34. @property (nonatomic, strong) NSString *a;
  35. @property (nonatomic, strong) NSString *b;
  36. @property (nonatomic, strong) NSString *c;
  37. @end
  38. @implementation YYTestBlackWhitelistModel
  39. + (NSArray *)modelPropertyBlacklist {
  40. return @[@"a", @"d"];
  41. }
  42. + (NSArray *)modelPropertyWhitelist {
  43. return @[@"a", @"b", @"d"];
  44. }
  45. @end
  46. @interface YYTestBlacklistWhitelist : XCTestCase
  47. @end
  48. @implementation YYTestBlacklistWhitelist
  49. - (void)testBlacklist {
  50. NSString *json = @"{\"a\":\"A\", \"b\":\"B\", \"c\":\"C\", \"d\":\"D\"}";
  51. YYTestBlacklistModel *model = [YYTestBlacklistModel yy_modelWithJSON:json];
  52. XCTAssert(model.a == nil);
  53. XCTAssert(model.b != nil);
  54. XCTAssert(model.c != nil);
  55. NSDictionary *dic = [model yy_modelToJSONObject];
  56. XCTAssert(dic[@"a"] == nil);
  57. XCTAssert(dic[@"b"] != nil);
  58. XCTAssert(dic[@"c"] != nil);
  59. }
  60. - (void)testWhitelist {
  61. NSString *json = @"{\"a\":\"A\", \"b\":\"B\", \"c\":\"C\", \"d\":\"D\"}";
  62. YYTestWhitelistModel *model = [YYTestWhitelistModel yy_modelWithJSON:json];
  63. XCTAssert(model.a != nil);
  64. XCTAssert(model.b == nil);
  65. XCTAssert(model.c == nil);
  66. NSDictionary *dic = [model yy_modelToJSONObject];
  67. XCTAssert(dic[@"a"] != nil);
  68. XCTAssert(dic[@"b"] == nil);
  69. XCTAssert(dic[@"c"] == nil);
  70. }
  71. - (void)testBlackWhitelist {
  72. NSString *json = @"{\"a\":\"A\", \"b\":\"B\", \"c\":\"C\", \"d\":\"D\"}";
  73. YYTestBlackWhitelistModel *model = [YYTestBlackWhitelistModel yy_modelWithJSON:json];
  74. XCTAssert(model.a == nil);
  75. XCTAssert(model.b != nil);
  76. XCTAssert(model.c == nil);
  77. NSDictionary *dic = [model yy_modelToJSONObject];
  78. XCTAssert(dic[@"a"] == nil);
  79. XCTAssert(dic[@"b"] != nil);
  80. XCTAssert(dic[@"c"] == nil);
  81. }
  82. @end