Skip to content

Commit

Permalink
Restructured unit tests for undocumented objects and members to get m…
Browse files Browse the repository at this point in the history
…ore specific testing in separate files.

All unit tests specific to undocumented objects and members were moved to a separate file to keep test cases more understandable and up to the point.
  • Loading branch information
tomaz committed Dec 5, 2010
1 parent f164e85 commit 0b332cf
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 101 deletions.
4 changes: 4 additions & 0 deletions Processing/GBProcessor.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,19 @@ @interface GBProcessor ()
- (void)processClasses;
- (void)processCategories;
- (void)processProtocols;

- (void)processSubclassForClass:(GBClassData *)class;
- (void)processDataProvider:(id<GBObjectDataProviding>)provider withComment:(GBComment *)comment;
- (void)processAdoptedProtocolsFromProvider:(GBAdoptedProtocolsProvider *)provider;
- (void)processMethodsFromProvider:(GBMethodsProvider *)provider;

- (void)processComment:(GBComment *)comment;
- (void)processParametersFromComment:(GBComment *)comment matchingMethod:(GBMethodData *)method;
- (void)processHtmlReferencesForObject:(GBModelBase *)object;

- (void)removeUndocumentedObjectsFromStore;
- (void)removeUndocumentedObjectsInSet:(NSSet *)objects;

- (void)validateCommentForObject:(GBModelBase *)object;
- (BOOL)isCommentValid:(GBComment *)comment;
@property (retain) GBCommentsProcessor *commentsProcessor;
Expand Down
101 changes: 0 additions & 101 deletions Testing/GBProcessor-CommentsTesting.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@
@interface GBProcessorCommentsTesting : GHTestCase

- (OCMockObject *)niceCommentMockExpectingRegisterParagraph;
- (OCMockObject *)settingsProviderKeepObjects:(BOOL)objects keepMembers:(BOOL)members;
- (GBClassData *)classWithComment:(BOOL)comment;
- (NSArray *)registerMethodsOfCount:(NSUInteger)count withComment:(BOOL)comment toObject:(id<GBObjectDataProviding>)provider;
- (NSString *)randomName;

@end

Expand Down Expand Up @@ -134,75 +130,6 @@ - (void)testProcesObjectsFromStore_shouldMatchParameterDirectivesWithActualOrder
assertThat([[[comment.parameters objectAtIndex:2] argumentDescription] stringValue], is(@"Description3"));
}

#pragma mark Undocumented objects handling

- (void)testProcessObjectsFromStore_shouldKeepUncommentedObjectIfKeepObjectsIsYes {
// setup
GBProcessor *processor = [GBProcessor processorWithSettingsProvider:[self settingsProviderKeepObjects:YES keepMembers:NO]];
GBClassData *class = [self classWithComment:NO];
GBStore *store = [GBTestObjectsRegistry storeByPerformingSelector:@selector(registerClass:) withObject:class];
// execute
[processor processObjectsFromStore:store];
// verify
assertThatInteger([store.classes count], equalToInteger(1));
assertThatBool([store.classes containsObject:class], equalToBool(YES));
}

- (void)testProcessObjectsFromStore_shouldKeepUncommentedObjectIfItHasCommentedMembers {
// setup
GBProcessor *processor = [GBProcessor processorWithSettingsProvider:[self settingsProviderKeepObjects:NO keepMembers:NO]];
GBClassData *class = [self classWithComment:NO];
GBStore *store = [GBTestObjectsRegistry storeByPerformingSelector:@selector(registerClass:) withObject:class];
[self registerMethodsOfCount:1 withComment:YES toObject:class];
[self registerMethodsOfCount:1 withComment:NO toObject:class];
// execute
[processor processObjectsFromStore:store];
// verify
assertThatInteger([store.classes count], equalToInteger(1));
assertThatBool([store.classes containsObject:class], equalToBool(YES));
}

- (void)testProcessObjectsFromStore_shouldDeleteUncommentedObjectIfKeepObjectsIsNo {
// setup
GBProcessor *processor = [GBProcessor processorWithSettingsProvider:[self settingsProviderKeepObjects:NO keepMembers:NO]];
GBClassData *class = [self classWithComment:NO];
GBStore *store = [GBTestObjectsRegistry storeByPerformingSelector:@selector(registerClass:) withObject:class];
// execute
[processor processObjectsFromStore:store];
// verify
assertThatInteger([store.classes count], equalToInteger(0));
}

