aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src
diff options
context:
space:
mode:
authorSamuel Tardieu <sam@rfc1149.net>2015-01-01 22:50:06 +0100
committerSamuel Tardieu <sam@rfc1149.net>2015-01-01 23:02:00 +0100
commit1c9482b79e414a1e4753ebb5fbb5560fe393ba33 (patch)
tree8ee35cef3e8d5468b82e5a2a6dfa8d33a36b56fa /tests/src
parentf309b4637be11ce7b740e7dc843936fb707ecfb1 (diff)
downloadcgeo-1c9482b79e414a1e4753ebb5fbb5560fe393ba33.zip
cgeo-1c9482b79e414a1e4753ebb5fbb5560fe393ba33.tar.gz
cgeo-1c9482b79e414a1e4753ebb5fbb5560fe393ba33.tar.bz2
New test for RxUtils
Diffstat (limited to 'tests/src')
-rw-r--r--tests/src/cgeo/geocaching/utils/RxUtilsTest.java45
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/src/cgeo/geocaching/utils/RxUtilsTest.java b/tests/src/cgeo/geocaching/utils/RxUtilsTest.java
new file mode 100644
index 0000000..5259998
--- /dev/null
+++ b/tests/src/cgeo/geocaching/utils/RxUtilsTest.java
@@ -0,0 +1,45 @@
+package cgeo.geocaching.utils;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import rx.Observable;
+import rx.Subscription;
+import rx.functions.Func1;
+import rx.subjects.PublishSubject;
+
+import android.test.AndroidTestCase;
+
+public class RxUtilsTest extends AndroidTestCase {
+
+ public static void testTakeUntil() {
+ final Observable<Integer> observable = Observable.range(1, 10).lift(RxUtils.operatorTakeUntil(new Func1<Integer, Boolean>() {
+ @Override
+ public Boolean call(final Integer value) {
+ return value > 6;
+ }
+ }));
+ assertThat(observable.toList().toBlocking().single().toArray()).isEqualTo(new int[]{1, 2, 3, 4, 5, 6, 7});
+ }
+
+ public static void testRememberLast() {
+ final PublishSubject<String> rawObservable = PublishSubject.create();
+ final Observable<String> observable = RxUtils.rememberLast(rawObservable, "initial");
+
+ // Check that the initial value is present, and is kept there
+ assertThat(observable.toBlocking().first()).isEqualTo("initial");
+ assertThat(observable.toBlocking().first()).isEqualTo("initial");
+
+ // Check that if the observable is not subscribed, changes are not propagated (similar to not keeping the
+ // inner subscription active).
+ rawObservable.onNext("without subscribers");
+ assertThat(observable.toBlocking().first()).isEqualTo("initial");
+
+ // Check that new values are propagated and cached
+ final Subscription subscription = observable.subscribe();
+ rawObservable.onNext("first");
+ assertThat(observable.toBlocking().first()).isEqualTo("first");
+ subscription.unsubscribe();
+ assertThat(observable.toBlocking().first()).isEqualTo("first");
+ }
+
+}