assert-rx


Source link: https://github.com/peter-tackage/assert-rx

Assert-Rx

DEPRECATED!

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.

Purpose

Although 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.

 assertThat(ts).hasReceivedFirstValueWhich()

 .is(notEmptyOrNull());

Where notEmptyOrNull is a reusable, AssertJ Condition.

Usage

Here are a few examples of the assertions performed using Assert-Rx.

OnNext Assertions

Assert that the subscriber received any single onNext value:

 assertThat(ts).hasReceivedAnyValue();

Assert that the subscriber has received one or more onNext values:

 assertThat(ts).hasReceivedAnyValues();

Multiple, in-order values:

 assertThat(ts).hasReceivedValues("a", "b", "c");

Assert conditions for single onNext events (currently only as Object instances):

 assertThat(ts).hasReceivedValueWhich()

 .is(notEmptyOrNull());

Assert conditions for the entire onNext value sequence:

 assertThat(ts).hasReceivedValuesWhich()

 .doesNotContain(someObject);

Assert the first or last received onNext values:

 assertThat(ts).hasReceivedFirstValue("the first value");
 assertThat(ts).hasReceivedLastValue("the last value");
 assertThat(ts).hasReceivedFirstValueWhich()

 .is(notEmptyOrNull());
 assertThat(ts).hasReceivedLastValueWhich()

 .is(notEmptyOrNull());

OnError Assertions

Received an IOException instance in onError:

 assertThat(ts).hasError(IOException.class);

Assert conditions for onError events (currently only as Throwable instances):

 assertThat(ts).hasErrorWhich()

 .hasMessageStartingWith("A terrible error");

Concurrency Handling

Handle concurrency, by ensuring that the TestSubscriber awaits a terminal event before asserting:

 assertThat(ts).afterTerminalEvent()

 .hasNoErrors()

 .hasReceivedValue("someValue")

 .hasCompleted();

Download

Releases are available as dependencies via Jitpack.

Implementation

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.

Acknowledgements

Brought to you by the power of the Chilicorn and the Futurice Open Source Program.

License

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. 

Resources

This library provides a simple service that allows to display arbitrary text as a system-window overlay.

This library allows to format bank card number automatically, adding a space after every four symbols.

This example project shows how to make imitation of the "double drag" layout.

A easy way to setEmptyView to ListView, GridView or RecyclerView.

A view with ripple effect.

Android components is an android library which contains improvements of native android components.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes