├── .gitignore
├── .travis.yml
├── CODE_OF_CONDUCT.md
├── LICENSE
├── README.md
├── _config.yml
├── art
├── kotlin_logo.png
├── plus_icon.png
└── rx_logo.png
├── build.gradle
├── descriptor.json
├── detekt.yml
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── settings.gradle
└── src
├── main
└── kotlin
│ └── com
│ └── rubylichtenstein
│ └── rxtest
│ ├── assertions
│ └── Assertions.kt
│ ├── extentions
│ └── Extantions.kt
│ └── matchers
│ ├── CreateMatcher.kt
│ ├── Matcher.kt
│ └── Matchers.kt
└── test
└── kotlin
└── com
└── rubylichtenstein
└── rxtest
└── matchers
├── CreateMatcherTest.kt
└── MatchersTest.kt
/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | .idea
3 |
4 | /out
5 | /build
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: java
2 | jdk:
3 | - oraclejdk8
4 |
5 | before_install:
6 | - chmod +x gradlew
7 |
8 | before_deploy:
9 | - ./gradlew generatePomFileForMavenPublication
10 |
11 | before_script:
12 | - chmod +x gradlew
13 |
14 | script:
15 | - ./gradlew check
16 | - ./gradlew jacocoTestReport
17 |
18 | deploy:
19 | provider: bintray
20 | file: "descriptor.json"
21 | user: $BINTRAY_API_USER
22 | key: $BINTRAY_API_KEY
23 | dry-run: false
24 |
25 | after_success:
26 | - bash <(curl -s https://codecov.io/bash)
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Contributor Covenant Code of Conduct
2 |
3 | ## Our Pledge
4 |
5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
6 |
7 | ## Our Standards
8 |
9 | Examples of behavior that contributes to creating a positive environment include:
10 |
11 | * Using welcoming and inclusive language
12 | * Being respectful of differing viewpoints and experiences
13 | * Gracefully accepting constructive criticism
14 | * Focusing on what is best for the community
15 | * Showing empathy towards other community members
16 |
17 | Examples of unacceptable behavior by participants include:
18 |
19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances
20 | * Trolling, insulting/derogatory comments, and personal or political attacks
21 | * Public or private harassment
22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission
23 | * Other conduct which could reasonably be considered inappropriate in a professional setting
24 |
25 | ## Our Responsibilities
26 |
27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
28 |
29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
30 |
31 | ## Scope
32 |
33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
34 |
35 | ## Enforcement
36 |
37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at ruby.lich@gmail.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
38 |
39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
40 |
41 | ## Attribution
42 |
43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
44 |
45 | [homepage]: http://contributor-covenant.org
46 | [version]: http://contributor-covenant.org/version/1/4/
47 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | kotlin|Rx
2 | |:---:|:---:|
3 |
|
4 |
5 | # RxTest - Kotlin DSL for easier RxJava testing.
6 |
7 | [](https://travis-ci.org/RubyLichtenstein/RxTest) [](https://codecov.io/gh/RubyLichtenstein/RxTest) [](https://www.codacy.com/app/reuven.lichtenstein/RxTest?utm_source=github.com&utm_medium=referral&utm_content=RubyLichtenstein/RxTest&utm_campaign=Badge_Grade) [](https://bintray.com/rubylichtenstein/RxTest/com.rubylichtenstein.rxtest/_latestVersion) [](http://kotlinlang.org/) [](http://www.apache.org/licenses/LICENSE-2.0) [](https://gitter.im/RxTest/) [](https://android-arsenal.com/details/1/6647)
8 |
9 | #### Main features
10 | * **Clear tests:** write clean, readable and simple tests in scala-test '*should* style'.
11 | * **Easy to extend:** create custom matchers for complex test cases or just for more readable code.
12 | * **Simple to use:** same API as RxJava assertions you already know.
13 |
14 | ## Example
15 | ```kotlin
16 | Observable.just("Hello RxTest!")
17 | .test {
18 | it shouldEmit "Hello RxTest!"
19 | it should complete()
20 | it shouldHave noErrors()
21 | }
22 | ```
23 | ## Documentation
24 |
25 | * [Home](https://github.com/RubyLichtenstein/RxTest/wiki)
26 | * [Introduction](https://github.com/RubyLichtenstein/RxTest/wiki/Introduction)
27 | * [Examples](https://github.com/RubyLichtenstein/RxTest/wiki/Examples)
28 | * Components
29 | * [Matchers](https://github.com/RubyLichtenstein/RxTest/wiki/Matchers)
30 | * [Assertions](https://github.com/RubyLichtenstein/RxTest/wiki/Assertions)
31 | * [Extensions](https://github.com/RubyLichtenstein/RxTest/wiki/Extensions)
32 |
33 | * [Custom matchers](https://github.com/RubyLichtenstein/RxTest/wiki/Custom-matchers)
34 | * [Create matcher from scratch](https://github.com/RubyLichtenstein/RxTest/wiki/Custom-matchers#1-create-matchers-from-scratch)
35 | * [Wrap existing matcher](https://github.com/RubyLichtenstein/RxTest/wiki/Custom-matchers#2-wrap-existing-matcher)
36 | * [Combine matchers with And/Or](https://github.com/RubyLichtenstein/RxTest/wiki/Custom-matchers#3-combine-matchers-with-andor)
37 |
38 | ## Download
39 | - #### Gradle
40 | ```groovy
41 | dependencies {
42 | testImplementation 'com.rubylichtenstein:rxtest:1.0.7'
43 | }
44 | ```
45 |
46 | - #### Maven
47 | ```xml
48 |
49 | com.rubylichtenstein
50 | rxtest
51 | 1.0.7
52 | pom
53 |
54 | ```
55 | ## Mentions
56 |
57 | [](http://androidweekly.net/issues/issue-298)
58 | [](https://androidweekly.cn/android-dev-weekly-issue-161/)
59 |
60 | ## Bugs and Feedback
61 |
62 | For bugs, questions and discussions please use the [Github Issues](https://github.com/RubyLichtenstein/RxTest/issues).
63 |
64 | ## Contribution
65 |
66 | Welcome :)
67 |
68 |
69 |
70 |
--------------------------------------------------------------------------------
/_config.yml:
--------------------------------------------------------------------------------
1 | theme: jekyll-theme-cayman
--------------------------------------------------------------------------------
/art/kotlin_logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RubyLichtenstein/RxTest/7ab1391421c1b9880182e5a83a98ad15cb38e1c5/art/kotlin_logo.png
--------------------------------------------------------------------------------
/art/plus_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RubyLichtenstein/RxTest/7ab1391421c1b9880182e5a83a98ad15cb38e1c5/art/plus_icon.png
--------------------------------------------------------------------------------
/art/rx_logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RubyLichtenstein/RxTest/7ab1391421c1b9880182e5a83a98ad15cb38e1c5/art/rx_logo.png
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | group 'com.rubylichtenstein'
2 | version '1.0.7'
3 |
4 | buildscript {
5 | ext.kotlin_version = '1.2.21'
6 | ext.detekt_version = '1.0.0.RC6'
7 |
8 | repositories {
9 | jcenter()
10 | maven { url "https://plugins.gradle.org/m2/" }
11 | maven { url "http://dl.bintray.com/jetbrains/spek" }
12 | }
13 | dependencies {
14 | classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:$detekt_version"
15 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
16 | classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.0'
17 | }
18 | }
19 |
20 | apply plugin: 'org.junit.platform.gradle.plugin'
21 | apply plugin: 'kotlin'
22 | apply plugin: 'maven-publish'
23 | apply plugin: "jacoco"
24 | apply plugin: "io.gitlab.arturbosch.detekt"
25 |
26 | repositories {
27 | jcenter()
28 | }
29 |
30 | junitPlatform {
31 | filters {
32 | engines {
33 | include 'spek'
34 | }
35 | }
36 | details 'tree'
37 |
38 | }
39 |
40 | jacocoTestReport {
41 | reports {
42 | xml.enabled true
43 | html.enabled true
44 | }
45 | }
46 |
47 | dependencies {
48 | compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
49 | compile 'io.reactivex.rxjava2:rxjava:2.1.7'
50 |
51 | testCompile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
52 | testCompile "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
53 |
54 | testCompile('org.jetbrains.spek:spek-api:1.1.5') {
55 | exclude group: 'org.jetbrains.kotlin'
56 | }
57 |
58 | testRuntime('org.jetbrains.spek:spek-junit-platform-engine:1.1.5') {
59 | exclude group: 'org.junit.platform'
60 | exclude group: 'org.jetbrains.kotlin'
61 | }
62 |
63 | testRuntime('org.junit.platform:junit-platform-runner:1.0.0')
64 | testCompile 'org.junit.platform:junit-platform-console:1.0.0'
65 |
66 | testCompile("org.junit.jupiter:junit-jupiter-api:5.0.2")
67 | testRuntime("org.junit.jupiter:junit-jupiter-engine:5.0.2")
68 |
69 | }
70 |
71 | task wrapper(type: Wrapper) {
72 | gradleVersion = '4.4.1'
73 | }
74 |
75 | detekt {
76 | version = "$detekt_version"
77 | profile("main") {
78 | input = "$projectDir/src/main/kotlin"
79 | output = "$projectDir/reports/report.xml"
80 | config = "$projectDir/detekt.yml"
81 | filters = ".*test.*,.*/resources/.*,.*/tmp/.*"
82 | }
83 | }
84 |
85 | publishing {
86 | publications {
87 | maven(MavenPublication) {
88 | from components.java
89 | pom.withXml {
90 | asNode().dependencies.'*'.findAll() {
91 | it.scope.text() == 'runtime' && project.configurations.compile.allDependencies.find { dep ->
92 | dep.name == it.artifactId.text()
93 | }
94 | }.each() {
95 | it.scope*.value = 'compile'
96 | }
97 | }
98 | }
99 | }
100 | }
101 |
102 | task sourcesJar(type: Jar, dependsOn: classes) {
103 | classifier = 'sources'
104 | from sourceSets.main.allSource
105 | }
106 |
107 |
108 | artifacts {
109 | archives sourcesJar
110 | }
111 |
112 | model {
113 | tasks.generatePomFileForMavenPublication {
114 | destination = file("$buildDir/libs/rxtest-" + version + ".pom")
115 | }
116 | }
117 |
--------------------------------------------------------------------------------
/descriptor.json:
--------------------------------------------------------------------------------
1 | {
2 | "package": {
3 | "name": "com.rubylichtenstein.rxtest",
4 | "repo": "RxTest",
5 | "subject": "rubylichtenstein",
6 | "desc": "Kotlin library for testing RxJava",
7 | "website_url": "",
8 | "issue_tracker_url": "https://github.com/RubyLichtenstein/RxTest/issues",
9 | "vcs_url": "https://github.com/RubyLichtenstein/RxTest.git",
10 | "licenses": ["Apache-2.0"],
11 | "labels": ["kotlin", "kotlin-dsl", "rxjava2", "bintray", "gradle"],
12 | "public_download_numbers": false,
13 | "public_stats": false
14 | },
15 |
16 | "version": {
17 | "name": "1.0.7",
18 | "released": "2018-02-27",
19 | "gpgSign": false
20 | },
21 |
22 | "files":
23 | [
24 | {"includePattern": "build/libs/(.*)", "uploadPattern": "com/rubylichtenstein/rxtest/1.0.7/$1"}
25 | ],
26 | "publish": true
27 | }
28 |
--------------------------------------------------------------------------------
/detekt.yml:
--------------------------------------------------------------------------------
1 | autoCorrect: true
2 | failFast: false
3 |
4 | test-pattern: # Configure exclusions for test sources
5 | active: true
6 | patterns: # Test file regexes
7 | - '.*/test/.*'
8 | - '.*Test.kt'
9 | - '.*Spec.kt'
10 | exclude-rule-sets:
11 | - 'comments'
12 | exclude-rules:
13 | - 'NamingRules'
14 | - 'WildcardImport'
15 | - 'MagicNumber'
16 | - 'MaxLineLength'
17 | - 'LateinitUsage'
18 | - 'StringLiteralDuplication'
19 | - 'SpreadOperator'
20 | - 'TooManyFunctions'
21 |
22 | build:
23 | warningThreshold: 5
24 | failThreshold: 10
25 | weights:
26 | complexity: 2
27 | formatting: 1
28 | LongParameterList: 1
29 | comments: 1
30 |
31 | processors:
32 | active: true
33 | exclude:
34 | # - 'FunctionCountProcessor'
35 | # - 'PropertyCountProcessor'
36 | # - 'ClassCountProcessor'
37 | # - 'PackageCountProcessor'
38 | # - 'KtFileCountProcessor'
39 |
40 | console-reports:
41 | active: true
42 | exclude:
43 | # - 'ProjectStatisticsReport'
44 | # - 'ComplexityReport'
45 | # - 'NotificationReport'
46 | # - 'FindingsReport'
47 | # - 'BuildFailureReport'
48 |
49 | output-reports:
50 | active: true
51 | exclude:
52 | # - 'PlainOutputReport'
53 | # - 'XmlOutputReport'
54 |
55 | comments:
56 | active: true
57 | CommentOverPrivateFunction:
58 | active: false
59 | CommentOverPrivateProperty:
60 | active: false
61 | UndocumentedPublicClass:
62 | active: false
63 | searchInNestedClass: true
64 | searchInInnerClass: true
65 | searchInInnerObject: true
66 | searchInInnerInterface: true
67 | UndocumentedPublicFunction:
68 | active: false
69 |
70 | complexity:
71 | active: true
72 | LongParameterList:
73 | active: true
74 | threshold: 5
75 | LongMethod:
76 | active: true
77 | threshold: 20
78 | LargeClass:
79 | active: true
80 | threshold: 150
81 | ComplexInterface:
82 | active: false
83 | threshold: 10
84 | includeStaticDeclarations: false
85 | ComplexMethod:
86 | active: true
87 | threshold: 10
88 | StringLiteralDuplication:
89 | active: false
90 | threshold: 2
91 | ignoreAnnotation: true
92 | excludeStringsWithLessThan5Characters: true
93 | ignoreStringsRegex: '$^'
94 | MethodOverloading:
95 | active: false
96 | threshold: 5
97 | NestedBlockDepth:
98 | active: true
99 | threshold: 3
100 | TooManyFunctions:
101 | active: true
102 | thresholdInFiles: 10
103 | thresholdInClasses: 10
104 | thresholdInInterfaces: 10
105 | thresholdInObjects: 10
106 | thresholdInEnums: 10
107 | ComplexCondition:
108 | active: true
109 | threshold: 3
110 | LabeledExpression:
111 | active: false
112 |
113 | empty-blocks:
114 | active: true
115 | EmptyCatchBlock:
116 | active: true
117 | EmptyClassBlock:
118 | active: true
119 | EmptyDefaultConstructor:
120 | active: true
121 | EmptyDoWhileBlock:
122 | active: true
123 | EmptyElseBlock:
124 | active: true
125 | EmptyFinallyBlock:
126 | active: true
127 | EmptyForBlock:
128 | active: true
129 | EmptyFunctionBlock:
130 | active: true
131 | EmptyIfBlock:
132 | active: true
133 | EmptyInitBlock:
134 | active: true
135 | EmptyKtFile:
136 | active: true
137 | EmptySecondaryConstructor:
138 | active: true
139 | EmptyWhenBlock:
140 | active: true
141 | EmptyWhileBlock:
142 | active: true
143 |
144 | exceptions:
145 | active: true
146 | TooGenericExceptionCaught:
147 | active: true
148 | exceptions:
149 | - ArrayIndexOutOfBoundsException
150 | - Error
151 | - Exception
152 | - IllegalMonitorStateException
153 | - NullPointerException
154 | - IndexOutOfBoundsException
155 | - RuntimeException
156 | - Throwable
157 | ExceptionRaisedInUnexpectedLocation:
158 | active: false
159 | methodNames: 'toString,hashCode,equals,finalize'
160 | TooGenericExceptionThrown:
161 | active: true
162 | exceptions:
163 | - Error
164 | - Exception
165 | - NullPointerException
166 | - Throwable
167 | - RuntimeException
168 | NotImplementedDeclaration:
169 | active: false
170 | PrintStackTrace:
171 | active: false
172 | InstanceOfCheckForException:
173 | active: false
174 | ThrowingExceptionsWithoutMessageOrCause:
175 | active: false
176 | exceptions: 'IllegalArgumentException,IllegalStateException,IOException'
177 | ReturnFromFinally:
178 | active: false
179 | ThrowingExceptionFromFinally:
180 | active: false
181 | ThrowingExceptionInMain:
182 | active: false
183 | RethrowCaughtException:
184 | active: false
185 | ThrowingNewInstanceOfSameException:
186 | active: false
187 | SwallowedException:
188 | active: false
189 |
190 | performance:
191 | active: true
192 | ForEachOnRange:
193 | active: true
194 | SpreadOperator:
195 | active: true
196 | UnnecessaryTemporaryInstantiation:
197 | active: true
198 |
199 | potential-bugs:
200 | active: true
201 | DuplicateCaseInWhenExpression:
202 | active: true
203 | EqualsAlwaysReturnsTrueOrFalse:
204 | active: false
205 | EqualsWithHashCodeExist:
206 | active: true
207 | IteratorNotThrowingNoSuchElementException:
208 | active: false
209 | IteratorHasNextCallsNextMethod:
210 | active: false
211 | UselessPostfixExpression:
212 | active: false
213 | InvalidLoopCondition:
214 | active: false
215 | WrongEqualsTypeParameter:
216 | active: false
217 | ExplicitGarbageCollectionCall:
218 | active: true
219 | LateinitUsage:
220 | active: false
221 | excludeAnnotatedProperties: ""
222 | ignoreOnClassesPattern: ""
223 | UnconditionalJumpStatementInLoop:
224 | active: false
225 | UnreachableCode:
226 | active: true
227 | UnsafeCallOnNullableType:
228 | active: false
229 | UnsafeCast:
230 | active: false
231 |
232 | style:
233 | active: true
234 | CollapsibleIfStatements:
235 | active: false
236 | ReturnCount:
237 | active: true
238 | max: 2
239 | excludedFunctions: "equals"
240 | ThrowsCount:
241 | active: true
242 | max: 2
243 | NewLineAtEndOfFile:
244 | active: true
245 | WildcardImport:
246 | active: true
247 | excludeImports: 'java.util.*,kotlinx.android.synthetic.*'
248 | MaxLineLength:
249 | active: true
250 | maxLineLength: 120
251 | excludePackageStatements: false
252 | excludeImportStatements: false
253 | EqualsNullCall:
254 | active: false
255 | ForbiddenComment:
256 | active: true
257 | values: 'TODO:,FIXME:,STOPSHIP:'
258 | ForbiddenImport:
259 | active: false
260 | imports: ''
261 | FunctionOnlyReturningConstant:
262 | active: false
263 | ignoreOverridableFunction: true
264 | excludedFunctions: 'describeContents'
265 | SpacingBetweenPackageAndImports:
266 | active: false
267 | LoopWithTooManyJumpStatements:
268 | active: false
269 | maxJumpCount: 1
270 | MemberNameEqualsClassName:
271 | active: false
272 | ignoreOverriddenFunction: true
273 | VariableNaming:
274 | active: true
275 | variablePattern: '[a-z][A-Za-z0-9]*'
276 | privateVariablePattern: '(_)?[a-z][A-Za-z0-9]*'
277 | VariableMinLength:
278 | active: false
279 | minimumVariableNameLength: 3
280 | VariableMaxLength:
281 | active: false
282 | maximumVariableNameLength: 30
283 | TopLevelPropertyNaming:
284 | active: true
285 | constantPattern: '[A-Z][_A-Z0-9]*'
286 | propertyPattern: '[a-z][A-Za-z\d]*'
287 | privatePropertyPattern: '(_)?[a-z][A-Za-z0-9]*'
288 | ObjectPropertyNaming:
289 | active: true
290 | propertyPattern: '[A-Za-z][_A-Za-z0-9]*'
291 | PackageNaming:
292 | active: true
293 | packagePattern: '^[a-z]+(\.[a-z][a-z0-9]*)*$'
294 | ClassNaming:
295 | active: true
296 | classPattern: '[A-Z$][a-zA-Z0-9$]*'
297 | EnumNaming:
298 | active: true
299 | enumEntryPattern: '^[A-Z$][a-zA-Z_$]*$'
300 | FunctionNaming:
301 | active: true
302 | functionPattern: '^([a-z$][a-zA-Z$0-9]*)|(`.*`)$'
303 | FunctionMaxLength:
304 | active: false
305 | maximumFunctionNameLength: 30
306 | FunctionMinLength:
307 | active: false
308 | minimumFunctionNameLength: 3
309 | ForbiddenClassName:
310 | active: false
311 | forbiddenName: ''
312 | SafeCast:
313 | active: true
314 | UnnecessaryAbstractClass:
315 | active: false
316 | UnnecessaryParentheses:
317 | active: false
318 | UnnecessaryInheritance:
319 | active: false
320 | UtilityClassWithPublicConstructor:
321 | active: false
322 | OptionalAbstractKeyword:
323 | active: true
324 | OptionalWhenBraces:
325 | active: false
326 | OptionalReturnKeyword:
327 | active: false
328 | OptionalUnit:
329 | active: false
330 | ProtectedMemberInFinalClass:
331 | active: false
332 | SerialVersionUIDInSerializableClass:
333 | active: false
334 | MagicNumber:
335 | active: true
336 | ignoreNumbers: '-1,0,1,2'
337 | ignoreHashCodeFunction: false
338 | ignorePropertyDeclaration: false
339 | ignoreConstantDeclaration: true
340 | ignoreCompanionObjectPropertyDeclaration: true
341 | ignoreAnnotation: false
342 | ignoreNamedArgument: true
343 | ignoreEnums: false
344 | ModifierOrder:
345 | active: true
346 | DataClassContainsFunctions:
347 | active: false
348 | conversionFunctionPrefix: 'to'
349 | UseDataClass:
350 | active: false
351 | UnusedImports:
352 | active: false
353 | ExpressionBodySyntax:
354 | active: false
355 | NestedClassesVisibility:
356 | active: false
357 | RedundantVisibilityModifierRule:
358 | active: false
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RubyLichtenstein/RxTest/7ab1391421c1b9880182e5a83a98ad15cb38e1c5/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sat Nov 04 11:21:47 IST 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.4.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn ( ) {
37 | echo "$*"
38 | }
39 |
40 | die ( ) {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save ( ) {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | rootProject.name = 'rxtest'
2 |
3 |
--------------------------------------------------------------------------------
/src/main/kotlin/com/rubylichtenstein/rxtest/assertions/Assertions.kt:
--------------------------------------------------------------------------------
1 | package com.rubylichtenstein.rxtest.assertions
2 |
3 | import com.rubylichtenstein.rxtest.matchers.Matcher
4 | import com.rubylichtenstein.rxtest.matchers.never
5 | import com.rubylichtenstein.rxtest.matchers.value
6 | import io.reactivex.functions.Predicate
7 | import io.reactivex.observers.BaseTestConsumer
8 | import java.lang.AssertionError
9 |
10 | /**
11 | * @param T the type of the stream.
12 | * @param U is TestObserver or TestSubscriber of type T
13 | * @see io.reactivex.observers.TestObserver
14 | * @see io.reactivex.subscribers.TestSubscriber
15 | *
16 | * @property matcher to assert.
17 | * matcher: Matcher>
18 | * @throws AssertionError
19 | * @return Unit on success or throws assertion error on failure
20 | */
21 | infix fun > BaseTestConsumer.should(matcher: Matcher>) =
22 | assertThat(this, matcher)
23 |
24 | /**
25 | * @param T the type of the stream.
26 | * @param U is TestObserver or TestSubscriber of type T
27 | * @see io.reactivex.observers.TestObserver
28 | * @see io.reactivex.subscribers.TestSubscriber
29 | *
30 | * @property matcher to assert.
31 | * matcher: Matcher>
32 | * @throws AssertionError
33 | * @return Unit on success or throws assertion error on failure
34 | */
35 | infix fun > BaseTestConsumer.shouldHave(matcher: Matcher>) =
36 | should(matcher)
37 |
38 | /**
39 | * @param T the type of the stream.
40 | * @param U is TestObserver or TestSubscriber of type T
41 | * @see io.reactivex.observers.TestObserver
42 | * @see io.reactivex.subscribers.TestSubscriber
43 | *
44 | * @property matcher to assert.
45 | * matcher: Matcher>
46 | * @throws AssertionError
47 | * @return Unit on success or throws assertion error on failure
48 | */
49 | infix fun > BaseTestConsumer.shouldBe(matcher: Matcher>) =
50 | should(matcher)
51 |
52 | /**
53 | * @param T the type of the stream.
54 | * @param U is TestObserver or TestSubscriber of type T
55 | * @see io.reactivex.observers.TestObserver
56 | * @see io.reactivex.subscribers.TestSubscriber
57 | *
58 | * @property matcher to assert.
59 | * matcher: Matcher>
60 | * @throws AssertionError
61 | * @return Unit on success or throws assertion error on failure
62 | */
63 | infix fun > BaseTestConsumer.shouldEmit(matcher: Matcher>) =
64 | should(matcher)
65 |
66 | /**
67 | * @param T the type of the stream.
68 | * @param U is TestObserver or TestSubscriber of type T
69 | * @see io.reactivex.observers.TestObserver
70 | * @see io.reactivex.subscribers.TestSubscriber
71 | *
72 | * @property matcher to assert.
73 | * matcher: Matcher>
74 | * @throws AssertionError
75 | * @return Unit on success or throws assertion error on failure
76 | */
77 | infix fun > BaseTestConsumer.shouldEmit(t: T) = shouldHave(value(t))
78 |
79 | /**
80 | * @param T the type of the stream.
81 | * @param U is TestObserver or TestSubscriber of type T
82 | * @see io.reactivex.observers.TestObserver
83 | * @see io.reactivex.subscribers.TestSubscriber
84 | *
85 | * @property matcher to assert.
86 | * matcher: Matcher>
87 | * @throws AssertionError
88 | * @return Unit on success or throws assertion error on failure
89 | */
90 | infix fun > BaseTestConsumer.shouldEmit(t: Predicate) = shouldHave(value(t))
91 |
92 | /**
93 | * @param T the type of the stream.
94 | * @param U is TestObserver or TestSubscriber of type T
95 | * @see io.reactivex.observers.TestObserver
96 | * @see io.reactivex.subscribers.TestSubscriber
97 | *
98 | * @property matcher to assert.
99 | * matcher: Matcher>
100 | * @throws AssertionError
101 | * @return Unit on success or throws assertion error on failure
102 | */
103 | infix fun > BaseTestConsumer.shouldNeverEmit(t: T) = should(never(t))
104 |
105 | /**
106 | * @param T the type of the stream.
107 | * @param U is TestObserver or TestSubscriber of type T
108 | * @see io.reactivex.observers.TestObserver
109 | * @see io.reactivex.subscribers.TestSubscriber
110 | *
111 | * @property matcher to assert.
112 | * matcher: Matcher>
113 | * @throws AssertionError
114 | * @return Unit on success or throws assertion error on failure
115 | */
116 | infix fun > BaseTestConsumer.shouldNeverEmit(t: Predicate) = should(never(t))
117 |
118 | internal fun > assertThat(
119 | baseTestConsumer: BaseTestConsumer,
120 | matcher: Matcher>
121 | ) = with(matcher.test(baseTestConsumer)) {
122 | if (!passed) {
123 | throw AssertionError(failMessage)
124 | }
125 | }
126 |
--------------------------------------------------------------------------------
/src/main/kotlin/com/rubylichtenstein/rxtest/extentions/Extantions.kt:
--------------------------------------------------------------------------------
1 | package com.rubylichtenstein.rxtest.extentions
2 |
3 | import io.reactivex.*
4 | import io.reactivex.observers.TestObserver
5 | import io.reactivex.subscribers.TestSubscriber
6 |
7 | /**
8 | * @param T type of stream
9 | * @param action to apply on TestObserver
10 | * @return TestObserver so more tests can be done
11 | */
12 | inline fun Maybe.test(action: (TestObserver) -> Unit): TestObserver = test().apply(action)
13 |
14 | /**
15 | * @param T type of stream
16 | * @param action to apply on TestObserver
17 | * @return TestObserver so more tests can be done
18 | */
19 | inline fun Single.test(action: (TestObserver) -> Unit): TestObserver = test().apply(action)
20 |
21 | /**
22 | * @param T type of stream
23 | * @param action to apply on TestObserver
24 | * @return TestObserver so more tests can be done
25 | */
26 | inline fun Observable.test(action: (TestObserver) -> Unit): TestObserver = test().apply(action)
27 |
28 | /**
29 | * @param action to apply on TestObserver
30 | * @return TestObserver so more tests can be done
31 | */
32 | inline fun Completable.test(action: (TestObserver) -> Unit): TestObserver = test().apply(action)
33 |
34 | /**
35 | * @param T type of stream
36 | * @param action to apply on TestSubscriber
37 | * @return TestSubscriber so more tests can be done
38 | */
39 | inline fun Flowable.test(action: (TestSubscriber) -> Unit): TestSubscriber = test().apply(action)
40 |
41 |
42 |
--------------------------------------------------------------------------------
/src/main/kotlin/com/rubylichtenstein/rxtest/matchers/CreateMatcher.kt:
--------------------------------------------------------------------------------
1 | package com.rubylichtenstein.rxtest.matchers
2 |
3 | import io.reactivex.observers.BaseTestConsumer
4 |
5 | /**
6 | * Create matcher by applying assertion on BaseTestConsumer
7 | *
8 | * @assertion assertion to apply on testConsumer,should return true on success.
9 | * @param failMessage to show in case of failure
10 | */
11 | inline fun > createMatcher(
12 | crossinline assertion: (BaseTestConsumer) -> Boolean,
13 | failMessage: String
14 | ): Matcher> {
15 | return object : Matcher> {
16 | override fun test(value: BaseTestConsumer) = Result(assertion.invoke(value), failMessage)
17 | }
18 | }
19 |
20 | /**
21 | * Create matcher by applying assertion on BaseTestConsumer
22 | *
23 | * @assertion native rx assertion to apply on BaseTestConsumer, should throws AssertionError on failure.
24 | * @return Matcher
25 | */
26 | internal inline fun > createMatcher(crossinline assertion: (BaseTestConsumer) -> Unit)
27 | : Matcher> {
28 | return object : Matcher> {
29 | override fun test(value: BaseTestConsumer): Result {
30 | applyAssertion(value, assertion).let {
31 | return Result(it == null, it?.message)
32 | }
33 | }
34 | }
35 | }
36 |
37 | internal inline fun > applyAssertion(
38 | testConsumer: BaseTestConsumer,
39 | assertion: (BaseTestConsumer) -> Unit
40 | )
41 | : AssertionError? {
42 | return try {
43 | assertion(testConsumer)
44 | null
45 | } catch (assertionError: AssertionError) {
46 | assertionError
47 | }
48 | }
49 |
50 |
--------------------------------------------------------------------------------
/src/main/kotlin/com/rubylichtenstein/rxtest/matchers/Matcher.kt:
--------------------------------------------------------------------------------
1 | package com.rubylichtenstein.rxtest.matchers
2 |
3 | /**
4 | * Generic matcher with logical OR/AND
5 | */
6 | interface Matcher {
7 |
8 | /**
9 | * apply test
10 | */
11 | fun test(value: T): Result
12 |
13 | /**
14 | * Logic AND
15 | */
16 | infix fun and(other: Matcher): Matcher = object : Matcher {
17 | override fun test(value: T): Result {
18 | return andTest(value, other)
19 | }
20 | }
21 |
22 | /**
23 | * Logic OR
24 | */
25 | infix fun or(other: Matcher): Matcher = object : Matcher {
26 | override fun test(value: T): Result {
27 | return orTest(value, other)
28 | }
29 | }
30 |
31 | private fun andTest(
32 | value: T,
33 | other: Matcher
34 | ): Result {
35 | val r = this.test(value)
36 | return if (!r.passed)
37 | r
38 | else
39 | other.test(value)
40 | }
41 |
42 | private fun orTest(
43 | value: T,
44 | other: Matcher
45 | ): Result {
46 | val r = this.test(value)
47 | return if (r.passed)
48 | r
49 | else
50 | other.test(value)
51 | }
52 | }
53 |
54 | /**
55 | * Matcher test result
56 | */
57 | data class Result(val passed: Boolean, val failMessage: String?)
58 |
--------------------------------------------------------------------------------
/src/main/kotlin/com/rubylichtenstein/rxtest/matchers/Matchers.kt:
--------------------------------------------------------------------------------
1 | package com.rubylichtenstein.rxtest.matchers
2 |
3 | import io.reactivex.functions.Predicate
4 | import io.reactivex.observers.BaseTestConsumer
5 |
6 | /**
7 | * @see io.reactivex.observers.TestObserver.assertComplete
8 | */
9 | fun > complete()
10 | = createMatcher({ it.assertComplete() })
11 |
12 | /**
13 | * @see io.reactivex.observers.TestObserver.assertNotComplete
14 | */
15 | fun > notComplete()
16 | = createMatcher({ it.assertNotComplete() })
17 |
18 | /**
19 | * @see io.reactivex.observers.TestObserver.assertError
20 | */
21 | fun > error(error: Throwable)
22 | = createMatcher({ it.assertError(error) })
23 |
24 | /**
25 | * @see io.reactivex.observers.TestObserver.assertError
26 | */
27 | fun > error(errorClass: Class)
28 | = createMatcher({ it.assertError(errorClass) })
29 |
30 | /**
31 | * @see io.reactivex.observers.TestObserver.assertError
32 | */
33 | fun > error(errorPredicate: Predicate)
34 | = createMatcher({ it.assertError(errorPredicate) })
35 |
36 | /**
37 | * @see io.reactivex.observers.TestObserver.assertNoErrors
38 | */
39 | fun > noErrors()
40 | = createMatcher({ it.assertNoErrors() })
41 |
42 | /**
43 | * @see io.reactivex.observers.TestObserver.assertValue
44 | */
45 | fun > value(value: T)
46 | = createMatcher({ it.assertValue(value) })
47 |
48 |
49 | /**
50 | * @see io.reactivex.observers.TestObserver.assertValue
51 | */
52 | fun > value(valuePredicate: Predicate)
53 | = createMatcher({ it.assertValue(valuePredicate) })
54 |
55 | /**
56 | * @see io.reactivex.observers.TestObserver.assertNever
57 | */
58 | fun > never(value: T)
59 | = createMatcher({ it.assertNever(value) })
60 |
61 |
62 | /**
63 | * @see io.reactivex.observers.TestObserver.assertNever
64 | */
65 | fun > never(neverPredicate: Predicate)
66 | = createMatcher({ it.assertNever(neverPredicate) })
67 |
68 | /**
69 | * @see io.reactivex.observers.TestObserver.assertValueAt
70 | */
71 | fun > valueAt(index: Int, value: T)
72 | = createMatcher({ it.assertValueAt(index, value) })
73 |
74 | /**
75 | * @see io.reactivex.observers.TestObserver.assertValueAt
76 | */
77 | fun > valueAt(index: Int, valuePredicate: Predicate)
78 | = createMatcher({ it.assertValueAt(index, valuePredicate) })
79 |
80 |
81 | /**
82 | * @see io.reactivex.observers.TestObserver.assertValues
83 | */
84 | fun > values(vararg values: T)
85 | = createMatcher({ it.assertValues(*values) })
86 |
87 | /**
88 | * @see io.reactivex.observers.TestObserver.assertEmpty
89 | */
90 | fun > empty()
91 | = createMatcher({ it.assertEmpty() })
92 |
93 | /**
94 | * @see io.reactivex.observers.TestObserver.assertSubscribed
95 | */
96 | fun > subscribed()
97 | = createMatcher({ it.assertSubscribed() })
98 |
99 | /**
100 | * @see io.reactivex.observers.TestObserver.assertFailure
101 | */
102 | fun > failure(errorPredicate: Predicate, vararg values: T)
103 | = createMatcher({ it.assertFailure(errorPredicate, *values) })
104 |
105 | /**
106 | * @see io.reactivex.observers.TestObserver.assertFailure
107 | */
108 | fun > failure(error: Class, vararg values: T)
109 | = createMatcher({ it.assertFailure(error, *values) })
110 |
111 | /**
112 | * @see io.reactivex.observers.TestObserver.assertFailureAndMessage
113 | */
114 | fun > failureAndMessage(error: Class,
115 | message: String,
116 | vararg values: T)
117 | = createMatcher({ it.assertFailureAndMessage(error, message, *values) })
118 |
119 | /**
120 | * @see io.reactivex.observers.TestObserver.assertResult
121 | */
122 | fun > result(vararg values: T)
123 | = createMatcher({ it.assertResult(*values) })
124 |
125 | /**
126 | * @see io.reactivex.observers.TestObserver.assertTerminated
127 | */
128 | fun > terminate()
129 | = createMatcher({ it.assertTerminated() })
130 |
131 | /**
132 | * @see io.reactivex.observers.TestObserver.assertValueCount
133 | */
134 | fun > valueCount(count: Int)
135 | = createMatcher({ it.assertValueCount(count) })
136 |
137 | /**
138 | * @see io.reactivex.observers.TestObserver.assertValueSequence
139 | */
140 | fun > valueSequence(sequence: Iterable)
141 | = createMatcher({ it.assertValueSequence(sequence) })
142 |
143 | /**
144 | * @see io.reactivex.observers.TestObserver.assertValueSet
145 | */
146 | fun > valueSet(expected: Collection)
147 | = createMatcher({ it.assertValueSet(expected) })
148 |
149 | /**
150 | * @see io.reactivex.observers.TestObserver.assertValuesOnly
151 | */
152 | fun > valueOnly(vararg values: T)
153 | = createMatcher({ it.assertValuesOnly(*values) })
154 |
155 | /**
156 | * @see io.reactivex.observers.TestObserver.assertTimeout
157 | */
158 | fun > timeout()
159 | = createMatcher({ it.assertTimeout() })
160 |
161 | /**
162 | * @see io.reactivex.observers.TestObserver.assertNoTimeout
163 | */
164 | fun > noTimeout()
165 | = createMatcher({ it.assertNoTimeout() })
166 |
167 | /**
168 | * @see io.reactivex.observers.TestObserver.assertNotSubscribed
169 | */
170 | fun > notSubscribed()
171 | = createMatcher({ it.assertNotSubscribed() })
172 |
--------------------------------------------------------------------------------
/src/test/kotlin/com/rubylichtenstein/rxtest/matchers/CreateMatcherTest.kt:
--------------------------------------------------------------------------------
1 | package com.rubylichtenstein.rxtest.matchers
2 |
3 | import com.rubylichtenstein.rxtest.assertions.shouldEmit
4 | import com.rubylichtenstein.rxtest.assertions.shouldHave
5 | import com.rubylichtenstein.rxtest.extentions.test
6 | import io.reactivex.Observable
7 | import io.reactivex.observers.BaseTestConsumer
8 | import io.reactivex.observers.TestObserver
9 | import org.hamcrest.CoreMatchers.notNullValue
10 | import org.hamcrest.MatcherAssert.assertThat
11 | import org.jetbrains.spek.api.Spek
12 | import org.jetbrains.spek.api.dsl.describe
13 | import org.jetbrains.spek.api.dsl.it
14 | import org.jetbrains.spek.api.dsl.on
15 |
16 | internal
17 | object CreateMatcherTest : Spek({
18 | describe("MatchersTest") {
19 | on("createMatcherOrAndTest") {
20 | val hello = "Hello"
21 | val stranger = "stranger"
22 |
23 | val itemsCount = 2
24 |
25 | val observable by memoized { Observable.just(hello, stranger) }
26 |
27 | it("or test") {
28 | observable.test {
29 | it shouldHave (valueCountBetween(0, itemsCount - 1) or values(hello, stranger))
30 | }
31 | }
32 |
33 | it("and test") {
34 | observable.test {
35 | it shouldHave (valueCountBetween(itemsCount - 1, itemsCount + 1) and values(
36 | hello,
37 | stranger
38 | ))
39 | }
40 | }
41 |
42 | it("fail and test") {
43 | observable.test {
44 | try {
45 | it shouldHave (valueCountBetween(0, itemsCount - 1) and values(hello, stranger))
46 | } catch (e: AssertionError) {
47 | assertThat(e, notNullValue())
48 | }
49 | }
50 | }
51 |
52 | it("or test") {
53 | observable.test {
54 | it shouldHave (valueCountBetween(0, itemsCount + 1) or values(hello, stranger))
55 | }
56 | }
57 | }
58 |
59 | on("create matcher test") {
60 | val values = listOf("Rx", "Kotlin", "Test")
61 |
62 | it("moreValuesThen") {
63 | Observable.fromIterable(values)
64 | .test {
65 | it shouldEmit moreValuesThen(2)
66 | }
67 | }
68 |
69 | it("noValues") {
70 | Observable.empty()
71 | .test {
72 | it shouldHave noValues()
73 | }
74 | }
75 |
76 | it("errorOrComplete") {
77 | Observable.just("")
78 | .test {
79 | it shouldHave errorOrComplete(Throwable())
80 | }
81 | }
82 |
83 | it("valueCountBetween") {
84 | Observable.just("", "")
85 | .test {
86 | it shouldHave valueCountBetween(1, 3)
87 | }
88 | }
89 |
90 | }
91 | }
92 | })
93 |
94 | internal fun > noValues() = valueCount(0)
95 |
96 | internal fun > errorOrComplete(error: Throwable) = error(error) or complete()
97 |
98 | internal fun > moreValuesThen(count: Int) = createMatcher(
99 | { it.values().size > count },
100 | failMessage = "Less values then $count"
101 | )
102 |
103 |
104 | internal fun > lessValuesThen(count: Int) =
105 | createMatcher(
106 | { it.values().size < count },
107 | failMessage = "More values then $count"
108 | )
109 |
110 | internal fun valueCountBetween(min: Int, max: Int) =
111 | moreValuesThen>(min) and lessValuesThen>(max)
112 |
113 |
--------------------------------------------------------------------------------
/src/test/kotlin/com/rubylichtenstein/rxtest/matchers/MatchersTest.kt:
--------------------------------------------------------------------------------
1 | package com.rubylichtenstein.rxtest.matchers
2 |
3 | import com.rubylichtenstein.rxtest.assertions.*
4 | import com.rubylichtenstein.rxtest.extentions.test
5 | import io.reactivex.*
6 | import io.reactivex.functions.Predicate
7 | import io.reactivex.observers.TestObserver
8 | import io.reactivex.schedulers.TestScheduler
9 | import io.reactivex.subjects.PublishSubject
10 | import io.reactivex.subjects.ReplaySubject
11 | import junit.framework.TestCase.assertNotNull
12 | import org.jetbrains.spek.api.Spek
13 | import org.jetbrains.spek.api.dsl.describe
14 | import org.jetbrains.spek.api.dsl.it
15 | import org.jetbrains.spek.api.dsl.on
16 | import java.util.concurrent.TimeUnit
17 |
18 | internal
19 | object MatchersTest : Spek({
20 | describe("") {
21 |
22 | val item0 = "a"
23 | val item1 = "b"
24 | val item2 = "c"
25 |
26 | val items = listOf(item0, item1, item2)
27 |
28 | it("should complete") {
29 |
30 | Maybe.just("")
31 | .test {
32 | it should complete()
33 | }
34 |
35 | Single.just("")
36 | .test {
37 | it should complete()
38 | }
39 |
40 | Completable.complete()
41 | .test {
42 | it should complete()
43 | }
44 | Observable.just("hello")
45 | .toFlowable(BackpressureStrategy.BUFFER)
46 | .test {
47 | it should complete()
48 | }
49 |
50 | assertThrowsAssertionError {
51 | PublishSubject.create()
52 | .test {
53 | it should complete()
54 | }
55 | }
56 | }
57 |
58 | it("should not complete") {
59 | PublishSubject.create()
60 | .test {
61 | it should notComplete()
62 | }
63 |
64 | assertThrowsAssertionError {
65 | PublishSubject.create()
66 | .test {
67 | it should complete()
68 | }
69 | }
70 | }
71 |
72 | it("should have error obj") {
73 | val assertionError = AssertionError()
74 |
75 | PublishSubject.create()
76 | .apply {
77 | onError(assertionError)
78 | }
79 | .test {
80 | it shouldHave error(assertionError)
81 | }
82 | }
83 |
84 | it("should have error type") {
85 | PublishSubject.create()
86 | .apply {
87 | onError(AssertionError())
88 | }
89 | .test {
90 | it shouldHave error(AssertionError::class.java)
91 | }
92 | }
93 |
94 | it("should have error predicate") {
95 | val assertionError = AssertionError()
96 | PublishSubject.create()
97 | .apply {
98 | onError(assertionError)
99 | }
100 | .test {
101 | it shouldHave error(Predicate { it == assertionError })
102 | }
103 | }
104 |
105 | it("should have no errors") {
106 | PublishSubject.create()
107 | .test {
108 | it shouldHave noErrors()
109 | }
110 | }
111 |
112 | on("value") {
113 | val value = "a"
114 | val obs = Observable.just(value)
115 |
116 | it("should have first value") {
117 | obs.test {
118 | it shouldHave value(value)
119 | }
120 | }
121 |
122 | it("should emit first value") {
123 | obs.test {
124 | it shouldEmit value
125 | }
126 | }
127 |
128 | it("should have first predicate value") {
129 | obs.test {
130 | it shouldHave value(Predicate { it == value })
131 | }
132 | }
133 |
134 | it("should emit first predicate value") {
135 | obs.test {
136 | it shouldEmit Predicate { it == value }
137 | }
138 | }
139 | }
140 |
141 | on("should have value at") {
142 | val value0 = "a"
143 | val value1 = "b"
144 | val obs by memoized {
145 | Observable.just(value0, value1)
146 | }
147 |
148 | it("with obj") {
149 | obs.test {
150 | it shouldHave valueAt(0, value0)
151 | it shouldHave valueAt(1, value1)
152 | }
153 | }
154 |
155 | it("with predicate") {
156 | obs.test {
157 | it shouldHave valueAt(0, Predicate { value -> value == value0 })
158 | it shouldHave valueAt(1, Predicate { value -> value == value1 })
159 | }
160 | }
161 | }
162 |
163 | on("should have values") {
164 | val value0 = "a"
165 | val value1 = "b"
166 | val obs by memoized {
167 | Observable.just(value0, value1)
168 | }
169 |
170 | it("have") {
171 | obs.test {
172 | it shouldHave values(value0, value1)
173 | }
174 | }
175 |
176 | it("emit") {
177 | obs.test {
178 | it shouldEmit values(value0, value1)
179 |
180 | }
181 | }
182 | }
183 |
184 | on("values") {
185 | val valueSequence = listOf(item0, item1, item2)
186 | val obs = Observable.fromIterable(valueSequence)
187 |
188 | it("valueSequenceTest") {
189 | obs.test {
190 | it shouldEmit valueSequence(valueSequence)
191 | }
192 | }
193 |
194 | it("valueSetTest") {
195 | obs.test {
196 | it shouldEmit valueSet(valueSequence)
197 | }
198 | }
199 |
200 | it("value Only") {
201 | ReplaySubject.create()
202 | .also {
203 | it.onNext(item0)
204 | it.onNext(item1)
205 | it.onNext(item2)
206 | }
207 | .test {
208 | it shouldEmit valueOnly(item0, item1, item2)
209 | }
210 | }
211 | }
212 |
213 | on("never") {
214 | val value = "a"
215 | val never = "b"
216 | val obs = Observable.just(value)
217 |
218 | val valuePredicate = Predicate { v: String -> v == never }
219 |
220 | it("should never") {
221 | obs.test {
222 | it should never(never)
223 | }
224 | }
225 |
226 | it("should never emit") {
227 | obs.test {
228 | it shouldNeverEmit never
229 | }
230 | }
231 |
232 | it("should never predicate") {
233 | obs.test {
234 | it should never(valuePredicate)
235 | }
236 | }
237 |
238 | it("should never") {
239 | obs.test {
240 | it shouldNeverEmit valuePredicate
241 | }
242 | }
243 | }
244 |
245 | it("emptyTest") {
246 | PublishSubject.create()
247 | .test {
248 | it shouldBe empty()
249 | }
250 | }
251 |
252 | on("failure") {
253 | val value0 = "a"
254 | val value1 = "b"
255 | val errorMessage = "Error"
256 | val error = Throwable(errorMessage)
257 |
258 | val obs = ReplaySubject.create()
259 | .also {
260 | it.onNext(value0)
261 | it.onNext(value1)
262 | it.onError(error)
263 | }
264 |
265 | it("failure by class") {
266 | obs.test {
267 | it shouldHave failure(Throwable::class.java, value0, value1)
268 | }
269 | }
270 |
271 | it("failure by predicate") {
272 | obs.test {
273 | it shouldHave failure(Predicate { true }, value0, value1)
274 | }
275 | }
276 |
277 | it("failureAndMessageTest") {
278 |
279 | obs.test {
280 | it shouldHave failureAndMessage(Throwable::class.java, errorMessage, value0, value1)
281 | }
282 | }
283 | }
284 |
285 | it("resultTest") {
286 | val value0 = "a"
287 | val value1 = "b"
288 | val values = listOf(value0, value1)
289 | Observable.just(values)
290 | .test {
291 | it shouldHave result(values)
292 | }
293 | }
294 |
295 | it("subscribeTest") {
296 | val value0 = "a"
297 | Observable.just(value0)
298 | .apply {
299 | subscribe({ })
300 | test {
301 | it should subscribed()
302 | }
303 | }
304 | }
305 |
306 | it("valueCountTest") {
307 | Observable.fromIterable(items)
308 | .test {
309 | it shouldHave valueCount(items.size)
310 | }
311 | }
312 |
313 | it("terminateTest") {
314 | Observable.just(item0)
315 | .test {
316 | it should terminate()
317 | }
318 |
319 | Observable.error(Throwable())
320 | .test {
321 | it should terminate()
322 | }
323 | }
324 |
325 | it("timeoutTest") {
326 | val scheduler = TestScheduler()
327 | val delay = 100L
328 | Observable
329 | .interval(delay, TimeUnit.MILLISECONDS, scheduler)
330 | .test {
331 | it.await(delay / 2, TimeUnit.MILLISECONDS)
332 | it shouldHave timeout()
333 | }
334 | }
335 |
336 | it("noTimeoutTest") {
337 | val scheduler = TestScheduler()
338 |
339 | Observable
340 | .interval(100, TimeUnit.MILLISECONDS, scheduler)
341 | .test {
342 | it shouldHave noTimeout()
343 | }
344 | }
345 |
346 | it("notSubscribedTest") {
347 | TestObserver()
348 | .apply {
349 | should(notSubscribed())
350 | }
351 | }
352 | }
353 | })
354 |
355 | internal fun assertThrowsAssertionError(function: () -> Unit) {
356 | val assertionError = catchAssertionError { function() }
357 | assertNotNull(assertionError)
358 | }
359 |
360 | internal fun catchAssertionError(function: () -> Unit): AssertionError? {
361 | return try {
362 | function.invoke()
363 | null
364 | } catch (assertionError: AssertionError) {
365 | return assertionError
366 | }
367 | }
368 |
--------------------------------------------------------------------------------