- (void)testProcessObjectsFromStore_shouldKeepUncommentedMethodsIfKeepMembersIsYes {
// setup
GBProcessor *processor = [GBProcessor processorWithSettingsProvider:[self settingsProviderKeepObjects:YES keepMembers:YES]];
GBClassData *class = [self classWithComment:YES];
NSArray *uncommented = [self registerMethodsOfCount:1 withComment:NO toObject:class];
GBStore *store = [GBTestObjectsRegistry storeByPerformingSelector:@selector(registerClass:) withObject:class];
// execute
[processor processObjectsFromStore:store];
// verify
NSArray *methods = [class.methods methods];
assertThatInteger([methods count], equalToInteger(1));
assertThatBool([methods containsObject:[uncommented objectAtIndex:0]], equalToBool(YES));
}

- (void)testProcessObjectsFromStore_shouldDeleteUncommentedMethodsIfKeepMembersIsNo {
// setup
GBProcessor *processor = [GBProcessor processorWithSettingsProvider:[self settingsProviderKeepObjects:YES keepMembers:NO]];
GBClassData *class = [self classWithComment:YES];
NSArray *commented = [self registerMethodsOfCount:1 withComment:YES toObject:class];
NSArray *uncommented = [self registerMethodsOfCount:1 withComment:NO toObject:class];
GBStore *store = [GBTestObjectsRegistry storeByPerformingSelector:@selector(registerClass:) withObject:class];
// execute
[processor processObjectsFromStore:store];
// verify
NSArray *methods = [class.methods methods];
assertThatInteger([methods count], equalToInteger(1));
assertThatBool([methods containsObject:[commented objectAtIndex:0]], equalToBool(YES));
assertThatBool([methods containsObject:[uncommented objectAtIndex:0]], equalToBool(NO));
}

#pragma mark Creation methods

