Skip to content

Commit

Permalink
Added missing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
artman committed Dec 23, 2015
1 parent 4a22dab commit 0393c6b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
Expand Up @@ -26,7 +26,8 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
shouldUseLaunchSchemeArgsEnv = "YES"
codeCoverageEnabled = "YES">
<Testables>
<TestableReference
skipped = "NO">
Expand Down
Expand Up @@ -40,7 +40,8 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
shouldUseLaunchSchemeArgsEnv = "YES"
codeCoverageEnabled = "YES">
<Testables>
<TestableReference
skipped = "NO">
Expand Down
15 changes: 6 additions & 9 deletions UberSignals/UBSignal.m
Expand Up @@ -122,12 +122,6 @@ - (instancetype)initWithProtocol:(Protocol *)protocol
return self;
}

- (instancetype)init
{
[NSException raise:@"Incorrect initializer" format:@"%@ is unavailable, use %@.", NSStringFromSelector(_cmd), NSStringFromSelector(@selector(initWithProtocol:))];
return nil;
}

#pragma mark - NSObject

- (NSString *)debugDescription
Expand All @@ -149,10 +143,13 @@ - (void)setMaxObservers:(NSUInteger)maxObservers

- (UBSignalObserver *)addObserver:(NSObject *)observer callback:(UBSignalCallback)callback
{
NSParameterAssert(observer != nil);
NSParameterAssert(callback != nil);
if (observer == nil) {
NSAssert(NO, @"Observer cannot be nil");
return nil;
}

if (observer == nil && callback == nil) {
if (callback == nil) {
NSAssert(NO, @"Callback cannot be nil");
return nil;
}

Expand Down
16 changes: 16 additions & 0 deletions UberSignalsTests/UBSignalTests.m
Expand Up @@ -723,4 +723,20 @@ - (void)testUBSignalHelper
XCTAssertEqualObjects([emptySignalWithHelper class], [UBSignal class], @"Object created with helper factory method should be a UBSignal");
}

- (void)testDebugDescription
{
UBSignal<EmptySignal> *signal = (UBSignal<EmptySignal> *)[[UBSignal alloc] initWithProtocol:@protocol(EmptySignal)];
[signal addObserver:self callback:^(id self) {}];
XCTAssert([[signal debugDescription] containsString:@"<UBSignal: "], @"Should contain string");
XCTAssert([[signal debugDescription] containsString:@"NSArray"], @"Should contain string");
XCTAssert([[signal debugDescription] containsString:@"<UBSignalObserver: "], @"Should contain string");
}

- (void)testAddingInvalidObservers
{
UBSignal<EmptySignal> *signal = (UBSignal<EmptySignal> *)[[UBSignal alloc] initWithProtocol:@protocol(EmptySignal)];
XCTAssertThrows([signal addObserver:nil callback:^(id self) {}], @"Should have asserted");
XCTAssertThrows([signal addObserver:self callback:nil], @"Should have asserted");
}

@end

0 comments on commit 0393c6b

Please sign in to comment.