-
Notifications
You must be signed in to change notification settings - Fork 644
/
GBProcessor-CommentsTesting.m
218 lines (189 loc) · 9.33 KB
/
GBProcessor-CommentsTesting.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
//
// GBProcessor-CommentsTesting.m
// appledoc
//
// Created by Tomaz Kragelj on 27.8.10.
// Copyright (C) 2010 Gentle Bytes. All rights reserved.
//
#import "GBApplicationSettingsProvider.h"
#import "GBDataObjects.h"
#import "GBStore.h"
#import "GBProcessor.h"
@interface GBProcessorCommentsTesting : GHTestCase
- (OCMockObject *)mockSettingsProviderKeepObject:(BOOL)objects members:(BOOL)members;
- (OCMockObject *)mockSettingsProviderRepeatFirst:(BOOL)repeat;
- (OCMockObject *)niceCommentMockExpectingRegisterParagraph;
- (GBStore *)storeWithMethodWithComment:(GBComment *)comment;
@end
#pragma mark -
@implementation GBProcessorCommentsTesting
#pragma mark Classes comments processing
- (void)testProcessObjectsFromStore_shouldProcessClassComments {
// setup
GBProcessor *processor = [GBProcessor processorWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
OCMockObject *comment = [self niceCommentMockExpectingRegisterParagraph];
GBStore *store = [GBTestObjectsRegistry storeWithClassWithComment:comment];
// execute
[processor processObjectsFromStore:store];
// verify - we just want to make sure we invoke comments processing!
[comment verify];
}
- (void)testProcessObjectsFromStore_shouldProcessClassMethodComments {
// setup
GBProcessor *processor = [GBProcessor processorWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
OCMockObject *comment1 = [self niceCommentMockExpectingRegisterParagraph];
OCMockObject *comment2 = [self niceCommentMockExpectingRegisterParagraph];
GBClassData *class = [GBClassData classDataWithName:@"Class"];
[class.methods registerMethod:[GBTestObjectsRegistry instanceMethodWithName:@"method1" comment:comment1]];
[class.methods registerMethod:[GBTestObjectsRegistry instanceMethodWithName:@"method2" comment:comment2]];
GBStore *store = [GBTestObjectsRegistry storeByPerformingSelector:@selector(registerClass:) withObject:class];
// execute
[processor processObjectsFromStore:store];
// verify - we just want to make sure we invoke comments processing!
[comment1 verify];
[comment2 verify];
}
- (void)testProcessObjectsFromStore_shouldSetEmptyClassCommentToNil {
// setup
GBProcessor *processor = [GBProcessor processorWithSettingsProvider:[self mockSettingsProviderKeepObject:YES members:YES]];
GBComment *comment = [GBComment commentWithStringValue:nil];
GBStore *store = [GBTestObjectsRegistry storeWithClassWithComment:comment];
// execute
[processor processObjectsFromStore:store];
// verify
assertThat([[store.classes anyObject] comment], is(nil));
}
#pragma mark Categories comments processing
- (void)testProcessObjectsFromStore_shouldProcessCategoryComments {
// setup
GBProcessor *processor = [GBProcessor processorWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
OCMockObject *comment = [self niceCommentMockExpectingRegisterParagraph];
GBStore *store = [GBTestObjectsRegistry storeWithCategoryWithComment:comment];
// execute
[processor processObjectsFromStore:store];
// verify - we just want to make sure we invoke comments processing!
[comment verify];
}
- (void)testProcessObjectsFromStore_shouldProcessCategoryMethodComments {
// setup
GBProcessor *processor = [GBProcessor processorWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
OCMockObject *comment1 = [self niceCommentMockExpectingRegisterParagraph];
OCMockObject *comment2 = [self niceCommentMockExpectingRegisterParagraph];
GBCategoryData *category = [GBCategoryData categoryDataWithName:@"Category" className:@"Class"];
[category.methods registerMethod:[GBTestObjectsRegistry instanceMethodWithName:@"method1" comment:comment1]];
[category.methods registerMethod:[GBTestObjectsRegistry instanceMethodWithName:@"method2" comment:comment2]];
GBStore *store = [GBTestObjectsRegistry storeByPerformingSelector:@selector(registerCategory:) withObject:category];
// execute
[processor processObjectsFromStore:store];
// verify - we just want to make sure we invoke comments processing!
[comment1 verify];
[comment2 verify];
}
- (void)testProcessObjectsFromStore_shouldSetEmptyCategoryCommentToNil {
// setup
GBProcessor *processor = [GBProcessor processorWithSettingsProvider:[self mockSettingsProviderKeepObject:YES members:YES]];
GBComment *comment = [GBComment commentWithStringValue:nil];
GBStore *store = [GBTestObjectsRegistry storeWithCategoryWithComment:comment];
// execute
[processor processObjectsFromStore:store];
// verify
assertThat([[store.categories anyObject] comment], is(nil));
}
#pragma mark Protocols comments processing
- (void)testProcessObjectsFromStore_shouldProcessProtocolComments {
// setup
GBProcessor *processor = [GBProcessor processorWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
OCMockObject *comment = [self niceCommentMockExpectingRegisterParagraph];
GBStore *store = [GBTestObjectsRegistry storeWithProtocolWithComment:comment];
// execute
[processor processObjectsFromStore:store];
// verify - we just want to make sure we invoke comments processing!
[comment verify];
}
- (void)testProcessObjectsFromStore_shouldProcessProtocolMethodComments {
// setup
GBProcessor *processor = [GBProcessor processorWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
OCMockObject *comment1 = [self niceCommentMockExpectingRegisterParagraph];
OCMockObject *comment2 = [self niceCommentMockExpectingRegisterParagraph];
GBProtocolData *protocol = [GBProtocolData protocolDataWithName:@"Protocol"];
[protocol.methods registerMethod:[GBTestObjectsRegistry instanceMethodWithName:@"method1" comment:comment1]];
[protocol.methods registerMethod:[GBTestObjectsRegistry instanceMethodWithName:@"method2" comment:comment2]];
GBStore *store = [GBTestObjectsRegistry storeByPerformingSelector:@selector(registerProtocol:) withObject:protocol];
// execute
[processor processObjectsFromStore:store];
// verify - we just want to make sure we invoke comments processing!
[comment1 verify];
[comment2 verify];
}
- (void)testProcessObjectsFromStore_shouldSetEmptyProtocolCommentToNil {
// setup
GBProcessor *processor = [GBProcessor processorWithSettingsProvider:[self mockSettingsProviderKeepObject:YES members:YES]];
GBComment *comment = [GBComment commentWithStringValue:nil];
GBStore *store = [GBTestObjectsRegistry storeWithProtocolWithComment:comment];
// execute
[processor processObjectsFromStore:store];
// verify
assertThat([[store.protocols anyObject] comment], is(nil));
}
#pragma mark Document comments processing
- (void)testProcessObjectsFromStore_shouldProcessDocumentComments {
// setup
GBProcessor *processor = [GBProcessor processorWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
OCMockObject *comment = [self niceCommentMockExpectingRegisterParagraph];
GBStore *store = [GBTestObjectsRegistry storeWithDocumentWithComment:comment];
// execute
[processor processObjectsFromStore:store];
// verify - we just want to make sure we invoke comments processing!
[comment verify];
}
- (void)testProcessObjectsFromStore_shouldSetEmptyDocumentCommentToNil {
// setup
GBProcessor *processor = [GBProcessor processorWithSettingsProvider:[self mockSettingsProviderKeepObject:YES members:YES]];
GBComment *comment = [GBComment commentWithStringValue:nil];
GBStore *store = [GBTestObjectsRegistry storeWithDocumentWithComment:comment];
// execute
[processor processObjectsFromStore:store];
// verify
assertThat([[store.documents anyObject] comment], is(nil));
}
#pragma mark Method comment processing
- (void)testProcessObjectsFromStore_shouldSetEmptyMethodCommentToNil {
// setup
GBProcessor *processor = [GBProcessor processorWithSettingsProvider:[self mockSettingsProviderKeepObject:YES members:YES]];
GBComment *comment = [GBComment commentWithStringValue:nil];
GBClassData *class = [GBClassData classDataWithName:@"Class"];
GBMethodData *method = [GBTestObjectsRegistry instanceMethodWithNames:@"arg1", @"arg2", @"arg3", nil];
[method setComment:comment];
[class.methods registerMethod:method];
GBStore *store = [GBTestObjectsRegistry storeByPerformingSelector:@selector(registerClass:) withObject:class];
// execute
[processor processObjectsFromStore:store];
// verify
assertThat(method.comment, is(nil));
}
#pragma mark Creation methods
- (OCMockObject *)mockSettingsProviderKeepObject:(BOOL)objects members:(BOOL)members {
OCMockObject *result = [GBTestObjectsRegistry mockSettingsProvider];
[GBTestObjectsRegistry settingsProvider:result keepObjects:objects keepMembers:members];
return result;
}
- (OCMockObject *)mockSettingsProviderRepeatFirst:(BOOL)repeat {
OCMockObject *result = [GBTestObjectsRegistry mockSettingsProvider];
[[[result stub] andReturnValue:[NSNumber numberWithBool:repeat]] repeatFirstParagraphForMemberDescription];
return result;
}
- (OCMockObject *)niceCommentMockExpectingRegisterParagraph {
OCMockObject *result = [OCMockObject niceMockForClass:[GBComment class]];
[[[result stub] andReturn:@"Paragraph"] stringValue];
// [[result expect] registerParagraph:OCMOCK_ANY];
return result;
}
- (GBStore *)storeWithMethodWithComment:(GBComment *)comment {
GBClassData *class = [GBClassData classDataWithName:@"Class"];
GBMethodData *method = [GBTestObjectsRegistry propertyMethodWithArgument:@"val"];
[method setComment:comment];
[class.methods registerMethod:method];
GBStore *result = [GBTestObjectsRegistry storeByPerformingSelector:@selector(registerClass:) withObject:class];
return result;
}
@end