Skip to content
Browse files

fill out Build unit tests

  • Loading branch information...
1 parent b789788 commit a722a7eb3078995f8c4b131660d582f94cd6cce0 @phinze committed Apr 22, 2012
Showing with 69 additions and 9 deletions.
  1. +1 −1 Woodhouse.xcodeproj/project.pbxproj
  2. +1 −0 Woodhouse/Build.h
  3. +13 −8 Woodhouse/Build.m
  4. +54 −0 WoodhouseTests/BuildTests.m
View
2 Woodhouse.xcodeproj/project.pbxproj
@@ -240,8 +240,8 @@
A777CF651492956F00FC97D3 /* Woodhouse-Info.plist */,
A777CF661492956F00FC97D3 /* InfoPlist.strings */,
A777CF691492956F00FC97D3 /* main.m */,
- A777CF6B1492956F00FC97D3 /* Woodhouse-Prefix.pch */,
A777CF6C1492956F00FC97D3 /* Credits.rtf */,
+ A777CF6B1492956F00FC97D3 /* Woodhouse-Prefix.pch */,
);
name = "Supporting Files";
sourceTree = "<group>";
View
1 Woodhouse/Build.h
@@ -10,6 +10,7 @@ extern NSString * const BuildStatusUnknown;
@property (nonatomic, copy, readonly) NSString *status;
@property (nonatomic, copy, readonly) NSURL *url;
+- (id)initWithName:(NSString *)aName status:(NSString *)aStatus url:(NSURL *)aUrl;
- (id)initFromNode:(NSXMLElement *)node;
- (BOOL)isSuccess;
View
21 Woodhouse/Build.m
@@ -8,15 +8,20 @@ @implementation Build
@synthesize name, status, url;
+- (id)initWithName:(NSString *)aName status:(NSString *)aStatus url:(NSURL *)aUrl {
+ self = [super init];
+ if (self) {
+ name = aName;
+ status = aStatus;
+ url = aUrl;
+ }
+ return self;
+}
+
- (id)initFromNode:(NSXMLElement *)node {
- self = [super init];
- if (self) {
- name = [[node attributeForName:@"name"] stringValue];
- status = [[node attributeForName:@"lastBuildStatus"] stringValue];
- url = [NSURL URLWithString: [[node attributeForName:@"webUrl"] stringValue]];
- }
-
- return self;
+ return [self initWithName:[[node attributeForName:@"name"] stringValue]
+ status:[[node attributeForName:@"lastBuildStatus"] stringValue]
+ url:[NSURL URLWithString: [[node attributeForName:@"webUrl"] stringValue]]];
}
- (BOOL)isFailure {
View
54 WoodhouseTests/BuildTests.m
@@ -6,10 +6,64 @@ @interface BuildTests : SenTestCase
@implementation BuildTests
+#pragma mark initFromNode
- (void)testInitializesAttributesFromNode {
+ NSString *projectXml = @"<Project name='build-name-in-xml'"
+ " webUrl='http://ci.example.com/job/build-name-in-xml'"
+ " lastBuildLabel='123'"
+ " lastBuildTime='2012-01-17T20:12:47Z'"
+ " lastBuildStatus='Failure'"
+ " activity='Sleeping'"
+ " />";
+ NSError *error;
+ NSXMLElement *node = [[NSXMLElement alloc] initWithXMLString:projectXml error:&error];
+ if (error) {
+ STFail(@"error parsing xml: %@", error);
+ }
+
+ Build *b = [[Build alloc] initFromNode:node];
+ STAssertEqualObjects(b.name, @"build-name-in-xml", nil);
+ STAssertEqualObjects(b.status, @"Failure", nil);
+ NSURL *expectedUrl = [NSURL URLWithString:@"http://ci.example.com/job/build-name-in-xml"];
+ STAssertEqualObjects(b.url, expectedUrl, nil);
+}
+
+#pragma mark isFailure
+
+- (void)testIsFailureWhenStatusMatches {
+ Build *build = [[Build alloc] initWithName:@"" status:@"Failure" url:[NSURL URLWithString:@""]];
+ STAssertTrue([build isFailure], nil);
+}
+
+#pragma mark isSuccess
+
+- (void)testIsSuccessWhenStatusMatches {
+ Build *build = [[Build alloc] initWithName:@"" status:@"Success" url:[NSURL URLWithString:@""]];
+ STAssertTrue([build isSuccess], nil);
+}
+
+#pragma mark isUnknown
+
+- (void)testIsUnknownWhenStatusMatches {
+ Build *build = [[Build alloc] initWithName:@"" status:@"Unknown" url:[NSURL URLWithString:@""]];
+ STAssertTrue([build isUnknown], nil);
+}
+
+#pragma mark isPresent
+
+- (void)testIsPresentAlwaysReturnsTrue {
+ Build *build = [[Build alloc] init];
+ STAssertTrue([build isPresent], nil);
+}
+
+#pragma mark isEqual
+-(void)testBuildsWithSameNameAreEqual {
+ Build *buildOne = [[Build alloc] initWithName:@"samename" status:@"one" url:[NSURL URLWithString:@"http://one"]];
+ Build *buildTwo = [[Build alloc] initWithName:@"samename" status:@"two" url:[NSURL URLWithString:@"http://two"]];
+ STAssertEqualObjects(buildOne, buildTwo, nil);
}
@end

0 comments on commit a722a7e

Please sign in to comment.
Something went wrong with that request. Please try again.