Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 164 lines (141 sloc) 7.643 kb
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
//
// GBProcessor-MembersDocCopyingTesting.m
// appledoc
//
// Created by Tomaz Kragelj on 7.12.10.
// Copyright (C) 2010 Gentle Bytes. All rights reserved.
//

#import "GBApplicationSettingsProvider.h"
#import "GBDataObjects.h"
#import "GBProcessor.h"

@interface GBProcessorMembersDocumentationCopyingTesting : GHTestCase

- (GBProcessor *)processorWithFind:(BOOL)find;
- (GBProcessor *)processorWithFind:(BOOL)find keepObjects:(BOOL)objects keepMembers:(BOOL)members;
- (GBClassData *)classWithName:(NSString *)name superclass:(NSString *)superclass method:(id)method;
- (GBClassData *)classWithName:(NSString *)name adopting:(GBProtocolData *)protocol method:(id)method;
- (GBProtocolData *)protocolWithName:(NSString *)name method:(id)method;
- (GBMethodData *)instanceMethodWithName:(NSString *)name comment:(id)comment;

@end

#pragma mark -

@implementation GBProcessorMembersDocumentationCopyingTesting

#pragma mark Superclass copying testing

- (void)testProcessObjectsFromStore_shouldCopyDocumentationFromSuperclassIfFindIsYes {
// setup
GBMethodData *original = [self instanceMethodWithName:@"method" comment:@"comment"];
GBClassData *superclass = [self classWithName:@"Superclass" superclass:nil method:original];
GBMethodData *derived = [self instanceMethodWithName:@"method" comment:nil];
GBClassData *class = [self classWithName:@"Class" superclass:@"Superclass" method:derived];
GBStore *store = [GBTestObjectsRegistry storeWithObjects:class, superclass, nil];
GBProcessor *processor = [self processorWithFind:YES];
// execute
[processor processObjectsFromStore:store];
// verify
assertThat(derived.comment, isNot(nil));
assertThat(derived.comment, isNot(original.comment)); // We actually create a new comment object!
assertThat([derived.comment stringValue], is([original.comment stringValue]));
}

- (void)testProcessObjectsFromStore_shouldCopyDocumentationFromAnySuperclassIfFindIsYes {
// setup
GBMethodData *original = [self instanceMethodWithName:@"method" comment:@"comment"];
GBClassData *superclass = [self classWithName:@"Base" superclass:nil method:original];
GBClassData *middle = [self classWithName:@"Middle" superclass:@"Base" method:nil];
GBMethodData *derived = [self instanceMethodWithName:@"method" comment:nil];
GBClassData *class = [self classWithName:@"Class" superclass:@"Middle" method:derived];
GBStore *store = [GBTestObjectsRegistry storeWithObjects:class, middle, superclass, nil];
GBProcessor *processor = [self processorWithFind:YES];
// execute
[processor processObjectsFromStore:store];
// verify
assertThat([derived.comment stringValue], is([original.comment stringValue]));
}

- (void)testProcessObjectsFromStore_shouldNotCopyDocumentationFromSuperclassIfFindIsNo {
// setup
GBMethodData *original = [self instanceMethodWithName:@"method" comment:@"comment"];
GBClassData *superclass = [self classWithName:@"Superclass" superclass:nil method:original];
GBMethodData *derived = [self instanceMethodWithName:@"method" comment:nil];
GBClassData *class = [self classWithName:@"Class" superclass:@"Superclass" method:derived];
GBStore *store = [GBTestObjectsRegistry storeWithObjects:class, superclass, nil];
GBProcessor *processor = [self processorWithFind:NO];
// execute
[processor processObjectsFromStore:store];
// verify
assertThat(derived.comment, is(nil));
}

- (void)testProcessObjectsFromStore_shouldCopyDocumentationFromSuperclassEvenIfUndocumentedObjectsShouldBeDeleted {
// setup
GBMethodData *original = [self instanceMethodWithName:@"method" comment:@"comment"];
GBClassData *superclass = [self classWithName:@"Superclass" superclass:nil method:original];
GBMethodData *derived = [self instanceMethodWithName:@"method" comment:nil];
GBClassData *class = [self classWithName:@"Class" superclass:@"Superclass" method:derived];
GBStore *store = [GBTestObjectsRegistry storeWithObjects:class, superclass, nil];
GBProcessor *processor = [self processorWithFind:YES keepObjects:NO keepMembers:NO];
// execute
[processor processObjectsFromStore:store];
// verify
assertThat(derived.comment, isNot(nil));
}

