As of RxJava 1.3, fluent assertions will be part of the RxJava 1.x library. You should use the official equivalent instead. The official assertions are assertion library agnostic and use the same API as RxJava 2.x, which should help you make the transition should you chose to.
Only use this library if somehow you cannot to update to RxJava 1.3.
Every library has its lifespan and this one's has ended. Thank you for your interest!
A fluent assertion wrapper to simplify and improve usability of RxJava's TestSubscriber assertions, built upon the AssertJ framework.
TestSubscriber provides some very handy assertions to test your Observables, it can be a bit tedious and verbose to use. For example, to test the last value in a sequence you would typically write:
TestSubscriber<String> ts = ...... // subscribe to your Observable with TestSubscriber ts.assertNoErrors(); List<String> values = ts.getOnNextEvents(); assertThat(values.get(values.size() - 1)).isEqualTo("expectedValue");
This library makes this more readable by allowing you to express assertions in a fluent style:
TestSubscriber<String> ts = ...... // subscribe to your Observable with TestSubscriber assertThat(ts).hasNoErrors() .hasReceivedLastValue("expectedValue");
In addition to this wrapping, it provides some higher order assertions to allow for testing of specific conditions.
notEmptyOrNull is a reusable, AssertJ Condition.
Here are a few examples of the assertions performed using Assert-Rx.
Assert that the subscriber received any single onNext value:
Assert that the subscriber has received one or more onNext values:
Multiple, in-order values:
assertThat(ts).hasReceivedValues("a", "b", "c");
Assert conditions for single onNext events (currently only as
Assert conditions for the entire onNext value sequence:
Assert the first or last received onNext values:
assertThat(ts).hasReceivedFirstValue("the first value");
assertThat(ts).hasReceivedLastValue("the last value");
IOException instance in
Assert conditions for onError events (currently only as
assertThat(ts).hasErrorWhich() .hasMessageStartingWith("A terrible error");
Handle concurrency, by ensuring that the
TestSubscriber awaits a terminal event before asserting:
assertThat(ts).afterTerminalEvent() .hasNoErrors() .hasReceivedValue("someValue") .hasCompleted();
Releases are available as dependencies via Jitpack.
The library is built as an extension to the AssertJ framework, but to avoid duplication of the assertion logic in
TestSubscriber, in most cases it simply calls through to the
TestSubscriber assertion methods. The exceptions to this are the higher level assertions, which are provided by returning instances of AssertJ assertions.
Brought to you by the power of the Chilicorn and the Futurice Open Source Program.
Copyright 2016 Peter Tackage 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.