-
Notifications
You must be signed in to change notification settings - Fork 634
/
Copy pathGBIvarsProviderTesting.m
102 lines (90 loc) · 3.84 KB
/
GBIvarsProviderTesting.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//
// GBIvarsProviderTesting.m
// appledoc
//
// Created by Tomaz Kragelj on 26.7.10.
// Copyright (C) 2010 Gentle Bytes. All rights reserved.
//
#import "GBIvarsProvider.h"
@interface GBIvarsProviderTesting : GHTestCase
@end
@implementation GBIvarsProviderTesting
#pragma mark Ivar registration testing
- (void)testRegisterIvar_shouldAddIvarToList {
// setup
GBIvarsProvider *provider = [[GBIvarsProvider alloc] initWithParentObject:self];
GBIvarData *ivar = [GBIvarData ivarDataWithComponents:@[@"NSUInteger", @"_name"]];
// execute
[provider registerIvar:ivar];
// verify
assertThatBool([provider.ivars containsObject:ivar], equalToBool(YES));
assertThatInteger([provider.ivars count], equalToInteger(1));
assertThat(provider.ivars[0], is(ivar));
}
- (void)testRegisterIvar_shouldSetParentObject {
// setup
GBIvarsProvider *provider = [[GBIvarsProvider alloc] initWithParentObject:self];
GBIvarData *ivar = [GBIvarData ivarDataWithComponents:@[@"NSUInteger", @"_name"]];
// execute
[provider registerIvar:ivar];
// verify
assertThat(ivar.parentObject, is(self));
}
- (void)testRegisterIvar_shouldIgnoreSameInstance {
// setup
GBIvarsProvider *provider = [[GBIvarsProvider alloc] initWithParentObject:self];
GBIvarData *ivar = [GBIvarData ivarDataWithComponents:@[@"NSUInteger", @"_name"]];
// execute
[provider registerIvar:ivar];
[provider registerIvar:ivar];
// verify
assertThatInteger([provider.ivars count], equalToInteger(1));
}
- (void)testRegisterIvar_shouldMergeDifferentInstanceWithSameName {
// setup
GBIvarsProvider *provider = [[GBIvarsProvider alloc] initWithParentObject:self];
GBIvarData *source = [GBIvarData ivarDataWithComponents:@[@"int", @"_index"]];
OCMockObject *destination = [OCMockObject niceMockForClass:[GBIvarData class]];
[[[destination stub] andReturn:@"_index"] nameOfIvar];
[[destination expect] mergeDataFromObject:source];
[provider registerIvar:(GBIvarData *)destination];
// execute
[provider registerIvar:source];
// verify
[destination verify];
}
#pragma mark Merging testing
- (void)testMergeDataFromIvarsProvider_shouldMergeAllDifferentIvars {
// setup
GBIvarsProvider *original = [[GBIvarsProvider alloc] initWithParentObject:self];
[original registerIvar:[GBTestObjectsRegistry ivarWithComponents:@"int", @"_i1", nil]];
[original registerIvar:[GBTestObjectsRegistry ivarWithComponents:@"int", @"_i2", nil]];
GBIvarsProvider *source = [[GBIvarsProvider alloc] initWithParentObject:self];
[source registerIvar:[GBTestObjectsRegistry ivarWithComponents:@"int", @"_i1", nil]];
[source registerIvar:[GBTestObjectsRegistry ivarWithComponents:@"int", @"_i3", nil]];
// execute
[original mergeDataFromIvarsProvider:source];
// verify - only basic testing here, details at GBIvarDataTesting!
NSArray *ivars = [original ivars];
assertThatInteger([ivars count], equalToInteger(3));
assertThat([ivars[0] nameOfIvar], is(@"_i1"));
assertThat([ivars[1] nameOfIvar], is(@"_i2"));
assertThat([ivars[2] nameOfIvar], is(@"_i3"));
}
- (void)testMergeDataFromIvarsProvider_shouldPreserveSourceData {
// setup
GBIvarsProvider *original = [[GBIvarsProvider alloc] initWithParentObject:self];
[original registerIvar:[GBTestObjectsRegistry ivarWithComponents:@"int", @"_i1", nil]];
[original registerIvar:[GBTestObjectsRegistry ivarWithComponents:@"int", @"_i2", nil]];
GBIvarsProvider *source = [[GBIvarsProvider alloc] initWithParentObject:self];
[source registerIvar:[GBTestObjectsRegistry ivarWithComponents:@"int", @"_i1", nil]];
[source registerIvar:[GBTestObjectsRegistry ivarWithComponents:@"int", @"_i3", nil]];
// execute
[original mergeDataFromIvarsProvider:source];
// verify - only basic testing here, details at GBIvarDataTesting!
NSArray *ivars = [source ivars];
assertThatInteger([ivars count], equalToInteger(2));
assertThat([ivars[0] nameOfIvar], is(@"_i1"));
assertThat([ivars[1] nameOfIvar], is(@"_i3"));
}
@end