#pragma mark Adopted protocols copying testing

- (void)testProcessObjectsFromStore_shouldCopyDocumentationFromAdoptedProtocolIfFindIsYes {
// setup
GBMethodData *original = [self instanceMethodWithName:@"method" comment:@"comment"];
GBProtocolData *protocol = [self protocolWithName:@"Protocol" method:original];
GBMethodData *derived = [self instanceMethodWithName:@"method" comment:nil];
GBClassData *class = [self classWithName:@"Class" adopting:protocol method:derived];
GBStore *store = [GBTestObjectsRegistry storeWithObjects:class, protocol, nil];
GBProcessor *processor = [self processorWithFind:YES];
// execute
[processor processObjectsFromStore:store];
// verify
assertThat(derived.comment, isNot(nil));
assertThat(derived.comment, isNot(original.comment)); // We actually create a new comment object!
assertThat([derived.comment stringValue], is([original.comment stringValue]));
}

- (void)testProcessObjectsFromStore_shouldCopyDocumentationFromAdoptedProtocolEvenIfUndocumentedObjectsShouldBeDeleted {
// setup
GBMethodData *original = [self instanceMethodWithName:@"method" comment:@"comment"];
GBProtocolData *protocol = [self protocolWithName:@"Protocol" method:original];
GBMethodData *derived = [self instanceMethodWithName:@"method" comment:nil];
GBClassData *class = [self classWithName:@"Class" adopting:protocol method:derived];
GBStore *store = [GBTestObjectsRegistry storeWithObjects:class, protocol, nil];
GBProcessor *processor = [self processorWithFind:YES keepObjects:NO keepMembers:NO];
// execute
[processor processObjectsFromStore:store];
// verify
assertThat(derived.comment, isNot(nil));
}

#pragma mark Creation methods

- (GBClassData *)classWithName:(NSString *)name superclass:(NSString *)superclass method:(id)method {
GBClassData *result = [GBClassData classDataWithName:name];
result.nameOfSuperclass = superclass;
if (method) [result.methods registerMethod:method];
return result;
}

- (GBClassData *)classWithName:(NSString *)name adopting:(GBProtocolData *)protocol method:(id)method {
GBClassData *result = [GBClassData classDataWithName:name];
if (protocol) [result.adoptedProtocols registerProtocol:protocol];
if (method) [result.methods registerMethod:method];
return result;
}

- (GBProtocolData *)protocolWithName:(NSString *)name method:(id)method {
GBProtocolData *result = [GBProtocolData protocolDataWithName:name];
if (method) [result.methods registerMethod:method];
return result;
}

- (GBMethodData *)instanceMethodWithName:(NSString *)name comment:(id)comment {
GBMethodData *method = [GBTestObjectsRegistry instanceMethodWithNames:name, nil];
if ([comment isKindOfClass:[NSString class]]) comment = [GBComment commentWithStringValue:comment];
method.comment = comment;
return method;
}

- (GBProcessor *)processorWithFind:(BOOL)find {
return [self processorWithFind:find keepObjects:YES keepMembers:YES];
}

- (GBProcessor *)processorWithFind:(BOOL)find keepObjects:(BOOL)objects keepMembers:(BOOL)members {
OCMockObject *settings = [GBTestObjectsRegistry mockSettingsProvider];
[[[settings stub] andReturnValue:[NSNumber numberWithBool:find]] findUndocumentedMembersDocumentation];
[[[settings stub] andReturnValue:[NSNumber numberWithBool:objects]] keepUndocumentedObjects];
[[[settings stub] andReturnValue:[NSNumber numberWithBool:members]] keepUndocumentedMembers];
[GBTestObjectsRegistry settingsProvider:settings keepObjects:YES keepMembers:YES];
return [GBProcessor processorWithSettingsProvider:settings];
}

@end
Something went wrong with that request. Please try again.