RxAssertions

Additional

Language
Java
Version
0.3.2 (Aug 26, 2016)
Created
May 11, 2016
Updated
Aug 2, 2018
Owner
Ubiratan Soares (ubiratansoares)
Contributors
Andrew Chen (yongjhih)
Niklas Baudy (vanniktech)
Ubiratan Soares (ubiratansoares)
3
Activity
Badge
Generate
Download
Source code

Promotion

[DEPRECATED] RxAssertions

This project is no longer maintened / active. Thanks for all OSS people that contributed and/or provided feedback !!!

RxAssertions is a simple idea for better RxJava assertions.

I found the original idea from the guys of Ribot : in fact, I think this a good idea and helps to keep tests clean.

However, Ribot guys deprecated their original repo some time ago in favor of vanilla TestSubscriber, so I decided to take my own shot on this.

This library mimics and improves the original Ribot`s idea with the following goodies :

  1. AssertJ powered assertions for RxJava (as the original one)
  2. All tests rely on BlockingObservable internally
  3. Internal API rely 100% on TestSubscriber
  4. Improved public API, covering most of TestSubscriber provided assertions
  5. Improved Assertions entry points from factory methods, with Observable, BlockingObservable, Single and Completable support

Lets see some code diet :

Regular assertions with TestSubscriber

TestSubscriber<String> testSubscriber = new TestSubscriber<>();
Observable.just("RxJava", "Assertions").toBlocking().subscribe(testSubscriber);
testSubscriber.assertCompleted();
testSubscriber.assertNoErrors();
testSubscriber.assertValues("RxJava", "Assertions");

Assertions with RxAssertions

RxAssertions.assertThat(Observable.just("RxJava", "Assertions"))
  .completes()
  .withoutErrors()
  .expectedValues("RxJava", "Assertions");

or

assertThat(Observable.empty())
  .emitsNothing()
  .completes()
  .withoutErrors();

or

Single<String> single = Single.fromCallable(() -> "RxJava");
assertThat(single).completes().expectedSingleValue("RxJava");

You can find other examples at test folder

Setup

Add it in your build.gradle

repositories {
 ...
 maven { url "https://jitpack.io" }

}

Add the dependency

dependencies {
 ...
 testCompile 'com.github.ubiratansoares:rxassertions:$version'
}

Check the releases tab for the latest version.

RxAssertions uses RxJava 1.1.9 and AssertJ 2.5.0 as dependencies.

Experimental

Since v0.3.0, we have some assertions leveraging on AssertJ Conditions API. This kind of assertion offers flexible matching both for emissions and error checks. You can find samples at test folder.

Contributing

PRs are wellcome. 🚀

Credits

  • Ribot guys for the original idea
  • RxJava and AssertJ guys for these awesome libraries

License

Copyright (C) 2016 Ubiratan Soares

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.