- (OCMockObject *)niceCommentMockExpectingRegisterParagraph {
Expand All @@ -212,32 +139,4 @@ - (OCMockObject *)niceCommentMockExpectingRegisterParagraph {
return result;
}

- (OCMockObject *)settingsProviderKeepObjects:(BOOL)objects keepMembers:(BOOL)members {
OCMockObject *result = [GBTestObjectsRegistry mockSettingsProvider];
[GBTestObjectsRegistry settingsProvider:result keepObjects:objects keepMembers:members];
return result;
}

- (GBClassData *)classWithComment:(BOOL)comment {
GBClassData *result = [GBClassData classDataWithName:[self randomName]];
if (comment) result.comment = [GBComment commentWithStringValue:@"comment"];
return result;
}

- (NSArray *)registerMethodsOfCount:(NSUInteger)count withComment:(BOOL)comment toObject:(id<GBObjectDataProviding>)provider {
NSMutableArray *result = [NSMutableArray arrayWithCapacity:count];
for (NSUInteger i=0; i<count; i++) {
GBMethodData *method = [GBTestObjectsRegistry instanceMethodWithNames:[self randomName], nil];
if (comment) method.comment = [GBComment commentWithStringValue:@"comment"];
if (provider) [provider.methods registerMethod:method];
[result addObject:method];
}
return result;
}

- (NSString *)randomName {
NSUInteger value = random();
return [NSString stringWithFormat:@"N%ld", value];
}

@end
127 changes: 127 additions & 0 deletions Testing/GBProcessor-UndocumentedObjectsTesting.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
//
// GBProcessor-UndocumentedObjectsTesting.m
// appledoc
//
// Created by Tomaz Kragelj on 5.12.10.
// Copyright (C) 2010 Gentle Bytes. All rights reserved.
//

#import "GBDataObjects.h"
#import "GBStore.h"
#import "GBProcessor.h"

@interface GBProcessorUndocumentedObjectsTesting : GHTestCase

- (OCMockObject *)settingsProviderKeepObjects:(BOOL)objects keepMembers:(BOOL)members;
- (GBClassData *)classWithComment:(BOOL)comment;
- (NSArray *)registerMethodsOfCount:(NSUInteger)count withComment:(BOOL)comment toObject:(id<GBObjectDataProviding>)provider;
- (NSString *)randomName;

@end

#pragma mark -

@implementation GBProcessorUndocumentedObjectsTesting

#pragma mark Undocumented objects handling

- (void)testProcessObjectsFromStore_shouldKeepUncommentedObjectIfKeepObjectsIsYes {
// setup
GBProcessor *processor = [GBProcessor processorWithSettingsProvider:[self settingsProviderKeepObjects:YES keepMembers:NO]];
GBClassData *class = [self classWithComment:NO];
GBStore *store = [GBTestObjectsRegistry storeByPerformingSelector:@selector(registerClass:) withObject:class];
// execute
[processor processObjectsFromStore:store];
// verify
assertThatInteger([store.classes count], equalToInteger(1));
assertThatBool([store.classes containsObject:class], equalToBool(YES));
}

- (void)testProcessObjectsFromStore_shouldKeepUncommentedObjectIfItHasCommentedMembers {
// setup
GBProcessor *processor = [GBProcessor processorWithSettingsProvider:[self settingsProviderKeepObjects:NO keepMembers:NO]];
GBClassData *class = [self classWithComment:NO];
GBStore *store = [GBTestObjectsRegistry storeByPerformingSelector:@selector(registerClass:) withObject:class];
[self registerMethodsOfCount:1 withComment:YES toObject:class];
[self registerMethodsOfCount:1 withComment:NO toObject:class];
// execute
[processor processObjectsFromStore:store];
// verify
assertThatInteger([store.classes count], equalToInteger(1));
assertThatBool([store.classes containsObject:class], equalToBool(YES));
}

- (void)testProcessObjectsFromStore_shouldDeleteUncommentedObjectIfKeepObjectsIsNo {
// setup
GBProcessor *processor = [GBProcessor processorWithSettingsProvider:[self settingsProviderKeepObjects:NO keepMembers:NO]];
GBClassData *class = [self classWithComment:NO];
GBStore *store = [GBTestObjectsRegistry storeByPerformingSelector:@selector(registerClass:) withObject:class];
// execute
[processor processObjectsFromStore:store];
// verify
assertThatInteger([store.classes count], equalToInteger(0));
}

#pragma mark Undocumented methods handling

- (void)testProcessObjectsFromStore_shouldKeepUncommentedMethodsIfKeepMembersIsYes {
// setup
GBProcessor *processor = [GBProcessor processorWithSettingsProvider:[self settingsProviderKeepObjects:YES keepMembers:YES]];
GBClassData *class = [self classWithComment:YES];
NSArray *uncommented = [self registerMethodsOfCount:1 withComment:NO toObject:class];
GBStore *store = [GBTestObjectsRegistry storeByPerformingSelector:@selector(registerClass:) withObject:class];
// execute
[processor processObjectsFromStore:store];
// verify
NSArray *methods = [class.methods methods];
assertThatInteger([methods count], equalToInteger(1));
assertThatBool([methods containsObject:[uncommented objectAtIndex:0]], equalToBool(YES));
}

- (void)testProcessObjectsFromStore_shouldDeleteUncommentedMethodsIfKeepMembersIsNo {
// setup
GBProcessor *processor = [GBProcessor processorWithSettingsProvider:[self settingsProviderKeepObjects:YES keepMembers:NO]];
GBClassData *class = [self classWithComment:YES];
NSArray *commented = [self registerMethodsOfCount:1 withComment:YES toObject:class];
NSArray *uncommented = [self registerMethodsOfCount:1 withComment:NO toObject:class];
GBStore *store = [GBTestObjectsRegistry storeByPerformingSelector:@selector(registerClass:) withObject:class];
// execute
[processor processObjectsFromStore:store];
// verify
NSArray *methods = [class.methods methods];
assertThatInteger([methods count], equalToInteger(1));
assertThatBool([methods containsObject:[commented objectAtIndex:0]], equalToBool(YES));
assertThatBool([methods containsObject:[uncommented objectAtIndex:0]], equalToBool(NO));
}

#pragma mark Creation methods

- (OCMockObject *)settingsProviderKeepObjects:(BOOL)objects keepMembers:(BOOL)members {
OCMockObject *result = [GBTestObjectsRegistry mockSettingsProvider];
[GBTestObjectsRegistry settingsProvider:result keepObjects:objects keepMembers:members];
return result;
}

- (GBClassData *)classWithComment:(BOOL)comment {
GBClassData *result = [GBClassData classDataWithName:[self randomName]];
if (comment) result.comment = [GBComment commentWithStringValue:@"comment"];
return result;
}

- (NSArray *)registerMethodsOfCount:(NSUInteger)count withComment:(BOOL)comment toObject:(id<GBObjectDataProviding>)provider {
NSMutableArray *result = [NSMutableArray arrayWithCapacity:count];
for (NSUInteger i=0; i<count; i++) {
GBMethodData *method = [GBTestObjectsRegistry instanceMethodWithNames:[self randomName], nil];
if (comment) method.comment = [GBComment commentWithStringValue:@"comment"];
if (provider) [provider.methods registerMethod:method];
[result addObject:method];
}
return result;
}

- (NSString *)randomName {
NSUInteger value = random();
return [NSString stringWithFormat:@"N%ld", value];
}

@end
4 changes: 4 additions & 0 deletions appledoc.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
739AD62F1255D8CB00B642C3 /* GBHTMLTemplateVariablesProvider.m in Sources */ = {isa = PBXBuildFile; fileRef = 739AD62E1255D8CB00B642C3 /* GBHTMLTemplateVariablesProvider.m */; };
739AD6301255D8CB00B642C3 /* GBHTMLTemplateVariablesProvider.m in Sources */ = {isa = PBXBuildFile; fileRef = 739AD62E1255D8CB00B642C3 /* GBHTMLTemplateVariablesProvider.m */; };
739AD6521255E32A00B642C3 /* GBTemplateVariablesProvider-CommonTesting.m in Sources */ = {isa = PBXBuildFile; fileRef = 739AD6511255E32A00B642C3 /* GBTemplateVariablesProvider-CommonTesting.m */; };
739C0C4712AC258B00F0130B /* GBProcessor-UndocumentedObjectsTesting.m in Sources */ = {isa = PBXBuildFile; fileRef = 739C0C4612AC258B00F0130B /* GBProcessor-UndocumentedObjectsTesting.m */; };
73A32FB01236491400040070 /* GBCommentsProcessor-LinkItemsTesting.m in Sources */ = {isa = PBXBuildFile; fileRef = 73A32FAF1236491400040070 /* GBCommentsProcessor-LinkItemsTesting.m */; };
73A330001236532500040070 /* GBParagraphLinkItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 73A32FFF1236532500040070 /* GBParagraphLinkItem.m */; };
73A330011236532500040070 /* GBParagraphLinkItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 73A32FFF1236532500040070 /* GBParagraphLinkItem.m */; };
Expand Down Expand Up @@ -323,6 +324,7 @@
739AD62D1255D8CB00B642C3 /* GBHTMLTemplateVariablesProvider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GBHTMLTemplateVariablesProvider.h; sourceTree = "<group>"; };
739AD62E1255D8CB00B642C3 /* GBHTMLTemplateVariablesProvider.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GBHTMLTemplateVariablesProvider.m; sourceTree = "<group>"; };
739AD6511255E32A00B642C3 /* GBTemplateVariablesProvider-CommonTesting.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GBTemplateVariablesProvider-CommonTesting.m"; sourceTree = "<group>"; };
739C0C4612AC258B00F0130B /* GBProcessor-UndocumentedObjectsTesting.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GBProcessor-UndocumentedObjectsTesting.m"; sourceTree = "<group>"; };
73A32FAF1236491400040070 /* GBCommentsProcessor-LinkItemsTesting.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GBCommentsProcessor-LinkItemsTesting.m"; sourceTree = "<group>"; };
73A32FB112364BC100040070 /* GBObjectDataProviding.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GBObjectDataProviding.h; sourceTree = "<group>"; };
73A32FFE1236532500040070 /* GBParagraphLinkItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GBParagraphLinkItem.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -886,6 +888,7 @@
children = (
73EC00BF1227EB0E0076B7B3 /* GBProcessor-KnownObjectsTesting.m */,
73EC00F71227F58F0076B7B3 /* GBProcessor-CommentsTesting.m */,
739C0C4612AC258B00F0130B /* GBProcessor-UndocumentedObjectsTesting.m */,
73EC015B122852ED0076B7B3 /* GBCommentsProcessor-TextItemsTesting.m */,
73329895122E4DFC00AEBA2B /* GBCommentsProcessor-UnorderedListsTesting.m */,
73329AA5122E8AA800AEBA2B /* GBCommentsProcessor-OrderedListsTesting.m */,
Expand Down Expand Up @@ -1210,6 +1213,7 @@
73F568C212A22A7900A72BB2 /* DDFileLogger.m in Sources */,
73F568C412A22A7900A72BB2 /* DDLog.m in Sources */,
73F568C612A22A7900A72BB2 /* DDTTYLogger.m in Sources */,
739C0C4712AC258B00F0130B /* GBProcessor-UndocumentedObjectsTesting.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down

0 comments on commit 0b332cf

Please sign in to comment.