Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 113 lines (99 sloc) 4.915 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
//
// GBAdoptedProtocolsProviderTesting.m
// appledoc
//
// Created by Tomaz Kragelj on 26.7.10.
// Copyright (C) 2010 Gentle Bytes. All rights reserved.
//

#import "GBProtocolData.h"
#import "GBAdoptedProtocolsProvider.h"

@interface GBAdoptedProtocolsProviderTesting : GHTestCase
@end

@implementation GBAdoptedProtocolsProviderTesting

#pragma mark Protocol registration testing

- (void)testRegisterProtocol_shouldAddProtocolToList {
// setup
GBAdoptedProtocolsProvider *provider = [[GBAdoptedProtocolsProvider alloc] initWithParentObject:self];
GBProtocolData *protocol = [[GBProtocolData alloc] initWithName:@"MyProtocol"];
// execute
[provider registerProtocol:protocol];
// verify
assertThatBool([provider.protocols containsObject:protocol], equalToBool(YES));
assertThatInteger([[provider.protocols allObjects] count], equalToInteger(1));
assertThat([[provider.protocols allObjects] objectAtIndex:0], is(protocol));
}

- (void)testRegisterProtocol_shouldIgnoreSameInstance {
// setup
GBAdoptedProtocolsProvider *provider = [[GBAdoptedProtocolsProvider alloc] initWithParentObject:self];
GBProtocolData *protocol = [[GBProtocolData alloc] initWithName:@"MyProtocol"];
// execute
[provider registerProtocol:protocol];
[provider registerProtocol:protocol];
// verify
assertThatInteger([[provider.protocols allObjects] count], equalToInteger(1));
}

- (void)testRegisterProtocol_shouldMergeDifferentInstanceWithSameName {
// setup
GBAdoptedProtocolsProvider *provider = [[GBAdoptedProtocolsProvider alloc] initWithParentObject:self];
GBProtocolData *source = [[GBProtocolData alloc] initWithName:@"MyProtocol"];
OCMockObject *original = [OCMockObject niceMockForClass:[GBProtocolData class]];
[[[original stub] andReturn:@"MyProtocol"] nameOfProtocol];
[[original expect] mergeDataFromObject:source];
[provider registerProtocol:(GBProtocolData *)original];
// execute
[provider registerProtocol:source];
// verify
[original verify];
}

#pragma mark Protocol merging handling

- (void)testMergeDataFromProtocolProvider_shouldMergeAllDifferentProtocols {
// setup
GBAdoptedProtocolsProvider *original = [[GBAdoptedProtocolsProvider alloc] initWithParentObject:self];
[original registerProtocol:[GBProtocolData protocolDataWithName:@"P1"]];
[original registerProtocol:[GBProtocolData protocolDataWithName:@"P2"]];
GBAdoptedProtocolsProvider *source = [[GBAdoptedProtocolsProvider alloc] initWithParentObject:self];
[source registerProtocol:[GBProtocolData protocolDataWithName:@"P1"]];
[source registerProtocol:[GBProtocolData protocolDataWithName:@"P3"]];
// execute
[original mergeDataFromProtocolsProvider:source];
// verify - only basic verification here, details within GBProtocolDataTesting!
NSArray *protocols = [original protocolsSortedByName];
assertThatInteger([protocols count], equalToInteger(3));
assertThat([[protocols objectAtIndex:0] nameOfProtocol], is(@"P1"));
assertThat([[protocols objectAtIndex:1] nameOfProtocol], is(@"P2"));
assertThat([[protocols objectAtIndex:2] nameOfProtocol], is(@"P3"));
}

- (void)testMergeDataFromProtocolProvider_shouldPreserveSourceData {
// setup
GBAdoptedProtocolsProvider *original = [[GBAdoptedProtocolsProvider alloc] initWithParentObject:self];
[original registerProtocol:[GBProtocolData protocolDataWithName:@"P1"]];
[original registerProtocol:[GBProtocolData protocolDataWithName:@"P2"]];
GBAdoptedProtocolsProvider *source = [[GBAdoptedProtocolsProvider alloc] initWithParentObject:self];
[source registerProtocol:[GBProtocolData protocolDataWithName:@"P1"]];
[source registerProtocol:[GBProtocolData protocolDataWithName:@"P3"]];
// execute
[original mergeDataFromProtocolsProvider:source];
// verify - only basic verification here, details within GBProtocolDataTesting!
NSArray *protocols = [source protocolsSortedByName];
assertThatInteger([protocols count], equalToInteger(2));
assertThat([[protocols objectAtIndex:0] nameOfProtocol], is(@"P1"));
assertThat([[protocols objectAtIndex:1] nameOfProtocol], is(@"P3"));
}

#pragma mark Protocols replacing handling

- (void)testReplaceProtocolWithProtocol_shouldReplaceObjects {
// setup
GBAdoptedProtocolsProvider *provider = [[GBAdoptedProtocolsProvider alloc] initWithParentObject:self];
GBProtocolData *protocol1 = [GBProtocolData protocolDataWithName:@"P1"];
GBProtocolData *protocol2 = [GBProtocolData protocolDataWithName:@"P2"];
GBProtocolData *protocol3 = [GBProtocolData protocolDataWithName:@"P3"];
[provider registerProtocol:protocol1];
[provider registerProtocol:protocol2];
// execute
[provider replaceProtocol:protocol1 withProtocol:protocol3];
// verify
NSArray *protocols = [provider protocolsSortedByName];
assertThatInteger([protocols count], equalToInteger(2));
assertThat([[protocols objectAtIndex:0] nameOfProtocol], is(@"P2"));
assertThat([[protocols objectAtIndex:1] nameOfProtocol], is(@"P3"));
}

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