Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 0c68a2f624
Fetching contributors…

Cannot retrieve contributors at this time

file 91 lines (68 sloc) 4.397 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

#import "CCMBuildNotificationFactoryTest.h"
#import "CCMProject.h"

@implementation CCMBuildNotificationFactoryTest

- (void)setUp
{
factory = [[[CCMBuildNotificationFactory alloc] init] autorelease];
}

- (NSMutableDictionary *)createProjectInfoWithActivity:(NSString *)activity lastBuildStatus:(NSString *)status
{
NSMutableDictionary *info = [NSMutableDictionary dictionary];
[info setObject:@"connectfour" forKey:@"name"];
[info setObject:activity forKey:@"activity"];
[info setObject:status forKey:@"lastBuildStatus"];
[info setObject:[NSCalendarDate calendarDate] forKey:@"lastBuildDate"];
return info;
}

- (void)testCreatesSuccessfulBuildCompleteNotification
{
NSDictionary *pi1 = [self createProjectInfoWithActivity:CCMBuildingActivity lastBuildStatus:CCMSuccessStatus];
NSDictionary *pi2 = [self createProjectInfoWithActivity:CCMSleepingActivity lastBuildStatus:CCMSuccessStatus];

NSNotification *notification = [factory buildCompleteNotificationForOldProjectInfo:pi1 andNewProjectInfo:pi2];

STAssertNotNil(notification, @"Should have created a notification.");
STAssertEqualObjects(CCMBuildCompleteNotification, [notification name], @"Should have created correct notification.");
NSDictionary *userInfo = [notification userInfo];
STAssertEqualObjects(@"connectfour", [userInfo objectForKey:@"projectName"], @"Should have set project name.");
STAssertEqualObjects(CCMSuccessfulBuild, [userInfo objectForKey:@"buildResult"], @"Should have set correct build result.");
}

- (void)testCreatesBrokenBuildCompleteNotification
{
NSDictionary *pi1 = [self createProjectInfoWithActivity:CCMBuildingActivity lastBuildStatus:CCMSuccessStatus];
NSDictionary *pi2 = [self createProjectInfoWithActivity:CCMSleepingActivity lastBuildStatus:CCMFailedStatus];

NSNotification *notification = [factory buildCompleteNotificationForOldProjectInfo:pi1 andNewProjectInfo:pi2];

NSDictionary *userInfo = [notification userInfo];
STAssertEqualObjects(CCMBrokenBuild, [userInfo objectForKey:@"buildResult"], @"Should have set correct build result.");
}

- (void)testCreatesFixedBuildCompleteNotification
{
NSDictionary *pi1 = [self createProjectInfoWithActivity:CCMBuildingActivity lastBuildStatus:CCMFailedStatus];
NSDictionary *pi2 = [self createProjectInfoWithActivity:CCMSleepingActivity lastBuildStatus:CCMSuccessStatus];

NSNotification *notification = [factory buildCompleteNotificationForOldProjectInfo:pi1 andNewProjectInfo:pi2];

NSDictionary *userInfo = [notification userInfo];
STAssertEqualObjects(CCMFixedBuild, [userInfo objectForKey:@"buildResult"], @"Should have set correct build result.");
}

- (void)testCreatesStillFailingBuildCompleteNotification
{
NSDictionary *pi1 = [self createProjectInfoWithActivity:CCMBuildingActivity lastBuildStatus:CCMFailedStatus];
NSDictionary *pi2 = [self createProjectInfoWithActivity:CCMSleepingActivity lastBuildStatus:CCMFailedStatus];

NSNotification *notification = [factory buildCompleteNotificationForOldProjectInfo:pi1 andNewProjectInfo:pi2];

NSDictionary *userInfo = [notification userInfo];
STAssertEqualObjects(CCMStillFailingBuild, [userInfo objectForKey:@"buildResult"], @"Should have set correct build result.");
}

- (void)testCreatesBrokenBuildCompletionNotificationEvenIfBuildWasMissed
{
NSDictionary *pi1 = [self createProjectInfoWithActivity:CCMSleepingActivity lastBuildStatus:CCMSuccessStatus];
NSDictionary *pi2 = [self createProjectInfoWithActivity:CCMSleepingActivity lastBuildStatus:CCMFailedStatus];

NSNotification *notification = [factory buildCompleteNotificationForOldProjectInfo:pi1 andNewProjectInfo:pi2];

NSDictionary *userInfo = [notification userInfo];
STAssertEqualObjects(CCMBrokenBuild, [userInfo objectForKey:@"buildResult"], @"Should have set correct build result.");
}

- (void)testCreatesFixedBuildCompletionNotificationEvenIfBuildWasMissed
{
NSDictionary *pi1 = [self createProjectInfoWithActivity:CCMSleepingActivity lastBuildStatus:CCMFailedStatus];
NSDictionary *pi2 = [self createProjectInfoWithActivity:CCMSleepingActivity lastBuildStatus:CCMSuccessStatus];

NSNotification *notification = [factory buildCompleteNotificationForOldProjectInfo:pi1 andNewProjectInfo:pi2];

NSDictionary *userInfo = [notification userInfo];
STAssertEqualObjects(CCMFixedBuild, [userInfo objectForKey:@"buildResult"], @"Should have set correct build result.");
}

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