aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Jorge Canizales <jcanizales@google.com>2016-03-11 12:26:27 -0800
committerGravatar Jorge Canizales <jcanizales@google.com>2016-03-11 12:26:42 -0800
commit232b6a8f191d9cbb905680dd2a95f3b1815d1eb7 (patch)
tree709e7e4a5762cf2e4eb5cced0ac33a14595d8af1 /src
parent180ca8635057f2dddeef88d6f4ce5d8f13074b4a (diff)
Test robustness of WriteableSingleHandler against non-single Writers
Diffstat (limited to 'src')
-rw-r--r--src/objective-c/tests/RxLibraryUnitTests.m51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/objective-c/tests/RxLibraryUnitTests.m b/src/objective-c/tests/RxLibraryUnitTests.m
index d342662814..ae9465f58c 100644
--- a/src/objective-c/tests/RxLibraryUnitTests.m
+++ b/src/objective-c/tests/RxLibraryUnitTests.m
@@ -64,6 +64,8 @@
}
@end
+// TODO(jcanizales): Split into one file per tested class.
+
@interface RxLibraryUnitTests : XCTestCase
@end
@@ -79,6 +81,7 @@
// If:
id<GRXWriteable> writeable = [GRXWriteable writeableWithSingleHandler:handler.block];
[writeable writeValue:anyValue];
+ [writeable writesFinishedWithError:nil];
// Then:
XCTAssertEqual(handler.timesCalled, 1);
@@ -101,6 +104,54 @@
XCTAssertEqualObjects(handler.errorOrNil, anyError);
}
+- (void)testWriteableSingleHandlerIsCalledOnlyOnce_ValueThenError {
+ // Given:
+ CapturingSingleValueHandler *handler = [CapturingSingleValueHandler handler];
+ id anyValue = @7;
+ NSError *anyError = [NSError errorWithDomain:@"domain" code:7 userInfo:nil];
+
+ // If:
+ id<GRXWriteable> writeable = [GRXWriteable writeableWithSingleHandler:handler.block];
+ [writeable writeValue:anyValue];
+ [writeable writesFinishedWithError:anyError];
+
+ // Then:
+ XCTAssertEqual(handler.timesCalled, 1);
+ XCTAssertEqualObjects(handler.value, anyValue);
+ XCTAssertEqualObjects(handler.errorOrNil, nil);
+}
+
+- (void)testWriteableSingleHandlerIsCalledOnlyOnce_ValueThenValue {
+ // Given:
+ CapturingSingleValueHandler *handler = [CapturingSingleValueHandler handler];
+ id anyValue = @7;
+
+ // If:
+ id<GRXWriteable> writeable = [GRXWriteable writeableWithSingleHandler:handler.block];
+ [writeable writeValue:anyValue];
+ [writeable writeValue:anyValue];
+ [writeable writesFinishedWithError:nil];
+
+ // Then:
+ XCTAssertEqual(handler.timesCalled, 1);
+ XCTAssertEqualObjects(handler.value, anyValue);
+ XCTAssertEqualObjects(handler.errorOrNil, nil);
+}
+
+- (void)testWriteableSingleHandlerFailsOnEmptyWriter {
+ // Given:
+ CapturingSingleValueHandler *handler = [CapturingSingleValueHandler handler];
+
+ // If:
+ id<GRXWriteable> writeable = [GRXWriteable writeableWithSingleHandler:handler.block];
+ [writeable writesFinishedWithError:nil];
+
+ // Then:
+ XCTAssertEqual(handler.timesCalled, 1);
+ XCTAssertEqualObjects(handler.value, nil);
+ XCTAssertNotNil(handler.errorOrNil);
+}
+
#pragma mark BufferedPipe
- (void)testBufferedPipePropagatesValue {