├── .buildscript └── deploy_snapshot.sh ├── .github ├── funding.yml └── workflows │ ├── build.yml │ ├── publish-release.yml │ └── publish-snapshot.yml ├── .gitignore ├── CHANGELOG.md ├── LICENSE ├── README.md ├── build.gradle ├── espresso-core-utils ├── .gitignore ├── build.gradle ├── gradle.properties ├── lint.xml └── src │ ├── androidTest │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── vanniktech │ │ │ └── espresso │ │ │ └── core │ │ │ └── utils │ │ │ ├── AppendTextActionActivity.java │ │ │ ├── AppendTextActionTest.java │ │ │ ├── AttributeMatcherActivity.java │ │ │ ├── AttributeMatcherTest.java │ │ │ ├── CurrentItemMatcherActivity.java │ │ │ ├── CurrentItemMatcherTest.java │ │ │ ├── DrawableMatcherActivity.java │ │ │ ├── DrawableMatcherTest.java │ │ │ ├── HintTextColorMatcherActivity.java │ │ │ ├── HintTextColorMatcherTest.java │ │ │ ├── ProgressBarActivity.java │ │ │ ├── ProgressMatcherTest.java │ │ │ ├── SetProgressActionTest.java │ │ │ ├── TextColorMatcherActivity.java │ │ │ ├── TextColorMatcherTest.java │ │ │ ├── TextViewDrawableMatcherActivity.java │ │ │ ├── TextViewDrawableMatcherTest.java │ │ │ ├── ViewIndexMatcherActivity.java │ │ │ └── ViewIndexMatcherTest.java │ └── res │ │ ├── drawable │ │ ├── android.png │ │ └── northern_lights.jpg │ │ └── values │ │ ├── colors.xml │ │ └── themes.xml │ ├── main │ └── java │ │ └── com │ │ └── vanniktech │ │ └── espresso │ │ └── core │ │ └── utils │ │ ├── AppendTextAction.java │ │ ├── AttributeMatcher.java │ │ ├── ColorChecker.java │ │ ├── CurrentItemMatcher.java │ │ ├── DrawableMatcher.java │ │ ├── HintTextColorMatcher.java │ │ ├── ProgressMatcher.java │ │ ├── SetProgressAction.java │ │ ├── TextColorMatcher.java │ │ ├── TextViewDrawableMatcher.java │ │ ├── Utils.java │ │ └── ViewIndexMatcher.java │ └── test │ └── java │ └── com │ └── vanniktech │ └── espresso │ └── core │ └── utils │ ├── TextViewDrawableMatcherTypeTest.java │ └── UtilsTest.java ├── get-espresso-core-utils-methods.sh ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── renovate.json └── settings.gradle /.buildscript/deploy_snapshot.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Deploy a jar, source jar, and javadoc jar to Sonatype's snapshot repo. 4 | # 5 | # Adapted from https://coderwall.com/p/9b_lfq and 6 | # http://benlimmer.com/2013/12/26/automatically-publish-javadoc-to-gh-pages-with-travis-ci/ and 7 | # https://github.com/JakeWharton/RxBinding/blob/master/.buildscript/deploy_snapshot.sh 8 | 9 | SLUG="vanniktech/espresso-utils" 10 | JDK="oraclejdk8" 11 | BRANCH="master" 12 | 13 | set -e 14 | 15 | if [ "$TRAVIS_REPO_SLUG" != "$SLUG" ]; then 16 | echo "Skipping snapshot deployment: wrong repository. Expected '$SLUG' but was '$TRAVIS_REPO_SLUG'." 17 | elif [ "$TRAVIS_JDK_VERSION" != "$JDK" ]; then 18 | echo "Skipping snapshot deployment: wrong JDK. Expected '$JDK' but was '$TRAVIS_JDK_VERSION'." 19 | elif [ "$TRAVIS_PULL_REQUEST" != "false" ]; then 20 | echo "Skipping snapshot deployment: was pull request." 21 | elif [ "$TRAVIS_BRANCH" != "$BRANCH" ]; then 22 | echo "Skipping snapshot deployment: wrong branch. Expected '$BRANCH' but was '$TRAVIS_BRANCH'." 23 | else 24 | echo "Deploying snapshot..." 25 | ./gradlew uploadArchives 26 | echo "Snapshot deployed!" 27 | fi -------------------------------------------------------------------------------- /.github/funding.yml: -------------------------------------------------------------------------------- 1 | github: [vanniktech] -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | 3 | on: [push, pull_request, merge_group] 4 | 5 | jobs: 6 | build: 7 | name: JDK ${{ matrix.java_version }} 8 | runs-on: ubuntu-latest 9 | 10 | strategy: 11 | matrix: 12 | java_version: [17] 13 | 14 | steps: 15 | - name: Checkout 16 | uses: actions/checkout@v4 17 | 18 | - name: Gradle Wrapper Validation 19 | uses: gradle/actions/wrapper-validation@v4 20 | 21 | - name: Setup gradle 22 | uses: gradle/gradle-build-action@v3 23 | 24 | - name: Install JDK ${{ matrix.java_version }} 25 | uses: actions/setup-java@v4 26 | with: 27 | distribution: 'zulu' 28 | java-version: ${{ matrix.java_version }} 29 | 30 | - name: Build with Gradle 31 | run: ./gradlew build --stacktrace -x connectedDebugAndroidTest -x connectedCheck 32 | -------------------------------------------------------------------------------- /.github/workflows/publish-release.yml: -------------------------------------------------------------------------------- 1 | name: Publish Release 2 | 3 | on: 4 | push: 5 | tags: 6 | - '*' 7 | 8 | jobs: 9 | publish: 10 | 11 | runs-on: ubuntu-latest 12 | if: github.repository == 'vanniktech/espresso-utils' 13 | 14 | steps: 15 | - name: Checkout 16 | uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 17 | 18 | - name: Install JDK 17 19 | uses: actions/setup-java@v4 20 | with: 21 | distribution: 'zulu' 22 | java-version: 17 23 | 24 | - name: Setup gradle 25 | uses: gradle/gradle-build-action@v3 26 | 27 | - name: Publish release 28 | run: ./gradlew publishAllPublicationsToMavenCentralRepository 29 | env: 30 | ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.SONATYPE_NEXUS_USERNAME }} 31 | ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.SONATYPE_NEXUS_PASSWORD }} 32 | ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.SIGNING_PRIVATE_KEY }} 33 | ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.SIGNING_PASSWORD }} 34 | -------------------------------------------------------------------------------- /.github/workflows/publish-snapshot.yml: -------------------------------------------------------------------------------- 1 | name: Publish Snapshot 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | 8 | jobs: 9 | publish: 10 | 11 | runs-on: ubuntu-latest 12 | if: github.repository == 'vanniktech/espresso-utils' 13 | 14 | steps: 15 | - name: Checkout 16 | uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 17 | 18 | - name: Install JDK 17 19 | uses: actions/setup-java@v4 20 | with: 21 | distribution: 'zulu' 22 | java-version: 17 23 | 24 | - name: Setup gradle 25 | uses: gradle/gradle-build-action@v3 26 | 27 | - name: Retrieve version 28 | run: | 29 | echo "VERSION_NAME=$(cat gradle.properties | grep -w "VERSION_NAME" | cut -d'=' -f2)" >> $GITHUB_ENV 30 | 31 | - name: Publish snapshot 32 | run: ./gradlew publishAllPublicationsToMavenCentralRepository 33 | if: endsWith(env.VERSION_NAME, '-SNAPSHOT') 34 | env: 35 | ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.SONATYPE_NEXUS_USERNAME }} 36 | ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.SONATYPE_NEXUS_PASSWORD }} 37 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # generated files 2 | bin/ 3 | gen/ 4 | 5 | # Java class files 6 | *.class 7 | 8 | # Sublime 9 | *.sublime-workspace 10 | 11 | # Android Studio 12 | .idea 13 | .gradle 14 | build/ 15 | *.iml 16 | captures/ 17 | local.properties 18 | 19 | # Editor temp files 20 | *~ 21 | *.swp 22 | 23 | # OSX files 24 | .DS_Store 25 | 26 | # secret signing stuff 27 | keystore-secrets 28 | 29 | paperwork.json 30 | 31 | #lint result 32 | lint-result.xml 33 | 34 | # Oh my zsh plugins 35 | .gradletasknamecache 36 | 37 | # Files generated by AspectJ 38 | ajcore.*.txt -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | Version 0.5.0 *(In development)* 4 | -------------------------------- 5 | 6 | Version 0.4.0 *(2022-05-11)* 7 | ---------------------------- 8 | 9 | - Fix allOf import which caused runtime crashes. [\#58](https://github.com/vanniktech/espresso-utils/pull/58) ([vanniktech](https://github.com/vanniktech)) 10 | - Update dependencies. [\#57](https://github.com/vanniktech/espresso-utils/pull/57) ([vanniktech](https://github.com/vanniktech)) 11 | - Switch to GitHub workflows. [\#55](https://github.com/vanniktech/espresso-utils/pull/55) ([vanniktech](https://github.com/vanniktech)) 12 | - Add ViewIndexMatcher. [\#54](https://github.com/vanniktech/espresso-utils/pull/54) ([vanniktech](https://github.com/vanniktech)) 13 | 14 | Version 0.3.0 *(2019-01-06)* 15 | ---------------------------- 16 | 17 | - Upgrade to AndroidX. [\#52](https://github.com/vanniktech/espresso-utils/pull/52) ([vanniktech](https://github.com/vanniktech)) 18 | - Remove sudo: false from travis config. [\#50](https://github.com/vanniktech/espresso-utils/pull/50) ([vanniktech](https://github.com/vanniktech)) 19 | - Use Gradle Maven Publish Plugin for publishing. [\#48](https://github.com/vanniktech/espresso-utils/pull/48) ([vanniktech](https://github.com/vanniktech)) 20 | - SetProgressAction to set the progress of a ProgressBar. [\#47](https://github.com/vanniktech/espresso-utils/pull/47) ([vanniktech](https://github.com/vanniktech)) 21 | - Remove Code Quality Tools for Kotlin as there's no Kotlin in here. [\#46](https://github.com/vanniktech/espresso-utils/pull/46) ([vanniktech](https://github.com/vanniktech)) 22 | - Nuke badges in README. [\#45](https://github.com/vanniktech/espresso-utils/pull/45) ([vanniktech](https://github.com/vanniktech)) 23 | - Update README and add Java documentation to all classes. [\#44](https://github.com/vanniktech/espresso-utils/pull/44) ([vanniktech](https://github.com/vanniktech)) 24 | - Tweak Travis configuration. [\#41](https://github.com/vanniktech/espresso-utils/pull/41) ([vanniktech](https://github.com/vanniktech)) 25 | - Unify Detekt configurations with RC6. [\#31](https://github.com/vanniktech/espresso-utils/pull/31) ([vanniktech](https://github.com/vanniktech)) 26 | - Increase testing coverage. [\#24](https://github.com/vanniktech/espresso-utils/pull/24) ([vanniktech](https://github.com/vanniktech)) 27 | - Increase testing coverage. [\#22](https://github.com/vanniktech/espresso-utils/pull/22) ([vanniktech](https://github.com/vanniktech)) 28 | 29 | Version 0.2.0 *(2017-08-20)* 30 | ---------------------------- 31 | 32 | - Don't clean build again when deploying SNAPSHOTS. [\#21](https://github.com/vanniktech/espresso-utils/pull/21) ([vanniktech](https://github.com/vanniktech)) 33 | - Add tests for TextViewDrawableMatcher. [\#20](https://github.com/vanniktech/espresso-utils/pull/20) ([vanniktech](https://github.com/vanniktech)) 34 | - Consistent return types. [\#19](https://github.com/vanniktech/espresso-utils/pull/19) ([vanniktech](https://github.com/vanniktech)) 35 | - Add tests for AttributeMatcher. [\#18](https://github.com/vanniktech/espresso-utils/pull/18) ([vanniktech](https://github.com/vanniktech)) 36 | - Add tests for DrawableMatcher. [\#17](https://github.com/vanniktech/espresso-utils/pull/17) ([vanniktech](https://github.com/vanniktech)) 37 | - Clean up a few things. [\#16](https://github.com/vanniktech/espresso-utils/pull/16) ([vanniktech](https://github.com/vanniktech)) 38 | - Add tests for HintTextColorMatcher. [\#15](https://github.com/vanniktech/espresso-utils/pull/15) ([vanniktech](https://github.com/vanniktech)) 39 | - Add tests for CurrentItemMatcher. [\#14](https://github.com/vanniktech/espresso-utils/pull/14) ([vanniktech](https://github.com/vanniktech)) 40 | - Add tests for AppendTextAction. [\#13](https://github.com/vanniktech/espresso-utils/pull/13) ([vanniktech](https://github.com/vanniktech)) 41 | - Add tests for ProgressMatcher. [\#12](https://github.com/vanniktech/espresso-utils/pull/12) ([vanniktech](https://github.com/vanniktech)) 42 | - Add tests for TextColorMatcher. [\#11](https://github.com/vanniktech/espresso-utils/pull/11) ([vanniktech](https://github.com/vanniktech)) 43 | - Update Support Library to 26.0.1 [\#10](https://github.com/vanniktech/espresso-utils/pull/10) ([vanniktech](https://github.com/vanniktech)) 44 | - Update Jacoco Gradle Plugin to 0.8.0 & Code Quality Plugin to 0.8.0 [\#9](https://github.com/vanniktech/espresso-utils/pull/9) ([vanniktech](https://github.com/vanniktech)) 45 | - Update to Espresso 3.0.0 & Test Runner rules 1.0.0 [\#8](https://github.com/vanniktech/espresso-utils/pull/8) ([vanniktech](https://github.com/vanniktech)) 46 | - Update Gradle to 4.1 [\#7](https://github.com/vanniktech/espresso-utils/pull/7) ([vanniktech](https://github.com/vanniktech)) 47 | - Update Code Quality Tools to 0.7.0 [\#6](https://github.com/vanniktech/espresso-utils/pull/6) ([vanniktech](https://github.com/vanniktech)) 48 | - Let Gradle install all of the Android dependencies. [\#5](https://github.com/vanniktech/espresso-utils/pull/5) ([vanniktech](https://github.com/vanniktech)) 49 | - Add TextViewDrawableMatcher. [\#4](https://github.com/vanniktech/espresso-utils/pull/4) ([vanniktech](https://github.com/vanniktech)) 50 | - Update Code Quality Tools Plugin to 0.5.0 [\#3](https://github.com/vanniktech/espresso-utils/pull/3) ([vanniktech](https://github.com/vanniktech)) 51 | - Update Error Prone to 2.0.20 [\#2](https://github.com/vanniktech/espresso-utils/pull/2) ([vanniktech](https://github.com/vanniktech)) 52 | 53 | Version 0.1.0 *(2017-07-01)* 54 | ---------------------------- 55 | 56 | - Initial version -------------------------------------------------------------------------------- /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 | Espresso Utils 2 | ============== 3 | 4 | Provides helper methods for asserting a few things that Espresso does not support out of the box. 5 | 6 | # Espresso Core Utils 7 | 8 | ```groovy 9 | androidTestImplementation 'com.vanniktech:espresso-core-utils:0.4.0' 10 | ``` 11 | 12 | ### Snapshots 13 | 14 | ```groovy 15 | repositories { 16 | maven { url "https://oss.sonatype.org/content/repositories/snapshots" } 17 | } 18 | 19 | dependencies { 20 | androidTestImplementation 'com.vanniktech:espresso-core-utils:0.5.0-SNAPSHOT' 21 | } 22 | ``` 23 | 24 | # APIs 25 | 26 | ### ViewActions: 27 | 28 | All of those are ViewActions that can be placed inside the `perform` function. `onView(withId(R.id.view)).perform(...);` 29 | 30 | ```java 31 | appendText(String text) 32 | ``` 33 | 34 | ### ViewMatchers: 35 | 36 | All of those are ViewMatchers that can be placed inside the `matches` function. `onView(withId(R.id.view)).check(matches(...));` 37 | 38 | ```java 39 | appendText(String text) 40 | withTextViewDrawableLeft(@DrawableRes int resourceId) 41 | withNoTextViewDrawableLeft() 42 | withTextViewDrawableRelativeLeft(@DrawableRes int resourceId) 43 | withNoTextViewDrawableRelativeLeft() 44 | withTextViewDrawableTop(@DrawableRes int resourceId) 45 | withNoTextViewDrawableTop() 46 | withTextViewDrawableRelativeTop(@DrawableRes int resourceId) 47 | withNoTextViewDrawableRelativeTop() 48 | withTextViewDrawableRight(@DrawableRes int resourceId) 49 | withNoTextViewDrawableRight() 50 | withTextViewDrawableRelativeRight(@DrawableRes int resourceId) 51 | withNoTextViewDrawableRelativeRight() 52 | withTextViewDrawableBottom(@DrawableRes int resourceId) 53 | withNoTextViewDrawableBottom() 54 | withTextViewDrawableRelativeBottom(@DrawableRes int resourceId) 55 | withNoTextViewDrawableRelativeBottom() 56 | withProgress(int progress) 57 | withDrawable(@DrawableRes int resourceId) 58 | withNoDrawable() 59 | withAttrRes(@AttrRes int attr, @ColorRes int colorRes) 60 | withAttr(@AttrRes int attr, @ColorInt int color) 61 | withAttr(@AttrRes int attr, String color) 62 | withColorAccentRes(@ColorRes int colorRes) 63 | withColorAccent(@ColorInt int color) 64 | withColorAccent(String color) 65 | withColorButtonNormalRes(@ColorRes int colorRes) 66 | withColorButtonNormal(@ColorInt int color) 67 | withColorButtonNormal(String color) 68 | withHintTextColorRes(@ColorRes int colorRes) 69 | withHintTextColor(@ColorInt int color) 70 | withHintTextColor(String color) 71 | withCurrentItem(int currentItem) 72 | withTextColorRes(@ColorRes int colorRes) 73 | withTextColor(@ColorInt int color) 74 | withTextColor(String color) 75 | ``` 76 | 77 | There's more documentation available in the Javadoc. Also have a look at the [tests](espresso-core-utils/src/androidTest/java/com/vanniktech/espresso/core/utils) for further usages. 78 | 79 | # License 80 | 81 | Copyright (C) 2017 Vanniktech - Niklas Baudy 82 | 83 | Licensed under the Apache License, Version 2.0 84 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext.deps = [ 3 | 'support': [ 4 | 'annotations': 'androidx.annotation:annotation:1.9.1', 5 | 'appCompat': 'androidx.appcompat:appcompat:1.7.0', 6 | 7 | 'test': [ 8 | 'espresso': [ 9 | 'core': "androidx.test.espresso:espresso-core:3.5.1", 10 | ], 11 | 'junitExt': "androidx.test.ext:junit:1.2.1", 12 | 'runner': "androidx.test:runner:1.6.2", 13 | 'rules': "androidx.test:rules:1.6.1", 14 | ], 15 | ], 16 | 'test': [ 17 | 'junit': 'junit:junit:4.13.2', 18 | ], 19 | ] 20 | 21 | repositories { 22 | mavenCentral() 23 | google() 24 | gradlePluginPortal() 25 | } 26 | 27 | dependencies { 28 | classpath 'com.vanniktech:gradle-code-quality-tools-plugin:0.24.0' 29 | 30 | classpath 'com.android.tools.build:gradle:8.10.0' 31 | classpath 'com.vanniktech:gradle-maven-publish-plugin:0.32.0' 32 | classpath 'app.cash.licensee:licensee-gradle-plugin:1.13.0' 33 | } 34 | } 35 | 36 | apply plugin: 'com.vanniktech.code.quality.tools' 37 | 38 | codeQualityTools { 39 | lint { 40 | textReport = true 41 | } 42 | checkstyle { 43 | enabled = false 44 | } 45 | pmd { 46 | enabled = false 47 | } 48 | cpd { 49 | enabled = false 50 | } 51 | } 52 | 53 | subprojects { 54 | repositories { 55 | mavenCentral() 56 | google() 57 | } 58 | } 59 | 60 | ext { 61 | minSdkVersion = 21 62 | compileSdkVersion = 33 63 | targetSdkVersion = 33 64 | } 65 | -------------------------------------------------------------------------------- /espresso-core-utils/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /espresso-core-utils/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("app.cash.licensee") 3 | id("com.android.library") 4 | } 5 | 6 | licensee { 7 | allow("Apache-2.0") 8 | allow("EPL-1.0") 9 | allow("BSD-2-Clause") 10 | } 11 | 12 | android { 13 | namespace "com.vanniktech.espresso.core.utils" 14 | 15 | compileSdk rootProject.ext.compileSdkVersion as int 16 | 17 | defaultConfig { 18 | minSdk rootProject.ext.minSdkVersion as int 19 | targetSdk rootProject.ext.targetSdkVersion // Needed for Integration Tests. 20 | 21 | testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' 22 | } 23 | 24 | compileOptions { 25 | sourceCompatibility = JavaVersion.VERSION_11 26 | targetCompatibility = JavaVersion.VERSION_11 27 | } 28 | } 29 | 30 | dependencies { 31 | api deps.support.annotations 32 | api deps.support.test.espresso.core 33 | implementation deps.support.appCompat 34 | } 35 | 36 | dependencies { 37 | testImplementation deps.test.junit 38 | } 39 | 40 | dependencies { 41 | androidTestImplementation deps.support.test.junitExt 42 | androidTestImplementation deps.support.test.runner 43 | androidTestImplementation deps.support.test.rules 44 | } 45 | 46 | apply plugin: "com.vanniktech.maven.publish" 47 | -------------------------------------------------------------------------------- /espresso-core-utils/gradle.properties: -------------------------------------------------------------------------------- 1 | POM_NAME=Espresso Core Utils 2 | POM_ARTIFACT_ID=espresso-core-utils 3 | POM_PACKAGING=aar -------------------------------------------------------------------------------- /espresso-core-utils/lint.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /espresso-core-utils/src/androidTest/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /espresso-core-utils/src/androidTest/java/com/vanniktech/espresso/core/utils/AppendTextActionActivity.java: -------------------------------------------------------------------------------- 1 | package com.vanniktech.espresso.core.utils; 2 | 3 | import android.app.Activity; 4 | import android.os.Bundle; 5 | import androidx.annotation.Nullable; 6 | import android.widget.TextView; 7 | 8 | public final class AppendTextActionActivity extends Activity { 9 | static final int VIEW_ID = 1234; 10 | 11 | @Override protected void onCreate(@Nullable final Bundle savedInstanceState) { 12 | super.onCreate(savedInstanceState); 13 | 14 | final TextView textView = new TextView(this); 15 | //noinspection ResourceType 16 | textView.setId(VIEW_ID); 17 | //noinspection AndroidLintSetTextI18n 18 | textView.setText("Test"); 19 | setContentView(textView); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /espresso-core-utils/src/androidTest/java/com/vanniktech/espresso/core/utils/AppendTextActionTest.java: -------------------------------------------------------------------------------- 1 | package com.vanniktech.espresso.core.utils; 2 | 3 | import androidx.test.ext.junit.runners.AndroidJUnit4; 4 | import androidx.test.rule.ActivityTestRule; 5 | import org.junit.Rule; 6 | import org.junit.Test; 7 | import org.junit.runner.RunWith; 8 | 9 | import static androidx.test.espresso.Espresso.onView; 10 | import static androidx.test.espresso.assertion.ViewAssertions.matches; 11 | import static androidx.test.espresso.matcher.ViewMatchers.withId; 12 | import static androidx.test.espresso.matcher.ViewMatchers.withText; 13 | import static com.vanniktech.espresso.core.utils.AppendTextAction.appendText; 14 | import static com.vanniktech.espresso.core.utils.ProgressBarActivity.VIEW_ID; 15 | 16 | @RunWith(AndroidJUnit4.class) public final class AppendTextActionTest { 17 | @Rule public final ActivityTestRule activityTestRule = new ActivityTestRule<>(AppendTextActionActivity.class); 18 | 19 | @Test public void appendingText() { 20 | onView(withId(VIEW_ID)).check(matches(withText("Test"))); 21 | onView(withId(VIEW_ID)).perform(appendText("Something")); 22 | onView(withId(VIEW_ID)).check(matches(withText("TestSomething"))); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /espresso-core-utils/src/androidTest/java/com/vanniktech/espresso/core/utils/AttributeMatcherActivity.java: -------------------------------------------------------------------------------- 1 | package com.vanniktech.espresso.core.utils; 2 | 3 | import android.os.Bundle; 4 | import android.widget.TextView; 5 | import androidx.annotation.Nullable; 6 | import androidx.appcompat.app.AppCompatActivity; 7 | 8 | public final class AttributeMatcherActivity extends AppCompatActivity { 9 | static final int VIEW_ID = 1234; 10 | 11 | @Override protected void onCreate(@Nullable final Bundle savedInstanceState) { 12 | super.onCreate(savedInstanceState); 13 | 14 | final TextView textView = new TextView(this); 15 | //noinspection ResourceType 16 | textView.setId(VIEW_ID); 17 | setContentView(textView); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /espresso-core-utils/src/androidTest/java/com/vanniktech/espresso/core/utils/AttributeMatcherTest.java: -------------------------------------------------------------------------------- 1 | package com.vanniktech.espresso.core.utils; 2 | 3 | import androidx.test.ext.junit.runners.AndroidJUnit4; 4 | import androidx.test.rule.ActivityTestRule; 5 | import com.vanniktech.espresso.core.utils.test.R; 6 | import junit.framework.AssertionFailedError; 7 | import org.junit.Rule; 8 | import org.junit.Test; 9 | import org.junit.rules.ExpectedException; 10 | import org.junit.runner.RunWith; 11 | 12 | import static android.graphics.Color.BLUE; 13 | import static android.graphics.Color.GREEN; 14 | import static android.graphics.Color.RED; 15 | import static androidx.test.espresso.Espresso.onView; 16 | import static androidx.test.espresso.assertion.ViewAssertions.matches; 17 | import static androidx.test.espresso.matcher.ViewMatchers.withId; 18 | import static com.vanniktech.espresso.core.utils.AttributeMatcher.withAttr; 19 | import static com.vanniktech.espresso.core.utils.AttributeMatcher.withAttrRes; 20 | import static com.vanniktech.espresso.core.utils.AttributeMatcher.withColorAccent; 21 | import static com.vanniktech.espresso.core.utils.AttributeMatcher.withColorAccentRes; 22 | import static com.vanniktech.espresso.core.utils.AttributeMatcher.withColorButtonNormal; 23 | import static com.vanniktech.espresso.core.utils.AttributeMatcher.withColorButtonNormalRes; 24 | import static com.vanniktech.espresso.core.utils.AttributeMatcherActivity.VIEW_ID; 25 | 26 | @RunWith(AndroidJUnit4.class) public final class AttributeMatcherTest { 27 | @Rule public final ExpectedException expectedException = ExpectedException.none(); 28 | 29 | @Rule public final ActivityTestRule activityTestRule = new ActivityTestRule<>(AttributeMatcherActivity.class); 30 | 31 | @Test public void withAttrResMatches() { 32 | onView(withId(VIEW_ID)).check(matches(withAttrRes(R.attr.colorError, R.color.blue))); 33 | } 34 | 35 | @Test public void withAttrMatches() { 36 | onView(withId(VIEW_ID)).check(matches(withAttr(R.attr.colorError, BLUE))); 37 | } 38 | 39 | @Test public void withAttrStringMatches() { 40 | onView(withId(VIEW_ID)).check(matches(withAttr(R.attr.colorError, "#0000ff"))); 41 | } 42 | 43 | @Test public void withAttrResDoesNotMatch() { 44 | expectedException.expect(AssertionFailedError.class); 45 | expectedException.expectMessage("'with " + R.attr.colorError + ": ' doesn't match the selected view."); 46 | onView(withId(VIEW_ID)).check(matches(withAttrRes(R.attr.colorError, R.color.red))); 47 | } 48 | 49 | @Test public void withAttrDoesNotMatch() { 50 | expectedException.expect(AssertionFailedError.class); 51 | expectedException.expectMessage("'with " + R.attr.colorError + ": ' doesn't match the selected view."); 52 | onView(withId(VIEW_ID)).check(matches(withAttr(R.attr.colorError, RED))); 53 | } 54 | 55 | @Test public void withAttrStringDoesNotMatch() { 56 | expectedException.expect(AssertionFailedError.class); 57 | expectedException.expectMessage("'with " + R.attr.colorError + ": ' doesn't match the selected view."); 58 | onView(withId(VIEW_ID)).check(matches(withAttr(R.attr.colorError, "#ff0000"))); 59 | } 60 | 61 | @Test public void withColorButtonNormalResMatches() { 62 | onView(withId(VIEW_ID)).check(matches(withColorButtonNormalRes(R.color.red))); 63 | } 64 | 65 | @Test public void withColorButtonNormalMatches() { 66 | onView(withId(VIEW_ID)).check(matches(withColorButtonNormal(RED))); 67 | } 68 | 69 | @Test public void withColorButtonNormalStringMatches() { 70 | onView(withId(VIEW_ID)).check(matches(withColorButtonNormal("#ff0000"))); 71 | } 72 | 73 | @Test public void withColorButtonNormalResDoesNotMatch() { 74 | expectedException.expect(AssertionFailedError.class); 75 | expectedException.expectMessage("'with colorButtonNormal: ' doesn't match the selected view."); 76 | onView(withId(VIEW_ID)).check(matches(withColorButtonNormalRes(R.color.green))); 77 | } 78 | 79 | @Test public void withColorButtonNormalDoesNotMatch() { 80 | expectedException.expect(AssertionFailedError.class); 81 | expectedException.expectMessage("'with colorButtonNormal: ' doesn't match the selected view."); 82 | onView(withId(VIEW_ID)).check(matches(withColorButtonNormal(GREEN))); 83 | } 84 | 85 | @Test public void withColorButtonNormalStringDoesNotMatch() { 86 | expectedException.expect(AssertionFailedError.class); 87 | expectedException.expectMessage("'with colorButtonNormal: ' doesn't match the selected view."); 88 | onView(withId(VIEW_ID)).check(matches(withColorButtonNormal("#00ff00"))); 89 | } 90 | 91 | @Test public void withColorAccentResMatches() { 92 | onView(withId(VIEW_ID)).check(matches(withColorAccentRes(R.color.green))); 93 | } 94 | 95 | @Test public void withColorAccentMatches() { 96 | onView(withId(VIEW_ID)).check(matches(withColorAccent(GREEN))); 97 | } 98 | 99 | @Test public void withColorAccentStringMatches() { 100 | onView(withId(VIEW_ID)).check(matches(withColorAccent("#00ff00"))); 101 | } 102 | 103 | @Test public void withColorAccentResDoesNotMatch() { 104 | expectedException.expect(AssertionFailedError.class); 105 | expectedException.expectMessage("'with colorAccent: ' doesn't match the selected view."); 106 | onView(withId(VIEW_ID)).check(matches(withColorAccentRes(R.color.red))); 107 | } 108 | 109 | @Test public void withColorAccentDoesNotMatch() { 110 | expectedException.expect(AssertionFailedError.class); 111 | expectedException.expectMessage("'with colorAccent: ' doesn't match the selected view."); 112 | onView(withId(VIEW_ID)).check(matches(withColorAccent(RED))); 113 | } 114 | 115 | @Test public void withColorAccentStringDoesNotMatch() { 116 | expectedException.expect(AssertionFailedError.class); 117 | expectedException.expectMessage("'with colorAccent: ' doesn't match the selected view."); 118 | onView(withId(VIEW_ID)).check(matches(withColorAccent("#ff0000"))); 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /espresso-core-utils/src/androidTest/java/com/vanniktech/espresso/core/utils/CurrentItemMatcherActivity.java: -------------------------------------------------------------------------------- 1 | package com.vanniktech.espresso.core.utils; 2 | 3 | import android.app.Activity; 4 | import android.os.Bundle; 5 | import androidx.annotation.Nullable; 6 | import androidx.viewpager.widget.ViewPager; 7 | 8 | public final class CurrentItemMatcherActivity extends Activity { 9 | static final int VIEW_ID = 1234; 10 | 11 | @Override protected void onCreate(@Nullable final Bundle savedInstanceState) { 12 | super.onCreate(savedInstanceState); 13 | 14 | final ViewPager viewPager = new ViewPager(this); 15 | //noinspection ResourceType 16 | viewPager.setId(VIEW_ID); 17 | viewPager.setCurrentItem(0); 18 | setContentView(viewPager); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /espresso-core-utils/src/androidTest/java/com/vanniktech/espresso/core/utils/CurrentItemMatcherTest.java: -------------------------------------------------------------------------------- 1 | package com.vanniktech.espresso.core.utils; 2 | 3 | import androidx.test.ext.junit.runners.AndroidJUnit4; 4 | import androidx.test.rule.ActivityTestRule; 5 | import junit.framework.AssertionFailedError; 6 | import org.junit.Rule; 7 | import org.junit.Test; 8 | import org.junit.rules.ExpectedException; 9 | import org.junit.runner.RunWith; 10 | 11 | import static androidx.test.espresso.Espresso.onView; 12 | import static androidx.test.espresso.assertion.ViewAssertions.matches; 13 | import static androidx.test.espresso.matcher.ViewMatchers.withId; 14 | import static com.vanniktech.espresso.core.utils.CurrentItemMatcher.withCurrentItem; 15 | import static com.vanniktech.espresso.core.utils.TextColorMatcherActivity.VIEW_ID; 16 | 17 | @RunWith(AndroidJUnit4.class) public final class CurrentItemMatcherTest { 18 | @Rule public final ExpectedException expectedException = ExpectedException.none(); 19 | 20 | @Rule public final ActivityTestRule activityTestRule = new ActivityTestRule<>(CurrentItemMatcherActivity.class); 21 | 22 | @Test public void withCurrentItemMatches() { 23 | onView(withId(VIEW_ID)).check(matches(withCurrentItem(0))); 24 | } 25 | 26 | @Test public void withCurrentItemDoesNotMatch() { 27 | expectedException.expect(AssertionFailedError.class); 28 | expectedException.expectMessage("'has currentItem: <1>' doesn't match the selected view."); 29 | onView(withId(VIEW_ID)).check(matches(withCurrentItem(1))); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /espresso-core-utils/src/androidTest/java/com/vanniktech/espresso/core/utils/DrawableMatcherActivity.java: -------------------------------------------------------------------------------- 1 | package com.vanniktech.espresso.core.utils; 2 | 3 | import android.app.Activity; 4 | import android.os.Bundle; 5 | import androidx.annotation.Nullable; 6 | import android.widget.ImageView; 7 | 8 | public final class DrawableMatcherActivity extends Activity { 9 | static final int VIEW_ID = 1234; 10 | 11 | ImageView imageView; 12 | 13 | @Override protected void onCreate(@Nullable final Bundle savedInstanceState) { 14 | super.onCreate(savedInstanceState); 15 | 16 | imageView = new ImageView(this); 17 | //noinspection ResourceType 18 | imageView.setId(VIEW_ID); 19 | setContentView(imageView); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /espresso-core-utils/src/androidTest/java/com/vanniktech/espresso/core/utils/DrawableMatcherTest.java: -------------------------------------------------------------------------------- 1 | package com.vanniktech.espresso.core.utils; 2 | 3 | import androidx.annotation.DrawableRes; 4 | import androidx.test.ext.junit.runners.AndroidJUnit4; 5 | import androidx.test.rule.ActivityTestRule; 6 | import com.vanniktech.espresso.core.utils.test.R; 7 | import junit.framework.AssertionFailedError; 8 | import org.junit.Rule; 9 | import org.junit.Test; 10 | import org.junit.rules.ExpectedException; 11 | import org.junit.runner.RunWith; 12 | 13 | import static android.view.View.GONE; 14 | import static androidx.test.espresso.Espresso.onView; 15 | import static androidx.test.espresso.assertion.ViewAssertions.matches; 16 | import static androidx.test.espresso.matcher.ViewMatchers.withId; 17 | import static com.vanniktech.espresso.core.utils.DrawableMatcher.withDrawable; 18 | import static com.vanniktech.espresso.core.utils.DrawableMatcher.withNoDrawable; 19 | import static com.vanniktech.espresso.core.utils.DrawableMatcherActivity.VIEW_ID; 20 | 21 | @RunWith(AndroidJUnit4.class) public final class DrawableMatcherTest { 22 | @Rule public final ExpectedException expectedException = ExpectedException.none(); 23 | 24 | @Rule public final ActivityTestRule activityTestRule = new ActivityTestRule<>(DrawableMatcherActivity.class); 25 | 26 | @Test public void withNoDrawableMatches() { 27 | onView(withId(VIEW_ID)).check(matches(withNoDrawable())); 28 | } 29 | 30 | @Test public void withDrawableMatches() throws Throwable { 31 | setDrawable(R.drawable.android); 32 | 33 | onView(withId(VIEW_ID)).check(matches(withDrawable(R.drawable.android))); 34 | } 35 | 36 | @Test public void withNoDrawableDoesNotMatchOnGone() throws Throwable { 37 | setVisibility(GONE); 38 | 39 | expectedException.expect(AssertionFailedError.class); 40 | expectedException.expectMessage("'with no drawable' doesn't match the selected view."); 41 | onView(withId(VIEW_ID)).check(matches(withNoDrawable())); 42 | } 43 | 44 | @Test public void withDrawableDoesNotMatchOnGone() throws Throwable { 45 | setDrawable(R.drawable.android); 46 | setVisibility(GONE); 47 | 48 | expectedException.expect(AssertionFailedError.class); 49 | expectedException.expectMessage("'with drawable from resource id: <" + R.drawable.android + ">' doesn't match the selected view."); 50 | onView(withId(VIEW_ID)).check(matches(withDrawable(R.drawable.android))); 51 | } 52 | 53 | @Test public void withNoDrawableDoesNotMatch() throws Throwable { 54 | setDrawable(R.drawable.android); 55 | 56 | expectedException.expect(AssertionFailedError.class); 57 | expectedException.expectMessage("'with no drawable' doesn't match the selected view."); 58 | onView(withId(VIEW_ID)).check(matches(withNoDrawable())); 59 | } 60 | 61 | @Test public void withDrawableDoesNotMatch() throws Throwable { 62 | setDrawable(R.drawable.android); 63 | 64 | expectedException.expect(AssertionFailedError.class); 65 | expectedException.expectMessage("'with drawable from resource id: <" + R.drawable.northern_lights + ">' doesn't match the selected view."); 66 | onView(withId(VIEW_ID)).check(matches(withDrawable(R.drawable.northern_lights))); 67 | } 68 | 69 | private void setDrawable(@DrawableRes final int drawable) throws Throwable { 70 | activityTestRule.runOnUiThread(new Runnable() { 71 | @Override public void run() { 72 | activityTestRule.getActivity().imageView.setImageResource(drawable); 73 | } 74 | }); 75 | } 76 | 77 | void setVisibility(final int visibility) throws Throwable { 78 | activityTestRule.runOnUiThread(new Runnable() { 79 | @Override public void run() { 80 | activityTestRule.getActivity().imageView.setVisibility(visibility); 81 | } 82 | }); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /espresso-core-utils/src/androidTest/java/com/vanniktech/espresso/core/utils/HintTextColorMatcherActivity.java: -------------------------------------------------------------------------------- 1 | package com.vanniktech.espresso.core.utils; 2 | 3 | import android.app.Activity; 4 | import android.os.Bundle; 5 | import android.widget.TextView; 6 | import androidx.annotation.Nullable; 7 | import androidx.core.content.ContextCompat; 8 | import com.vanniktech.espresso.core.utils.test.R; 9 | 10 | public final class HintTextColorMatcherActivity extends Activity { 11 | static final int VIEW_ID = 1234; 12 | 13 | @Override protected void onCreate(@Nullable final Bundle savedInstanceState) { 14 | super.onCreate(savedInstanceState); 15 | 16 | final TextView textView = new TextView(this); 17 | //noinspection ResourceType 18 | textView.setId(VIEW_ID); 19 | textView.setHintTextColor(ContextCompat.getColor(this, R.color.red)); 20 | setContentView(textView); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /espresso-core-utils/src/androidTest/java/com/vanniktech/espresso/core/utils/HintTextColorMatcherTest.java: -------------------------------------------------------------------------------- 1 | package com.vanniktech.espresso.core.utils; 2 | 3 | import androidx.test.ext.junit.runners.AndroidJUnit4; 4 | import androidx.test.rule.ActivityTestRule; 5 | import com.vanniktech.espresso.core.utils.test.R; 6 | import junit.framework.AssertionFailedError; 7 | import org.junit.Rule; 8 | import org.junit.Test; 9 | import org.junit.rules.ExpectedException; 10 | import org.junit.runner.RunWith; 11 | 12 | import static android.graphics.Color.GREEN; 13 | import static android.graphics.Color.RED; 14 | import static androidx.test.espresso.Espresso.onView; 15 | import static androidx.test.espresso.assertion.ViewAssertions.matches; 16 | import static androidx.test.espresso.matcher.ViewMatchers.withId; 17 | import static com.vanniktech.espresso.core.utils.HintTextColorMatcher.withHintTextColor; 18 | import static com.vanniktech.espresso.core.utils.HintTextColorMatcher.withHintTextColorRes; 19 | import static com.vanniktech.espresso.core.utils.HintTextColorMatcherActivity.VIEW_ID; 20 | 21 | @RunWith(AndroidJUnit4.class) public final class HintTextColorMatcherTest { 22 | @Rule public final ExpectedException expectedException = ExpectedException.none(); 23 | 24 | @Rule public final ActivityTestRule activityTestRule = new ActivityTestRule<>(HintTextColorMatcherActivity.class); 25 | 26 | @Test public void withHintTextColorResMatches() { 27 | onView(withId(VIEW_ID)).check(matches(withHintTextColorRes(R.color.red))); 28 | } 29 | 30 | @Test public void withHintTextColorMatches() { 31 | onView(withId(VIEW_ID)).check(matches(withHintTextColor(RED))); 32 | } 33 | 34 | @Test public void withHintTextColorStringMatches() { 35 | onView(withId(VIEW_ID)).check(matches(withHintTextColor("#ff0000"))); 36 | } 37 | 38 | @Test public void withHintTextColorResDoesNotMatch() { 39 | expectedException.expect(AssertionFailedError.class); 40 | expectedException.expectMessage("'with hint text color: ' doesn't match the selected view."); 41 | onView(withId(VIEW_ID)).check(matches(withHintTextColorRes(R.color.green))); 42 | } 43 | 44 | @Test public void withHintTextColorDoesNotMatch() { 45 | expectedException.expect(AssertionFailedError.class); 46 | expectedException.expectMessage("'with hint text color: ' doesn't match the selected view."); 47 | onView(withId(VIEW_ID)).check(matches(withHintTextColor(GREEN))); 48 | } 49 | 50 | @Test public void withHintTextColorStringDoesNotMatch() { 51 | expectedException.expect(AssertionFailedError.class); 52 | expectedException.expectMessage("'with hint text color: ' doesn't match the selected view."); 53 | onView(withId(VIEW_ID)).check(matches(withHintTextColor("#00ff00"))); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /espresso-core-utils/src/androidTest/java/com/vanniktech/espresso/core/utils/ProgressBarActivity.java: -------------------------------------------------------------------------------- 1 | package com.vanniktech.espresso.core.utils; 2 | 3 | import android.app.Activity; 4 | import android.os.Bundle; 5 | import androidx.annotation.Nullable; 6 | import android.widget.ProgressBar; 7 | 8 | public final class ProgressBarActivity extends Activity { 9 | static final int VIEW_ID = 1234; 10 | 11 | @Override protected void onCreate(@Nullable final Bundle savedInstanceState) { 12 | super.onCreate(savedInstanceState); 13 | 14 | final ProgressBar progressBar = new ProgressBar(this, null, 0); // Explicit no defStyleAttr. 15 | //noinspection ResourceType 16 | progressBar.setId(VIEW_ID); 17 | progressBar.setMax(100); 18 | progressBar.setProgress(1); 19 | setContentView(progressBar); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /espresso-core-utils/src/androidTest/java/com/vanniktech/espresso/core/utils/ProgressMatcherTest.java: -------------------------------------------------------------------------------- 1 | package com.vanniktech.espresso.core.utils; 2 | 3 | import androidx.test.ext.junit.runners.AndroidJUnit4; 4 | import androidx.test.rule.ActivityTestRule; 5 | import junit.framework.AssertionFailedError; 6 | import org.junit.Rule; 7 | import org.junit.Test; 8 | import org.junit.rules.ExpectedException; 9 | import org.junit.runner.RunWith; 10 | 11 | import static androidx.test.espresso.Espresso.onView; 12 | import static androidx.test.espresso.assertion.ViewAssertions.matches; 13 | import static androidx.test.espresso.matcher.ViewMatchers.withId; 14 | import static com.vanniktech.espresso.core.utils.ProgressBarActivity.VIEW_ID; 15 | import static com.vanniktech.espresso.core.utils.ProgressMatcher.withProgress; 16 | 17 | @RunWith(AndroidJUnit4.class) public final class ProgressMatcherTest { 18 | @Rule public final ExpectedException expectedException = ExpectedException.none(); 19 | 20 | @Rule public final ActivityTestRule activityTestRule = new ActivityTestRule<>(ProgressBarActivity.class); 21 | 22 | @Test public void withProgressMatches() { 23 | onView(withId(VIEW_ID)).check(matches(withProgress(1))); 24 | } 25 | 26 | @Test public void withProgressDoesNotMatch() { 27 | expectedException.expect(AssertionFailedError.class); 28 | expectedException.expectMessage("'has progress: <2>' doesn't match the selected view."); 29 | onView(withId(VIEW_ID)).check(matches(withProgress(2))); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /espresso-core-utils/src/androidTest/java/com/vanniktech/espresso/core/utils/SetProgressActionTest.java: -------------------------------------------------------------------------------- 1 | package com.vanniktech.espresso.core.utils; 2 | 3 | import androidx.test.ext.junit.runners.AndroidJUnit4; 4 | import androidx.test.rule.ActivityTestRule; 5 | import org.junit.Rule; 6 | import org.junit.Test; 7 | import org.junit.runner.RunWith; 8 | 9 | import static androidx.test.espresso.Espresso.onView; 10 | import static androidx.test.espresso.assertion.ViewAssertions.matches; 11 | import static androidx.test.espresso.matcher.ViewMatchers.withId; 12 | import static com.vanniktech.espresso.core.utils.ProgressBarActivity.VIEW_ID; 13 | import static com.vanniktech.espresso.core.utils.ProgressMatcher.withProgress; 14 | import static com.vanniktech.espresso.core.utils.SetProgressAction.setProgress; 15 | 16 | @RunWith(AndroidJUnit4.class) public final class SetProgressActionTest { 17 | @Rule public final ActivityTestRule activityTestRule = new ActivityTestRule<>(ProgressBarActivity.class); 18 | 19 | @Test public void settingProgress() { 20 | onView(withId(VIEW_ID)).check(matches(withProgress(1))); 21 | onView(withId(VIEW_ID)).perform(setProgress(95)); 22 | onView(withId(VIEW_ID)).check(matches(withProgress(95))); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /espresso-core-utils/src/androidTest/java/com/vanniktech/espresso/core/utils/TextColorMatcherActivity.java: -------------------------------------------------------------------------------- 1 | package com.vanniktech.espresso.core.utils; 2 | 3 | import android.app.Activity; 4 | import android.os.Bundle; 5 | import android.widget.TextView; 6 | import androidx.annotation.Nullable; 7 | import androidx.core.content.ContextCompat; 8 | import com.vanniktech.espresso.core.utils.test.R; 9 | 10 | public final class TextColorMatcherActivity extends Activity { 11 | static final int VIEW_ID = 1234; 12 | 13 | @Override protected void onCreate(@Nullable final Bundle savedInstanceState) { 14 | super.onCreate(savedInstanceState); 15 | 16 | final TextView textView = new TextView(this); 17 | //noinspection ResourceType 18 | textView.setId(VIEW_ID); 19 | textView.setTextColor(ContextCompat.getColor(this, R.color.red)); 20 | setContentView(textView); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /espresso-core-utils/src/androidTest/java/com/vanniktech/espresso/core/utils/TextColorMatcherTest.java: -------------------------------------------------------------------------------- 1 | package com.vanniktech.espresso.core.utils; 2 | 3 | import androidx.test.ext.junit.runners.AndroidJUnit4; 4 | import androidx.test.rule.ActivityTestRule; 5 | import com.vanniktech.espresso.core.utils.test.R; 6 | import junit.framework.AssertionFailedError; 7 | import org.junit.Rule; 8 | import org.junit.Test; 9 | import org.junit.rules.ExpectedException; 10 | import org.junit.runner.RunWith; 11 | 12 | import static android.graphics.Color.GREEN; 13 | import static android.graphics.Color.RED; 14 | import static androidx.test.espresso.Espresso.onView; 15 | import static androidx.test.espresso.assertion.ViewAssertions.matches; 16 | import static androidx.test.espresso.matcher.ViewMatchers.withId; 17 | import static com.vanniktech.espresso.core.utils.TextColorMatcher.withTextColor; 18 | import static com.vanniktech.espresso.core.utils.TextColorMatcher.withTextColorRes; 19 | import static com.vanniktech.espresso.core.utils.TextColorMatcherActivity.VIEW_ID; 20 | 21 | @RunWith(AndroidJUnit4.class) public final class TextColorMatcherTest { 22 | @Rule public final ExpectedException expectedException = ExpectedException.none(); 23 | 24 | @Rule public final ActivityTestRule activityTestRule = new ActivityTestRule<>(TextColorMatcherActivity.class); 25 | 26 | @Test public void withTextColorResMatches() { 27 | onView(withId(VIEW_ID)).check(matches(withTextColorRes(R.color.red))); 28 | } 29 | 30 | @Test public void withTextColorMatches() { 31 | onView(withId(VIEW_ID)).check(matches(withTextColor(RED))); 32 | } 33 | 34 | @Test public void withTextColorStringMatches() { 35 | onView(withId(VIEW_ID)).check(matches(withTextColor("#ff0000"))); 36 | } 37 | 38 | @Test public void withTextColorResDoesNotMatch() { 39 | expectedException.expect(AssertionFailedError.class); 40 | expectedException.expectMessage("'with text color: ' doesn't match the selected view."); 41 | onView(withId(VIEW_ID)).check(matches(withTextColorRes(R.color.green))); 42 | } 43 | 44 | @Test public void withTextColorDoesNotMatch() { 45 | expectedException.expect(AssertionFailedError.class); 46 | expectedException.expectMessage("'with text color: ' doesn't match the selected view."); 47 | onView(withId(VIEW_ID)).check(matches(withTextColor(GREEN))); 48 | } 49 | 50 | @Test public void withTextColorStringDoesNotMatch() { 51 | expectedException.expect(AssertionFailedError.class); 52 | expectedException.expectMessage("'with text color: ' doesn't match the selected view."); 53 | onView(withId(VIEW_ID)).check(matches(withTextColor("#00ff00"))); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /espresso-core-utils/src/androidTest/java/com/vanniktech/espresso/core/utils/TextViewDrawableMatcherActivity.java: -------------------------------------------------------------------------------- 1 | package com.vanniktech.espresso.core.utils; 2 | 3 | import android.app.Activity; 4 | import android.os.Bundle; 5 | import androidx.annotation.Nullable; 6 | import android.widget.TextView; 7 | 8 | public final class TextViewDrawableMatcherActivity extends Activity { 9 | static final int VIEW_ID = 1234; 10 | 11 | TextView textView; 12 | 13 | @Override protected void onCreate(@Nullable final Bundle savedInstanceState) { 14 | super.onCreate(savedInstanceState); 15 | 16 | textView = new TextView(this); 17 | //noinspection ResourceType 18 | textView.setId(VIEW_ID); 19 | setContentView(textView); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /espresso-core-utils/src/androidTest/java/com/vanniktech/espresso/core/utils/TextViewDrawableMatcherTest.java: -------------------------------------------------------------------------------- 1 | package com.vanniktech.espresso.core.utils; 2 | 3 | import androidx.annotation.DrawableRes; 4 | import androidx.test.ext.junit.runners.AndroidJUnit4; 5 | import androidx.test.rule.ActivityTestRule; 6 | import com.vanniktech.espresso.core.utils.test.R; 7 | import junit.framework.AssertionFailedError; 8 | import org.junit.Rule; 9 | import org.junit.Test; 10 | import org.junit.rules.ExpectedException; 11 | import org.junit.runner.RunWith; 12 | 13 | import static androidx.test.espresso.Espresso.onView; 14 | import static androidx.test.espresso.assertion.ViewAssertions.matches; 15 | import static androidx.test.espresso.matcher.ViewMatchers.withId; 16 | import static com.vanniktech.espresso.core.utils.DrawableMatcherActivity.VIEW_ID; 17 | import static com.vanniktech.espresso.core.utils.TextViewDrawableMatcher.withNoTextViewDrawableBottom; 18 | import static com.vanniktech.espresso.core.utils.TextViewDrawableMatcher.withNoTextViewDrawableLeft; 19 | import static com.vanniktech.espresso.core.utils.TextViewDrawableMatcher.withNoTextViewDrawableRelativeBottom; 20 | import static com.vanniktech.espresso.core.utils.TextViewDrawableMatcher.withNoTextViewDrawableRelativeLeft; 21 | import static com.vanniktech.espresso.core.utils.TextViewDrawableMatcher.withNoTextViewDrawableRelativeRight; 22 | import static com.vanniktech.espresso.core.utils.TextViewDrawableMatcher.withNoTextViewDrawableRelativeTop; 23 | import static com.vanniktech.espresso.core.utils.TextViewDrawableMatcher.withNoTextViewDrawableRight; 24 | import static com.vanniktech.espresso.core.utils.TextViewDrawableMatcher.withNoTextViewDrawableTop; 25 | import static com.vanniktech.espresso.core.utils.TextViewDrawableMatcher.withTextViewDrawableBottom; 26 | import static com.vanniktech.espresso.core.utils.TextViewDrawableMatcher.withTextViewDrawableLeft; 27 | import static com.vanniktech.espresso.core.utils.TextViewDrawableMatcher.withTextViewDrawableRelativeBottom; 28 | import static com.vanniktech.espresso.core.utils.TextViewDrawableMatcher.withTextViewDrawableRelativeLeft; 29 | import static com.vanniktech.espresso.core.utils.TextViewDrawableMatcher.withTextViewDrawableRelativeRight; 30 | import static com.vanniktech.espresso.core.utils.TextViewDrawableMatcher.withTextViewDrawableRelativeTop; 31 | import static com.vanniktech.espresso.core.utils.TextViewDrawableMatcher.withTextViewDrawableRight; 32 | import static com.vanniktech.espresso.core.utils.TextViewDrawableMatcher.withTextViewDrawableTop; 33 | 34 | @RunWith(AndroidJUnit4.class) public final class TextViewDrawableMatcherTest { 35 | @Rule public final ExpectedException expectedException = ExpectedException.none(); 36 | 37 | @Rule public final ActivityTestRule activityTestRule = new ActivityTestRule<>(TextViewDrawableMatcherActivity.class); 38 | 39 | @Test public void withTextViewDrawableLeftMatches() throws Throwable { 40 | setDrawableLeft(R.drawable.android); 41 | 42 | onView(withId(VIEW_ID)).check(matches(withTextViewDrawableLeft(R.drawable.android))); 43 | } 44 | 45 | @Test public void withTextViewDrawableLeftDoesNotMatch() throws Throwable { 46 | setDrawableLeft(R.drawable.android); 47 | 48 | expectedException.expect(AssertionFailedError.class); 49 | expectedException.expectMessage("'with left drawable from resource id: <" + R.drawable.northern_lights + ">' doesn't match the selected view."); 50 | onView(withId(VIEW_ID)).check(matches(withTextViewDrawableLeft(R.drawable.northern_lights))); 51 | } 52 | 53 | @Test public void withNoTextViewDrawableLeftMatches() { 54 | onView(withId(VIEW_ID)).check(matches(withNoTextViewDrawableLeft())); 55 | } 56 | 57 | @Test public void withNoTextViewDrawableLeftDoesNotMatch() throws Throwable { 58 | setDrawableLeft(R.drawable.android); 59 | 60 | expectedException.expect(AssertionFailedError.class); 61 | expectedException.expectMessage("'with no left drawable' doesn't match the selected view."); 62 | onView(withId(VIEW_ID)).check(matches(withNoTextViewDrawableLeft())); 63 | } 64 | 65 | @Test public void withTextViewDrawableRelativeLeftMatches() throws Throwable { 66 | setDrawableRelativeLeft(R.drawable.android); 67 | 68 | onView(withId(VIEW_ID)).check(matches(withTextViewDrawableRelativeLeft(R.drawable.android))); 69 | } 70 | 71 | @Test public void withTextViewDrawableRelativeLeftDoesNotMatch() throws Throwable { 72 | setDrawableRelativeLeft(R.drawable.android); 73 | 74 | expectedException.expect(AssertionFailedError.class); 75 | expectedException.expectMessage("'with relative left drawable from resource id: <" + R.drawable.northern_lights + ">' doesn't match the selected view."); 76 | onView(withId(VIEW_ID)).check(matches(withTextViewDrawableRelativeLeft(R.drawable.northern_lights))); 77 | } 78 | 79 | @Test public void withNoTextViewDrawableRelativeLeftMatches() { 80 | onView(withId(VIEW_ID)).check(matches(withNoTextViewDrawableRelativeLeft())); 81 | } 82 | 83 | @Test public void withNoTextViewDrawableRelativeLeftDoesNotMatch() throws Throwable { 84 | setDrawableRelativeLeft(R.drawable.android); 85 | 86 | expectedException.expect(AssertionFailedError.class); 87 | expectedException.expectMessage("'with no relative left drawable' doesn't match the selected view."); 88 | onView(withId(VIEW_ID)).check(matches(withNoTextViewDrawableRelativeLeft())); 89 | } 90 | 91 | @Test public void withTextViewDrawableTopMatches() throws Throwable { 92 | setDrawableTop(R.drawable.android); 93 | 94 | onView(withId(VIEW_ID)).check(matches(withTextViewDrawableTop(R.drawable.android))); 95 | } 96 | 97 | @Test public void withTextViewDrawableTopDoesNotMatch() throws Throwable { 98 | setDrawableTop(R.drawable.android); 99 | 100 | expectedException.expect(AssertionFailedError.class); 101 | expectedException.expectMessage("'with top drawable from resource id: <" + R.drawable.northern_lights + ">' doesn't match the selected view."); 102 | onView(withId(VIEW_ID)).check(matches(withTextViewDrawableTop(R.drawable.northern_lights))); 103 | } 104 | 105 | @Test public void withNoTextViewDrawableTopMatches() { 106 | onView(withId(VIEW_ID)).check(matches(withNoTextViewDrawableTop())); 107 | } 108 | 109 | @Test public void withNoTextViewDrawableTopDoesNotMatch() throws Throwable { 110 | setDrawableTop(R.drawable.android); 111 | 112 | expectedException.expect(AssertionFailedError.class); 113 | expectedException.expectMessage("'with no top drawable' doesn't match the selected view."); 114 | onView(withId(VIEW_ID)).check(matches(withNoTextViewDrawableTop())); 115 | } 116 | 117 | @Test public void withTextViewDrawableRelativeTopMatches() throws Throwable { 118 | setDrawableRelativeTop(R.drawable.android); 119 | 120 | onView(withId(VIEW_ID)).check(matches(withTextViewDrawableRelativeTop(R.drawable.android))); 121 | } 122 | 123 | @Test public void withTextViewDrawableRelativeTopDoesNotMatch() throws Throwable { 124 | setDrawableRelativeTop(R.drawable.android); 125 | 126 | expectedException.expect(AssertionFailedError.class); 127 | expectedException.expectMessage("'with relative top drawable from resource id: <" + R.drawable.northern_lights + ">' doesn't match the selected view."); 128 | onView(withId(VIEW_ID)).check(matches(withTextViewDrawableRelativeTop(R.drawable.northern_lights))); 129 | } 130 | 131 | @Test public void withNoTextViewDrawableRelativeTopMatches() { 132 | onView(withId(VIEW_ID)).check(matches(withNoTextViewDrawableRelativeTop())); 133 | } 134 | 135 | @Test public void withNoTextViewDrawableRelativeTopDoesNotMatch() throws Throwable { 136 | setDrawableRelativeTop(R.drawable.android); 137 | 138 | expectedException.expect(AssertionFailedError.class); 139 | expectedException.expectMessage("'with no relative top drawable' doesn't match the selected view."); 140 | onView(withId(VIEW_ID)).check(matches(withNoTextViewDrawableRelativeTop())); 141 | } 142 | 143 | @Test public void withTextViewDrawableRightMatches() throws Throwable { 144 | setDrawableRight(R.drawable.android); 145 | 146 | onView(withId(VIEW_ID)).check(matches(withTextViewDrawableRight(R.drawable.android))); 147 | } 148 | 149 | @Test public void withTextViewDrawableRightDoesNotMatch() throws Throwable { 150 | setDrawableRight(R.drawable.android); 151 | 152 | expectedException.expect(AssertionFailedError.class); 153 | expectedException.expectMessage("'with right drawable from resource id: <" + R.drawable.northern_lights + ">' doesn't match the selected view."); 154 | onView(withId(VIEW_ID)).check(matches(withTextViewDrawableRight(R.drawable.northern_lights))); 155 | } 156 | 157 | @Test public void withNoTextViewDrawableRightMatches() { 158 | onView(withId(VIEW_ID)).check(matches(withNoTextViewDrawableRight())); 159 | } 160 | 161 | @Test public void withNoTextViewDrawableRightDoesNotMatch() throws Throwable { 162 | setDrawableRight(R.drawable.android); 163 | 164 | expectedException.expect(AssertionFailedError.class); 165 | expectedException.expectMessage("'with no right drawable' doesn't match the selected view."); 166 | onView(withId(VIEW_ID)).check(matches(withNoTextViewDrawableRight())); 167 | } 168 | 169 | @Test public void withTextViewDrawableRelativeRightMatches() throws Throwable { 170 | setDrawableRelativeRight(R.drawable.android); 171 | 172 | onView(withId(VIEW_ID)).check(matches(withTextViewDrawableRelativeRight(R.drawable.android))); 173 | } 174 | 175 | @Test public void withTextViewDrawableRelativeRightDoesNotMatch() throws Throwable { 176 | setDrawableRelativeRight(R.drawable.android); 177 | 178 | expectedException.expect(AssertionFailedError.class); 179 | expectedException.expectMessage("'with relative right drawable from resource id: <" + R.drawable.northern_lights + ">' doesn't match the selected view."); 180 | onView(withId(VIEW_ID)).check(matches(withTextViewDrawableRelativeRight(R.drawable.northern_lights))); 181 | } 182 | 183 | @Test public void withNoTextViewDrawableRelativeRightMatches() { 184 | onView(withId(VIEW_ID)).check(matches(withNoTextViewDrawableRelativeRight())); 185 | } 186 | 187 | @Test public void withNoTextViewDrawableRelativeRightDoesNotMatch() throws Throwable { 188 | setDrawableRelativeRight(R.drawable.android); 189 | 190 | expectedException.expect(AssertionFailedError.class); 191 | expectedException.expectMessage("'with no relative right drawable' doesn't match the selected view."); 192 | onView(withId(VIEW_ID)).check(matches(withNoTextViewDrawableRelativeRight())); 193 | } 194 | 195 | @Test public void withTextViewDrawableBottomMatches() throws Throwable { 196 | setDrawableBottom(R.drawable.android); 197 | 198 | onView(withId(VIEW_ID)).check(matches(withTextViewDrawableBottom(R.drawable.android))); 199 | } 200 | 201 | @Test public void withTextViewDrawableBottomDoesNotMatch() throws Throwable { 202 | setDrawableBottom(R.drawable.android); 203 | 204 | expectedException.expect(AssertionFailedError.class); 205 | expectedException.expectMessage("'with bottom drawable from resource id: <" + R.drawable.northern_lights + ">' doesn't match the selected view."); 206 | onView(withId(VIEW_ID)).check(matches(withTextViewDrawableBottom(R.drawable.northern_lights))); 207 | } 208 | 209 | @Test public void withNoTextViewDrawableBottomMatches() { 210 | onView(withId(VIEW_ID)).check(matches(withNoTextViewDrawableBottom())); 211 | } 212 | 213 | @Test public void withNoTextViewDrawableBottomDoesNotMatch() throws Throwable { 214 | setDrawableBottom(R.drawable.android); 215 | 216 | expectedException.expect(AssertionFailedError.class); 217 | expectedException.expectMessage("'with no bottom drawable' doesn't match the selected view."); 218 | onView(withId(VIEW_ID)).check(matches(withNoTextViewDrawableBottom())); 219 | } 220 | 221 | @Test public void withTextViewDrawableRelativeBottomMatches() throws Throwable { 222 | setDrawableRelativeBottom(R.drawable.android); 223 | 224 | onView(withId(VIEW_ID)).check(matches(withTextViewDrawableRelativeBottom(R.drawable.android))); 225 | } 226 | 227 | @Test public void withTextViewDrawableRelativeBottomDoesNotMatch() throws Throwable { 228 | setDrawableRelativeBottom(R.drawable.android); 229 | 230 | expectedException.expect(AssertionFailedError.class); 231 | expectedException.expectMessage("'with relative bottom drawable from resource id: <" + R.drawable.northern_lights + ">' doesn't match the selected view."); 232 | onView(withId(VIEW_ID)).check(matches(withTextViewDrawableRelativeBottom(R.drawable.northern_lights))); 233 | } 234 | 235 | @Test public void withNoTextViewDrawableRelativeBottomMatches() { 236 | onView(withId(VIEW_ID)).check(matches(withNoTextViewDrawableRelativeBottom())); 237 | } 238 | 239 | @Test public void withNoTextViewDrawableRelativeBottomDoesNotMatch() throws Throwable { 240 | setDrawableRelativeBottom(R.drawable.android); 241 | 242 | expectedException.expect(AssertionFailedError.class); 243 | expectedException.expectMessage("'with no relative bottom drawable' doesn't match the selected view."); 244 | onView(withId(VIEW_ID)).check(matches(withNoTextViewDrawableRelativeBottom())); 245 | } 246 | 247 | private void setDrawableLeft(@DrawableRes final int drawable) throws Throwable { 248 | activityTestRule.runOnUiThread(new Runnable() { 249 | @Override public void run() { 250 | activityTestRule.getActivity().textView.setCompoundDrawablesWithIntrinsicBounds(drawable, 0, 0, 0); 251 | } 252 | }); 253 | } 254 | 255 | private void setDrawableRelativeLeft(@DrawableRes final int drawable) throws Throwable { 256 | activityTestRule.runOnUiThread(new Runnable() { 257 | @Override public void run() { 258 | activityTestRule.getActivity().textView.setCompoundDrawablesRelativeWithIntrinsicBounds(drawable, 0, 0, 0); 259 | } 260 | }); 261 | } 262 | 263 | private void setDrawableTop(@DrawableRes final int drawable) throws Throwable { 264 | activityTestRule.runOnUiThread(new Runnable() { 265 | @Override public void run() { 266 | activityTestRule.getActivity().textView.setCompoundDrawablesWithIntrinsicBounds(0, drawable, 0, 0); 267 | } 268 | }); 269 | } 270 | 271 | private void setDrawableRelativeTop(@DrawableRes final int drawable) throws Throwable { 272 | activityTestRule.runOnUiThread(new Runnable() { 273 | @Override public void run() { 274 | activityTestRule.getActivity().textView.setCompoundDrawablesRelativeWithIntrinsicBounds(0, drawable, 0, 0); 275 | } 276 | }); 277 | } 278 | 279 | private void setDrawableRight(@DrawableRes final int drawable) throws Throwable { 280 | activityTestRule.runOnUiThread(new Runnable() { 281 | @Override public void run() { 282 | activityTestRule.getActivity().textView.setCompoundDrawablesWithIntrinsicBounds(0, 0, drawable, 0); 283 | } 284 | }); 285 | } 286 | 287 | private void setDrawableRelativeRight(@DrawableRes final int drawable) throws Throwable { 288 | activityTestRule.runOnUiThread(new Runnable() { 289 | @Override public void run() { 290 | activityTestRule.getActivity().textView.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, drawable, 0); 291 | } 292 | }); 293 | } 294 | 295 | private void setDrawableBottom(@DrawableRes final int drawable) throws Throwable { 296 | activityTestRule.runOnUiThread(new Runnable() { 297 | @Override public void run() { 298 | activityTestRule.getActivity().textView.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, drawable); 299 | } 300 | }); 301 | } 302 | 303 | private void setDrawableRelativeBottom(@DrawableRes final int drawable) throws Throwable { 304 | activityTestRule.runOnUiThread(new Runnable() { 305 | @Override public void run() { 306 | activityTestRule.getActivity().textView.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, 0, drawable); 307 | } 308 | }); 309 | } 310 | } 311 | -------------------------------------------------------------------------------- /espresso-core-utils/src/androidTest/java/com/vanniktech/espresso/core/utils/ViewIndexMatcherActivity.java: -------------------------------------------------------------------------------- 1 | package com.vanniktech.espresso.core.utils; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.app.Activity; 5 | import android.os.Bundle; 6 | import android.widget.LinearLayout; 7 | import android.widget.TextView; 8 | import androidx.annotation.Nullable; 9 | 10 | public final class ViewIndexMatcherActivity extends Activity { 11 | @Override @SuppressLint("SetTextI18n") protected void onCreate(@Nullable final Bundle savedInstanceState) { 12 | super.onCreate(savedInstanceState); 13 | 14 | final TextView textView1 = new TextView(this); 15 | textView1.setText("Test"); 16 | textView1.setTag(1); 17 | 18 | final TextView textView2 = new TextView(this); 19 | textView2.setText("Test"); 20 | textView2.setTag(2); 21 | 22 | final LinearLayout linearLayout = new LinearLayout(this); 23 | linearLayout.addView(textView1); 24 | linearLayout.addView(textView2); 25 | setContentView(linearLayout); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /espresso-core-utils/src/androidTest/java/com/vanniktech/espresso/core/utils/ViewIndexMatcherTest.java: -------------------------------------------------------------------------------- 1 | package com.vanniktech.espresso.core.utils; 2 | 3 | import androidx.test.espresso.NoMatchingViewException; 4 | import androidx.test.ext.junit.runners.AndroidJUnit4; 5 | import androidx.test.rule.ActivityTestRule; 6 | import org.hamcrest.Matchers; 7 | import org.junit.Rule; 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | 11 | import static androidx.test.espresso.Espresso.onView; 12 | import static androidx.test.espresso.assertion.ViewAssertions.matches; 13 | import static androidx.test.espresso.matcher.ViewMatchers.withTagValue; 14 | import static androidx.test.espresso.matcher.ViewMatchers.withText; 15 | import static com.vanniktech.espresso.core.utils.ViewIndexMatcher.withIndex; 16 | import static org.junit.Assert.fail; 17 | import static org.junit.Assert.assertEquals; 18 | 19 | @RunWith(AndroidJUnit4.class) public final class ViewIndexMatcherTest { 20 | @Rule public final ActivityTestRule activityTestRule = new ActivityTestRule<>(ViewIndexMatcherActivity.class); 21 | 22 | @Test public void index() { 23 | onView(withIndex(withText("Test"), 0)).check(matches(withTagValue(Matchers.equalTo(1)))); 24 | onView(withIndex(withText("Test"), 1)).check(matches(withTagValue(Matchers.equalTo(2)))); 25 | } 26 | 27 | @Test public void invalidIndex() { 28 | try { 29 | onView(withIndex(withText("Test"), 2)).check(matches(withTagValue(Matchers.equalTo(1)))); 30 | fail(); 31 | } catch (final NoMatchingViewException e) { 32 | assertEquals(true, e.getMessage().startsWith("No views in hierarchy found matching: with index: <2> with text: is \"Test\"")); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /espresso-core-utils/src/androidTest/res/drawable/android.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vanniktech/espresso-utils/4b0ce2e399002b9928360752282baa06545b839d/espresso-core-utils/src/androidTest/res/drawable/android.png -------------------------------------------------------------------------------- /espresso-core-utils/src/androidTest/res/drawable/northern_lights.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vanniktech/espresso-utils/4b0ce2e399002b9928360752282baa06545b839d/espresso-core-utils/src/androidTest/res/drawable/northern_lights.jpg -------------------------------------------------------------------------------- /espresso-core-utils/src/androidTest/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #ff0000 4 | #00ff00 5 | #0000ff 6 | 7 | -------------------------------------------------------------------------------- /espresso-core-utils/src/androidTest/res/values/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | -------------------------------------------------------------------------------- /espresso-core-utils/src/main/java/com/vanniktech/espresso/core/utils/AppendTextAction.java: -------------------------------------------------------------------------------- 1 | package com.vanniktech.espresso.core.utils; 2 | 3 | import android.view.View; 4 | import android.widget.TextView; 5 | import androidx.annotation.CheckResult; 6 | import androidx.test.espresso.UiController; 7 | import androidx.test.espresso.ViewAction; 8 | import org.hamcrest.Matcher; 9 | 10 | import static androidx.test.espresso.action.ViewActions.actionWithAssertions; 11 | import static androidx.test.espresso.matcher.ViewMatchers.isAssignableFrom; 12 | import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; 13 | import static org.hamcrest.Matchers.allOf; 14 | 15 | public final class AppendTextAction implements ViewAction { 16 | /** 17 | * Appends the given text to a TextView. 18 | * 19 | *

Example usage:

20 | * onView(withId(R.id.view)).perform(appendText("Something")); 21 | */ 22 | @CheckResult public static ViewAction appendText(final String text) { 23 | return actionWithAssertions(new AppendTextAction(text)); 24 | } 25 | 26 | private final String text; 27 | 28 | private AppendTextAction(final String text) { 29 | this.text = text; 30 | } 31 | 32 | @Override public Matcher getConstraints() { 33 | return allOf(isDisplayed(), isAssignableFrom(TextView.class)); 34 | } 35 | 36 | @Override public void perform(final UiController uiController, final View view) { 37 | ((TextView) view).append(text); 38 | } 39 | 40 | @Override public String getDescription() { 41 | return "append text: " + text; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /espresso-core-utils/src/main/java/com/vanniktech/espresso/core/utils/AttributeMatcher.java: -------------------------------------------------------------------------------- 1 | package com.vanniktech.espresso.core.utils; 2 | 3 | import android.graphics.Color; 4 | import androidx.annotation.AttrRes; 5 | import androidx.annotation.CheckResult; 6 | import androidx.annotation.ColorInt; 7 | import androidx.annotation.ColorRes; 8 | import androidx.annotation.Nullable; 9 | import androidx.test.espresso.matcher.BoundedMatcher; 10 | import android.view.View; 11 | import android.widget.TextView; 12 | import org.hamcrest.Description; 13 | 14 | import static com.vanniktech.espresso.core.utils.Utils.resolveAttribute; 15 | 16 | public final class AttributeMatcher extends BoundedMatcher { 17 | /** 18 | * Matches that the given attribute has the expected color. 19 | * 20 | *

Example usage:

21 | * onView(withId(R.id.view)).check(matches(withAttrRes(R.attr.colorError, R.color.blue))); 22 | */ 23 | @CheckResult public static AttributeMatcher withAttrRes(@AttrRes final int attr, @ColorRes final int colorRes) { 24 | return new AttributeMatcher(attr, null, ColorChecker.fromRes(colorRes)); 25 | } 26 | 27 | /** 28 | * Matches that the given attribute has the expected color. 29 | * 30 | *

Example usage:

31 | * onView(withId(R.id.view)).check(matches(withAttr(R.attr.colorError, BLUE))); 32 | */ 33 | @CheckResult public static AttributeMatcher withAttr(@AttrRes final int attr, @ColorInt final int color) { 34 | return new AttributeMatcher(attr, null, ColorChecker.from(color)); 35 | } 36 | 37 | /** 38 | * Matches that the given attribute has the expected color. 39 | * 40 | *

Example usage:

41 | * onView(withId(R.id.view)).check(matches(withAttr(R.attr.colorError, "#0000ff"))); 42 | */ 43 | @CheckResult public static AttributeMatcher withAttr(@AttrRes final int attr, final String color) { 44 | return withAttr(attr, Color.parseColor(color)); 45 | } 46 | 47 | /** 48 | * Matches that the accent color has the expected color. 49 | * 50 | *

Example usage:

51 | * onView(withId(R.id.view)).check(matches(withColorAccentRes(R.color.green))); 52 | */ 53 | @CheckResult public static AttributeMatcher withColorAccentRes(@ColorRes final int colorRes) { 54 | return new AttributeMatcher(android.R.attr.colorAccent, "colorAccent", ColorChecker.fromRes(colorRes)); 55 | } 56 | 57 | /** 58 | * Matches that the accent color has the expected color. 59 | * 60 | *

Example usage:

61 | * onView(withId(R.id.view)).check(matches(withColorAccent(GREEN))); 62 | */ 63 | @CheckResult public static AttributeMatcher withColorAccent(@ColorInt final int color) { 64 | return new AttributeMatcher(android.R.attr.colorAccent, "colorAccent", ColorChecker.from(color)); 65 | } 66 | 67 | /** 68 | * Matches that the accent color has the expected color. 69 | * 70 | *

Example usage:

71 | * onView(withId(R.id.view)).check(matches(withColorAccent("#00ff00"))); 72 | */ 73 | @CheckResult public static AttributeMatcher withColorAccent(final String color) { 74 | return withColorAccent(Color.parseColor(color)); 75 | } 76 | 77 | /** 78 | * Matches that the button color has the expected color. 79 | * 80 | *

Example usage:

81 | * onView(withId(R.id.view)).check(matches(withColorButtonNormalRes(R.color.red))); 82 | */ 83 | @CheckResult public static AttributeMatcher withColorButtonNormalRes(@ColorRes final int colorRes) { 84 | return new AttributeMatcher(android.R.attr.colorButtonNormal, "colorButtonNormal", ColorChecker.fromRes(colorRes)); 85 | } 86 | 87 | /** 88 | * Matches that the button color has the expected color. 89 | * 90 | *

Example usage:

91 | * onView(withId(R.id.view)).check(matches(withColorButtonNormal(RED))); 92 | */ 93 | @CheckResult public static AttributeMatcher withColorButtonNormal(@ColorInt final int color) { 94 | return new AttributeMatcher(android.R.attr.colorButtonNormal, "colorButtonNormal", ColorChecker.from(color)); 95 | } 96 | 97 | /** 98 | * Matches that the button color has the expected color. 99 | * 100 | *

Example usage:

101 | * onView(withId(R.id.view)).check(matches(withColorButtonNormal("#ff0000"))); 102 | */ 103 | @CheckResult public static AttributeMatcher withColorButtonNormal(final String color) { 104 | return withColorButtonNormal(Color.parseColor(color)); 105 | } 106 | 107 | @AttrRes private final int attr; 108 | @Nullable private final String name; 109 | private final ColorChecker colorChecker; 110 | 111 | private AttributeMatcher(final int attr, @Nullable final String name, final ColorChecker colorChecker) { 112 | super(TextView.class); 113 | 114 | this.name = name; 115 | this.colorChecker = colorChecker; 116 | this.attr = attr; 117 | } 118 | 119 | @Override protected boolean matchesSafely(final TextView item) { 120 | final int color = resolveAttribute(item, attr); 121 | return colorChecker.matches(color, item.getContext()); 122 | } 123 | 124 | @Override public void describeTo(final Description description) { 125 | description.appendText("with ") 126 | .appendText(name != null ? name : String.valueOf(attr)) 127 | .appendText(": "); 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /espresso-core-utils/src/main/java/com/vanniktech/espresso/core/utils/ColorChecker.java: -------------------------------------------------------------------------------- 1 | package com.vanniktech.espresso.core.utils; 2 | 3 | import android.content.Context; 4 | import androidx.annotation.CheckResult; 5 | import androidx.annotation.ColorInt; 6 | import androidx.annotation.ColorRes; 7 | import androidx.annotation.Nullable; 8 | import androidx.core.content.ContextCompat; 9 | 10 | import static com.vanniktech.espresso.core.utils.Utils.checkNotNull; 11 | 12 | final class ColorChecker { 13 | @CheckResult static ColorChecker fromRes(@ColorRes final int colorRes) { 14 | final ColorChecker matcher = new ColorChecker(); 15 | matcher.colorRes = colorRes; 16 | return matcher; 17 | } 18 | 19 | @CheckResult static ColorChecker from(@ColorInt final int color) { 20 | final ColorChecker matcher = new ColorChecker(); 21 | matcher.colorInt = color; 22 | return matcher; 23 | } 24 | 25 | @Nullable @ColorRes private Integer colorRes; 26 | @Nullable @ColorInt private Integer colorInt; 27 | 28 | private ColorChecker() { 29 | } 30 | 31 | boolean matches(final int color, final Context context) { 32 | if (colorInt != null) { 33 | return color == colorInt; 34 | } 35 | 36 | return color == ContextCompat.getColor(context, checkNotNull(colorRes, "colorRes == null")); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /espresso-core-utils/src/main/java/com/vanniktech/espresso/core/utils/CurrentItemMatcher.java: -------------------------------------------------------------------------------- 1 | package com.vanniktech.espresso.core.utils; 2 | 3 | import android.view.View; 4 | import androidx.annotation.CheckResult; 5 | import androidx.test.espresso.matcher.BoundedMatcher; 6 | import androidx.viewpager.widget.ViewPager; 7 | import org.hamcrest.Description; 8 | 9 | public final class CurrentItemMatcher extends BoundedMatcher { 10 | /** 11 | * Matches that the expected currentItem is being displayed. 12 | * 13 | *

Example usage:

14 | * onView(withId(R.id.view)).check(matches(withCurrentItem(0))); 15 | */ 16 | @CheckResult public static CurrentItemMatcher withCurrentItem(final int currentItem) { 17 | return new CurrentItemMatcher(currentItem); 18 | } 19 | 20 | private final int currentItem; 21 | 22 | private CurrentItemMatcher(final int currentItem) { 23 | super(ViewPager.class); 24 | 25 | this.currentItem = currentItem; 26 | } 27 | 28 | @Override protected boolean matchesSafely(final ViewPager currentItemBar) { 29 | return currentItemBar.getCurrentItem() == currentItem; 30 | } 31 | 32 | @Override public void describeTo(final Description description) { 33 | description.appendText("has currentItem: ").appendValue(currentItem); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /espresso-core-utils/src/main/java/com/vanniktech/espresso/core/utils/DrawableMatcher.java: -------------------------------------------------------------------------------- 1 | package com.vanniktech.espresso.core.utils; 2 | 3 | import android.graphics.drawable.Drawable; 4 | import androidx.annotation.CheckResult; 5 | import androidx.annotation.DrawableRes; 6 | import androidx.test.espresso.matcher.BoundedMatcher; 7 | import android.view.View; 8 | import android.widget.ImageView; 9 | import org.hamcrest.Description; 10 | 11 | import static com.vanniktech.espresso.core.utils.Utils.NO_DRAWABLE; 12 | import static com.vanniktech.espresso.core.utils.Utils.drawableMatches; 13 | 14 | public final class DrawableMatcher extends BoundedMatcher { 15 | /** 16 | * Matches that the given view has the expected drawable. 17 | * 18 | *

Example usage:

19 | * onView(withId(R.id.view)).check(matches(withDrawable(R.drawable.android))); 20 | */ 21 | @CheckResult public static DrawableMatcher withDrawable(@DrawableRes final int resourceId) { 22 | return new DrawableMatcher(resourceId); 23 | } 24 | 25 | /** 26 | * Matches that the given view has no drawable. 27 | * 28 | *

Example usage:

29 | * onView(withId(R.id.view)).check(matches(withNoDrawable())); 30 | */ 31 | @CheckResult public static DrawableMatcher withNoDrawable() { 32 | return new DrawableMatcher(NO_DRAWABLE); 33 | } 34 | 35 | private final int expectedId; 36 | 37 | private DrawableMatcher(final int expectedId) { 38 | super(ImageView.class); 39 | 40 | this.expectedId = expectedId; 41 | } 42 | 43 | @Override protected boolean matchesSafely(final ImageView imageView) { 44 | final Drawable drawable = imageView.getDrawable(); 45 | return drawableMatches(imageView, drawable, expectedId); 46 | } 47 | 48 | @Override public void describeTo(final Description description) { 49 | if (expectedId == NO_DRAWABLE) { 50 | description.appendText("with no drawable"); 51 | } else { 52 | description.appendText("with drawable from resource id: ").appendValue(expectedId); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /espresso-core-utils/src/main/java/com/vanniktech/espresso/core/utils/HintTextColorMatcher.java: -------------------------------------------------------------------------------- 1 | package com.vanniktech.espresso.core.utils; 2 | 3 | import android.graphics.Color; 4 | import androidx.annotation.CheckResult; 5 | import androidx.annotation.ColorInt; 6 | import androidx.annotation.ColorRes; 7 | import androidx.test.espresso.matcher.BoundedMatcher; 8 | import android.view.View; 9 | import android.widget.TextView; 10 | import org.hamcrest.Description; 11 | 12 | public final class HintTextColorMatcher extends BoundedMatcher { 13 | /** 14 | * Matches that the hint text has the expected color. 15 | * 16 | *

Example usage:

17 | * onView(withId(R.id.view)).check(matches(withHintTextColorRes(R.color.blue))); 18 | */ 19 | @CheckResult public static HintTextColorMatcher withHintTextColorRes(@ColorRes final int colorRes) { 20 | return new HintTextColorMatcher(ColorChecker.fromRes(colorRes)); 21 | } 22 | 23 | /** 24 | * Matches that the hint text has the expected color. 25 | * 26 | *

Example usage:

27 | * onView(withId(R.id.view)).check(matches(withHintTextColorRes(BLUE))); 28 | */ 29 | @CheckResult public static HintTextColorMatcher withHintTextColor(@ColorInt final int color) { 30 | return new HintTextColorMatcher(ColorChecker.from(color)); 31 | } 32 | 33 | /** 34 | * Matches that the hint text has the expected color. 35 | * 36 | *

Example usage:

37 | * onView(withId(R.id.view)).check(matches(withHintTextColorRes("#0000ff"))); 38 | */ 39 | @CheckResult public static HintTextColorMatcher withHintTextColor(final String color) { 40 | return withHintTextColor(Color.parseColor(color)); 41 | } 42 | 43 | private final ColorChecker colorChecker; 44 | 45 | private HintTextColorMatcher(final ColorChecker colorChecker) { 46 | super(TextView.class); 47 | 48 | this.colorChecker = colorChecker; 49 | } 50 | 51 | @Override protected boolean matchesSafely(final TextView item) { 52 | final int color = item.getCurrentHintTextColor(); 53 | return colorChecker.matches(color, item.getContext()); 54 | } 55 | 56 | @Override public void describeTo(final Description description) { 57 | description.appendText("with hint text color: "); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /espresso-core-utils/src/main/java/com/vanniktech/espresso/core/utils/ProgressMatcher.java: -------------------------------------------------------------------------------- 1 | package com.vanniktech.espresso.core.utils; 2 | 3 | import androidx.annotation.CheckResult; 4 | import androidx.test.espresso.matcher.BoundedMatcher; 5 | import android.view.View; 6 | import android.widget.ProgressBar; 7 | import org.hamcrest.Description; 8 | 9 | public final class ProgressMatcher extends BoundedMatcher { 10 | /** 11 | * Matches that the given progress is displayed. 12 | * 13 | *

Example usage:

14 | * onView(withId(R.id.view)).check(matches(withProgress(2))); 15 | */ 16 | @CheckResult public static ProgressMatcher withProgress(final int progress) { 17 | return new ProgressMatcher(progress); 18 | } 19 | 20 | private final int progress; 21 | 22 | private ProgressMatcher(final int progress) { 23 | super(ProgressBar.class); 24 | 25 | this.progress = progress; 26 | } 27 | 28 | @Override protected boolean matchesSafely(final ProgressBar progressBar) { 29 | return progressBar.getProgress() == progress; 30 | } 31 | 32 | @Override public void describeTo(final Description description) { 33 | description.appendText("has progress: ").appendValue(progress); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /espresso-core-utils/src/main/java/com/vanniktech/espresso/core/utils/SetProgressAction.java: -------------------------------------------------------------------------------- 1 | package com.vanniktech.espresso.core.utils; 2 | 3 | import androidx.annotation.CheckResult; 4 | import androidx.test.espresso.UiController; 5 | import androidx.test.espresso.ViewAction; 6 | import android.view.View; 7 | import android.widget.ProgressBar; 8 | import org.hamcrest.Matcher; 9 | 10 | import static androidx.test.espresso.action.ViewActions.actionWithAssertions; 11 | import static androidx.test.espresso.matcher.ViewMatchers.isAssignableFrom; 12 | import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; 13 | import static org.hamcrest.Matchers.allOf; 14 | 15 | public final class SetProgressAction implements ViewAction { 16 | /** 17 | * Sets the given progress on a ProgressBar. 18 | * 19 | *

Example usage:

20 | * onView(withId(R.id.view)).perform(setProgress(95)); 21 | */ 22 | @CheckResult public static ViewAction setProgress(final int progress) { 23 | return actionWithAssertions(new SetProgressAction(progress)); 24 | } 25 | 26 | private final int progress; 27 | 28 | private SetProgressAction(final int progress) { 29 | this.progress = progress; 30 | } 31 | 32 | @Override public Matcher getConstraints() { 33 | return allOf(isDisplayed(), isAssignableFrom(ProgressBar.class)); 34 | } 35 | 36 | @Override public void perform(final UiController uiController, final View view) { 37 | ((ProgressBar) view).setProgress(progress); 38 | } 39 | 40 | @Override public String getDescription() { 41 | return "set progress: " + progress; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /espresso-core-utils/src/main/java/com/vanniktech/espresso/core/utils/TextColorMatcher.java: -------------------------------------------------------------------------------- 1 | package com.vanniktech.espresso.core.utils; 2 | 3 | import android.graphics.Color; 4 | import androidx.annotation.CheckResult; 5 | import androidx.annotation.ColorInt; 6 | import androidx.annotation.ColorRes; 7 | import androidx.test.espresso.matcher.BoundedMatcher; 8 | import android.view.View; 9 | import android.widget.TextView; 10 | import org.hamcrest.Description; 11 | 12 | public final class TextColorMatcher extends BoundedMatcher { 13 | /** 14 | * Matches that the text has the expected color. 15 | * 16 | *

Example usage:

17 | * onView(withId(R.id.view)).check(matches(withTextColor(R.color.blue))); 18 | */ 19 | @CheckResult public static TextColorMatcher withTextColorRes(@ColorRes final int colorRes) { 20 | return new TextColorMatcher(ColorChecker.fromRes(colorRes)); 21 | } 22 | 23 | /** 24 | * Matches that the text has the expected color. 25 | * 26 | *

Example usage:

27 | * onView(withId(R.id.view)).check(matches(withTextColor(BLUE))); 28 | */ 29 | @CheckResult public static TextColorMatcher withTextColor(@ColorInt final int color) { 30 | return new TextColorMatcher(ColorChecker.from(color)); 31 | } 32 | 33 | /** 34 | * Matches that the text has the expected color. 35 | * 36 | *

Example usage:

37 | * onView(withId(R.id.view)).check(matches(withTextColor("#0000ff"))); 38 | */ 39 | @CheckResult public static TextColorMatcher withTextColor(final String color) { 40 | return withTextColor(Color.parseColor(color)); 41 | } 42 | 43 | private final ColorChecker colorChecker; 44 | 45 | private TextColorMatcher(final ColorChecker colorChecker) { 46 | super(TextView.class); 47 | 48 | this.colorChecker = colorChecker; 49 | } 50 | 51 | @Override protected boolean matchesSafely(final TextView item) { 52 | final int color = item.getCurrentTextColor(); 53 | return colorChecker.matches(color, item.getContext()); 54 | } 55 | 56 | @Override public void describeTo(final Description description) { 57 | description.appendText("with text color: "); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /espresso-core-utils/src/main/java/com/vanniktech/espresso/core/utils/TextViewDrawableMatcher.java: -------------------------------------------------------------------------------- 1 | package com.vanniktech.espresso.core.utils; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.graphics.drawable.Drawable; 5 | import android.view.View; 6 | import android.widget.TextView; 7 | import androidx.annotation.CheckResult; 8 | import androidx.annotation.DrawableRes; 9 | import androidx.test.espresso.matcher.BoundedMatcher; 10 | import org.hamcrest.Description; 11 | 12 | import static com.vanniktech.espresso.core.utils.TextViewDrawableMatcher.Type.DRAWABLE_BOTTOM; 13 | import static com.vanniktech.espresso.core.utils.TextViewDrawableMatcher.Type.DRAWABLE_LEFT; 14 | import static com.vanniktech.espresso.core.utils.TextViewDrawableMatcher.Type.DRAWABLE_RELATIVE_BOTTOM; 15 | import static com.vanniktech.espresso.core.utils.TextViewDrawableMatcher.Type.DRAWABLE_RELATIVE_LEFT; 16 | import static com.vanniktech.espresso.core.utils.TextViewDrawableMatcher.Type.DRAWABLE_RELATIVE_RIGHT; 17 | import static com.vanniktech.espresso.core.utils.TextViewDrawableMatcher.Type.DRAWABLE_RELATIVE_TOP; 18 | import static com.vanniktech.espresso.core.utils.TextViewDrawableMatcher.Type.DRAWABLE_RIGHT; 19 | import static com.vanniktech.espresso.core.utils.TextViewDrawableMatcher.Type.DRAWABLE_TOP; 20 | import static com.vanniktech.espresso.core.utils.Utils.INDEX_BOTTOM; 21 | import static com.vanniktech.espresso.core.utils.Utils.INDEX_LEFT; 22 | import static com.vanniktech.espresso.core.utils.Utils.INDEX_RIGHT; 23 | import static com.vanniktech.espresso.core.utils.Utils.INDEX_TOP; 24 | import static com.vanniktech.espresso.core.utils.Utils.NO_DRAWABLE; 25 | import static com.vanniktech.espresso.core.utils.Utils.drawableMatches; 26 | 27 | public final class TextViewDrawableMatcher extends BoundedMatcher { 28 | /** 29 | * Matches that the given drawable is displayed as the left drawable. 30 | * 31 | *

Example usage:

32 | * onView(withId(R.id.view)).check(matches(withTextViewDrawableLeft(R.color.blue))); 33 | */ 34 | @CheckResult public static TextViewDrawableMatcher withTextViewDrawableLeft(@DrawableRes final int resourceId) { 35 | return new TextViewDrawableMatcher(resourceId, DRAWABLE_LEFT); 36 | } 37 | 38 | /** 39 | * Matches that there is no left drawable. 40 | * 41 | *

Example usage:

42 | * onView(withId(R.id.view)).check(matches(withNoTextViewDrawableLeft())); 43 | */ 44 | @CheckResult public static TextViewDrawableMatcher withNoTextViewDrawableLeft() { 45 | return new TextViewDrawableMatcher(NO_DRAWABLE, DRAWABLE_LEFT); 46 | } 47 | 48 | /** 49 | * Matches that the given drawable is displayed as the relative left drawable. 50 | * 51 | *

Example usage:

52 | * onView(withId(R.id.view)).check(matches(withTextViewDrawableRelativeLeft(R.color.blue))); 53 | */ 54 | @CheckResult public static TextViewDrawableMatcher withTextViewDrawableRelativeLeft(@DrawableRes final int resourceId) { 55 | return new TextViewDrawableMatcher(resourceId, DRAWABLE_RELATIVE_LEFT); 56 | } 57 | 58 | /** 59 | * Matches that there is no relative left drawable. 60 | * 61 | *

Example usage:

62 | * onView(withId(R.id.view)).check(matches(withNoTextViewDrawableRelativeLeft())); 63 | */ 64 | @CheckResult public static TextViewDrawableMatcher withNoTextViewDrawableRelativeLeft() { 65 | return new TextViewDrawableMatcher(NO_DRAWABLE, DRAWABLE_RELATIVE_LEFT); 66 | } 67 | 68 | /** 69 | * Matches that the given drawable is displayed as the top drawable. 70 | * 71 | *

Example usage:

72 | * onView(withId(R.id.view)).check(matches(withTextViewDrawableTop(R.color.blue))); 73 | */ 74 | @CheckResult public static TextViewDrawableMatcher withTextViewDrawableTop(@DrawableRes final int resourceId) { 75 | return new TextViewDrawableMatcher(resourceId, DRAWABLE_TOP); 76 | } 77 | 78 | /** 79 | * Matches that there is no top drawable. 80 | * 81 | *

Example usage:

82 | * onView(withId(R.id.view)).check(matches(withNoTextViewDrawableTop())); 83 | */ 84 | @CheckResult public static TextViewDrawableMatcher withNoTextViewDrawableTop() { 85 | return new TextViewDrawableMatcher(NO_DRAWABLE, DRAWABLE_TOP); 86 | } 87 | 88 | /** 89 | * Matches that the given drawable is displayed as the relative top drawable. 90 | * 91 | *

Example usage:

92 | * onView(withId(R.id.view)).check(matches(withTextViewDrawableRelativeTop(R.color.blue))); 93 | */ 94 | @CheckResult public static TextViewDrawableMatcher withTextViewDrawableRelativeTop(@DrawableRes final int resourceId) { 95 | return new TextViewDrawableMatcher(resourceId, DRAWABLE_RELATIVE_TOP); 96 | } 97 | 98 | /** 99 | * Matches that there is no relative top drawable. 100 | * 101 | *

Example usage:

102 | * onView(withId(R.id.view)).check(matches(withNoTextViewDrawableRelativeTop())); 103 | */ 104 | @CheckResult public static TextViewDrawableMatcher withNoTextViewDrawableRelativeTop() { 105 | return new TextViewDrawableMatcher(NO_DRAWABLE, DRAWABLE_RELATIVE_TOP); 106 | } 107 | 108 | /** 109 | * Matches that the given drawable is displayed as the right drawable. 110 | * 111 | *

Example usage:

112 | * onView(withId(R.id.view)).check(matches(withTextViewDrawableRight(R.color.blue))); 113 | */ 114 | @CheckResult public static TextViewDrawableMatcher withTextViewDrawableRight(@DrawableRes final int resourceId) { 115 | return new TextViewDrawableMatcher(resourceId, DRAWABLE_RIGHT); 116 | } 117 | 118 | /** 119 | * Matches that there is no right drawable. 120 | * 121 | *

Example usage:

122 | * onView(withId(R.id.view)).check(matches(withNoTextViewDrawableRight())); 123 | */ 124 | @CheckResult public static TextViewDrawableMatcher withNoTextViewDrawableRight() { 125 | return new TextViewDrawableMatcher(NO_DRAWABLE, DRAWABLE_RIGHT); 126 | } 127 | 128 | /** 129 | * Matches that the given drawable is displayed as the relative right drawable. 130 | * 131 | *

Example usage:

132 | * onView(withId(R.id.view)).check(matches(withTextViewDrawableRelativeRight(R.color.blue))); 133 | */ 134 | @CheckResult public static TextViewDrawableMatcher withTextViewDrawableRelativeRight(@DrawableRes final int resourceId) { 135 | return new TextViewDrawableMatcher(resourceId, DRAWABLE_RELATIVE_RIGHT); 136 | } 137 | 138 | /** 139 | * Matches that there is no relative right drawable. 140 | * 141 | *

Example usage:

142 | * onView(withId(R.id.view)).check(matches(withNoTextViewDrawableRelativeRight())); 143 | */ 144 | @CheckResult public static TextViewDrawableMatcher withNoTextViewDrawableRelativeRight() { 145 | return new TextViewDrawableMatcher(NO_DRAWABLE, DRAWABLE_RELATIVE_RIGHT); 146 | } 147 | 148 | /** 149 | * Matches that the given drawable is displayed as the bottom drawable. 150 | * 151 | *

Example usage:

152 | * onView(withId(R.id.view)).check(matches(withTextViewDrawableBottom(R.color.blue))); 153 | */ 154 | @CheckResult public static TextViewDrawableMatcher withTextViewDrawableBottom(@DrawableRes final int resourceId) { 155 | return new TextViewDrawableMatcher(resourceId, DRAWABLE_BOTTOM); 156 | } 157 | 158 | /** 159 | * Matches that there is no bottom drawable. 160 | * 161 | *

Example usage:

162 | * onView(withId(R.id.view)).check(matches(withNoTextViewDrawableBottom())); 163 | */ 164 | @CheckResult public static TextViewDrawableMatcher withNoTextViewDrawableBottom() { 165 | return new TextViewDrawableMatcher(NO_DRAWABLE, DRAWABLE_BOTTOM); 166 | } 167 | 168 | /** 169 | * Matches that the given drawable is displayed as the relative bottom drawable. 170 | * 171 | *

Example usage:

172 | * onView(withId(R.id.view)).check(matches(withTextViewDrawableRelativeBottom(R.color.blue))); 173 | */ 174 | @CheckResult public static TextViewDrawableMatcher withTextViewDrawableRelativeBottom(@DrawableRes final int resourceId) { 175 | return new TextViewDrawableMatcher(resourceId, DRAWABLE_RELATIVE_BOTTOM); 176 | } 177 | 178 | /** 179 | * Matches that there is no relative bottom drawable. 180 | * 181 | *

Example usage:

182 | * onView(withId(R.id.view)).check(matches(withNoTextViewDrawableRelativeBottom())); 183 | */ 184 | @CheckResult public static TextViewDrawableMatcher withNoTextViewDrawableRelativeBottom() { 185 | return new TextViewDrawableMatcher(NO_DRAWABLE, DRAWABLE_RELATIVE_BOTTOM); 186 | } 187 | 188 | private final int expectedId; 189 | private final Type type; 190 | 191 | private TextViewDrawableMatcher(final int expectedId, final Type type) { 192 | super(TextView.class); 193 | 194 | this.expectedId = expectedId; 195 | this.type = type; 196 | } 197 | 198 | @Override protected boolean matchesSafely(final TextView textView) { 199 | return drawableMatches(textView, type.getDrawable(textView), expectedId); 200 | } 201 | 202 | @Override public void describeTo(final Description description) { 203 | if (expectedId == NO_DRAWABLE) { 204 | description.appendText("with no ") 205 | .appendText(type.string) 206 | .appendText(" drawable"); 207 | } else { 208 | description.appendText("with ") 209 | .appendText(type.string) 210 | .appendText(" drawable from resource id: ") 211 | .appendValue(expectedId); 212 | } 213 | } 214 | 215 | enum Type { 216 | DRAWABLE_LEFT(INDEX_LEFT, false, "left"), 217 | DRAWABLE_RELATIVE_LEFT(INDEX_LEFT, true, "relative left"), 218 | DRAWABLE_TOP(INDEX_TOP, false, "top"), 219 | DRAWABLE_RELATIVE_TOP(INDEX_TOP, true, "relative top"), 220 | DRAWABLE_RIGHT(INDEX_RIGHT, false, "right"), 221 | DRAWABLE_RELATIVE_RIGHT(INDEX_RIGHT, true, "relative right"), 222 | DRAWABLE_BOTTOM(INDEX_BOTTOM, false, "bottom"), 223 | DRAWABLE_RELATIVE_BOTTOM(INDEX_BOTTOM, true, "relative bottom"); 224 | 225 | private final int index; 226 | private final boolean isRelative; 227 | final String string; 228 | 229 | Type(final int index, final boolean isRelative, final String string) { 230 | this.index = index; 231 | this.isRelative = isRelative; 232 | this.string = string; 233 | } 234 | 235 | @SuppressLint("NewApi") public Drawable getDrawable(final TextView textView) { 236 | final Drawable[] drawables = isRelative ? textView.getCompoundDrawablesRelative() : textView.getCompoundDrawables(); 237 | return drawables[index]; 238 | } 239 | } 240 | } 241 | -------------------------------------------------------------------------------- /espresso-core-utils/src/main/java/com/vanniktech/espresso/core/utils/Utils.java: -------------------------------------------------------------------------------- 1 | package com.vanniktech.espresso.core.utils; 2 | 3 | import android.content.Context; 4 | import android.graphics.drawable.Drawable; 5 | import android.util.TypedValue; 6 | import android.view.View; 7 | import androidx.annotation.AttrRes; 8 | import androidx.annotation.DrawableRes; 9 | import androidx.annotation.NonNull; 10 | import androidx.annotation.Nullable; 11 | import androidx.core.content.ContextCompat; 12 | 13 | import static android.view.View.VISIBLE; 14 | 15 | final class Utils { 16 | static final int NO_DRAWABLE = -1; 17 | static final int INDEX_LEFT = 0; 18 | static final int INDEX_TOP = 1; 19 | static final int INDEX_RIGHT = 2; 20 | static final int INDEX_BOTTOM = 3; 21 | 22 | static int resolveAttribute(final View view, @AttrRes final int attr) { 23 | final TypedValue value = new TypedValue(); 24 | view.getContext().getTheme().resolveAttribute(attr, value, true); 25 | return value.data; 26 | } 27 | 28 | @NonNull static T checkNotNull(@Nullable final T reference, final String message) { 29 | if (reference == null) { 30 | throw new IllegalArgumentException(message); 31 | } 32 | 33 | return reference; 34 | } 35 | 36 | static boolean drawableMatches(final View view, final Drawable drawable, @DrawableRes final int expectedId) { 37 | final boolean isVisible = view.getVisibility() == VISIBLE; 38 | 39 | if (expectedId == NO_DRAWABLE) { 40 | return isVisible && drawable == null; 41 | } 42 | 43 | final Context context = view.getContext(); 44 | return isVisible && checkNotNull(drawable.getConstantState(), "constantState == null").equals(ContextCompat.getDrawable(context, expectedId).getConstantState()); 45 | } 46 | 47 | private Utils() { 48 | throw new AssertionError("No instances."); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /espresso-core-utils/src/main/java/com/vanniktech/espresso/core/utils/ViewIndexMatcher.java: -------------------------------------------------------------------------------- 1 | package com.vanniktech.espresso.core.utils; 2 | 3 | import android.view.View; 4 | import androidx.annotation.CheckResult; 5 | import androidx.test.espresso.matcher.BoundedMatcher; 6 | import org.hamcrest.Description; 7 | import org.hamcrest.Matcher; 8 | 9 | public final class ViewIndexMatcher extends BoundedMatcher { 10 | /** 11 | * Matches the given matcher on the given index. This can be used when you have a Matcher that matches multiple views. 12 | * By default Espresso will throw an exception on ambiguous views that can be matched. 13 | * 14 | *

Example usage:

15 | * onView(withIndex(withId(R.id.view), 2)).check(matches(withProgress(2))); 16 | */ 17 | @CheckResult public static Matcher withIndex(final Matcher matcher, final int index) { 18 | return new ViewIndexMatcher(matcher, index); 19 | } 20 | 21 | private int currentIndex; 22 | 23 | private final Matcher matcher; 24 | private final int index; 25 | 26 | private ViewIndexMatcher(final Matcher matcher, final int index) { 27 | super(View.class); 28 | 29 | this.matcher = matcher; 30 | this.index = index; 31 | } 32 | 33 | @Override public void describeTo(final Description description) { 34 | description.appendText("with index: "); 35 | description.appendValue(index); 36 | description.appendText(" "); 37 | matcher.describeTo(description); 38 | } 39 | 40 | @Override public boolean matchesSafely(final View view) { 41 | return matcher.matches(view) && currentIndex++ == index; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /espresso-core-utils/src/test/java/com/vanniktech/espresso/core/utils/TextViewDrawableMatcherTypeTest.java: -------------------------------------------------------------------------------- 1 | package com.vanniktech.espresso.core.utils; 2 | 3 | import com.vanniktech.espresso.core.utils.TextViewDrawableMatcher.Type; 4 | import java.util.Arrays; 5 | import org.junit.Test; 6 | 7 | import static com.vanniktech.espresso.core.utils.TextViewDrawableMatcher.Type.DRAWABLE_BOTTOM; 8 | import static com.vanniktech.espresso.core.utils.TextViewDrawableMatcher.Type.DRAWABLE_LEFT; 9 | import static com.vanniktech.espresso.core.utils.TextViewDrawableMatcher.Type.DRAWABLE_RELATIVE_BOTTOM; 10 | import static com.vanniktech.espresso.core.utils.TextViewDrawableMatcher.Type.DRAWABLE_RELATIVE_LEFT; 11 | import static com.vanniktech.espresso.core.utils.TextViewDrawableMatcher.Type.DRAWABLE_RELATIVE_RIGHT; 12 | import static com.vanniktech.espresso.core.utils.TextViewDrawableMatcher.Type.DRAWABLE_RELATIVE_TOP; 13 | import static com.vanniktech.espresso.core.utils.TextViewDrawableMatcher.Type.DRAWABLE_RIGHT; 14 | import static com.vanniktech.espresso.core.utils.TextViewDrawableMatcher.Type.DRAWABLE_TOP; 15 | import static org.junit.Assert.assertEquals; 16 | 17 | public final class TextViewDrawableMatcherTypeTest { 18 | @Test public void entries() { 19 | assertEquals(Arrays.asList( 20 | DRAWABLE_LEFT, 21 | DRAWABLE_RELATIVE_LEFT, 22 | DRAWABLE_TOP, 23 | DRAWABLE_RELATIVE_TOP, 24 | DRAWABLE_RIGHT, 25 | DRAWABLE_RELATIVE_RIGHT, 26 | DRAWABLE_BOTTOM, 27 | DRAWABLE_RELATIVE_BOTTOM 28 | ), Arrays.asList(Type.values())); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /espresso-core-utils/src/test/java/com/vanniktech/espresso/core/utils/UtilsTest.java: -------------------------------------------------------------------------------- 1 | package com.vanniktech.espresso.core.utils; 2 | 3 | import org.junit.Rule; 4 | import org.junit.Test; 5 | import org.junit.rules.ExpectedException; 6 | 7 | import static com.vanniktech.espresso.core.utils.Utils.checkNotNull; 8 | import static org.junit.Assert.assertEquals; 9 | 10 | public final class UtilsTest { 11 | @Rule public final ExpectedException expectedException = ExpectedException.none(); 12 | 13 | 14 | @Test public void checkNotNullNoNull() { 15 | assertEquals(Integer.valueOf(5), checkNotNull(5, "should never be")); 16 | assertEquals("5", checkNotNull("5", "should never be")); 17 | assertEquals(Float.valueOf(3f), checkNotNull(3f, "should never be")); 18 | } 19 | 20 | @Test public void checkNotNullNull() { 21 | expectedException.expect(IllegalArgumentException.class); 22 | expectedException.expectMessage("null == null"); 23 | checkNotNull(null, "null == null"); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /get-espresso-core-utils-methods.sh: -------------------------------------------------------------------------------- 1 | ack -h -o --java "append[\w\d\()\s@,]+ \{" espresso-core-utils/src/main | xargs -L 1 | sed 's/final //g' | sed 's/ {//g' 2 | ack -h -o --java "with[\w\d\()\s@,]+ \{" espresso-core-utils/src/main | xargs -L 1 | sed 's/final //g' | sed 's/ {//g' -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | VERSION_NAME=0.5.0-SNAPSHOT 2 | GROUP=com.vanniktech 3 | 4 | POM_DESCRIPTION=Helper methods for asserting a few things that Espresso does not support out of the box 5 | POM_URL=https://github.com/vanniktech/espresso-utils 6 | POM_SCM_URL=https://github.com/vanniktech/espresso-utils 7 | POM_SCM_CONNECTION=scm:git@github.com:vanniktech/espresso-utils.git 8 | POM_SCM_DEV_CONNECTION=scm:git@github.com:vanniktech/espresso-utils.git 9 | POM_LICENCE_NAME=The Apache Software License, Version 2.0 10 | POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt 11 | POM_LICENCE_DIST=repo 12 | POM_DEVELOPER_ID=vanniktech 13 | POM_DEVELOPER_NAME=Niklas Baudy 14 | 15 | android.useAndroidX=true 16 | android.enableJetifier=false 17 | 18 | SONATYPE_HOST=DEFAULT 19 | SONATYPE_AUTOMATIC_RELEASE=true 20 | RELEASE_SIGNING_ENABLED=true 21 | 22 | org.gradle.jvmargs=-Xmx2048m 23 | 24 | android.defaults.buildfeatures.buildconfig=false 25 | android.defaults.buildfeatures.aidl=false 26 | android.defaults.buildfeatures.renderscript=false 27 | android.defaults.buildfeatures.resvalues=false 28 | android.defaults.buildfeatures.shaders=false 29 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vanniktech/espresso-utils/4b0ce2e399002b9928360752282baa06545b839d/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.1-all.zip 4 | networkTimeout=10000 5 | validateDistributionUrl=true 6 | zipStoreBase=GRADLE_USER_HOME 7 | zipStorePath=wrapper/dists 8 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | # SPDX-License-Identifier: Apache-2.0 19 | # 20 | 21 | ############################################################################## 22 | # 23 | # Gradle start up script for POSIX generated by Gradle. 24 | # 25 | # Important for running: 26 | # 27 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 28 | # noncompliant, but you have some other compliant shell such as ksh or 29 | # bash, then to run this script, type that shell name before the whole 30 | # command line, like: 31 | # 32 | # ksh Gradle 33 | # 34 | # Busybox and similar reduced shells will NOT work, because this script 35 | # requires all of these POSIX shell features: 36 | # * functions; 37 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 38 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 39 | # * compound commands having a testable exit status, especially «case»; 40 | # * various built-in commands including «command», «set», and «ulimit». 41 | # 42 | # Important for patching: 43 | # 44 | # (2) This script targets any POSIX shell, so it avoids extensions provided 45 | # by Bash, Ksh, etc; in particular arrays are avoided. 46 | # 47 | # The "traditional" practice of packing multiple parameters into a 48 | # space-separated string is a well documented source of bugs and security 49 | # problems, so this is (mostly) avoided, by progressively accumulating 50 | # options in "$@", and eventually passing that to Java. 51 | # 52 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 53 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 54 | # see the in-line comments for details. 55 | # 56 | # There are tweaks for specific operating systems such as AIX, CygWin, 57 | # Darwin, MinGW, and NonStop. 58 | # 59 | # (3) This script is generated from the Groovy template 60 | # https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 61 | # within the Gradle project. 62 | # 63 | # You can find Gradle at https://github.com/gradle/gradle/. 64 | # 65 | ############################################################################## 66 | 67 | # Attempt to set APP_HOME 68 | 69 | # Resolve links: $0 may be a link 70 | app_path=$0 71 | 72 | # Need this for daisy-chained symlinks. 73 | while 74 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 75 | [ -h "$app_path" ] 76 | do 77 | ls=$( ls -ld "$app_path" ) 78 | link=${ls#*' -> '} 79 | case $link in #( 80 | /*) app_path=$link ;; #( 81 | *) app_path=$APP_HOME$link ;; 82 | esac 83 | done 84 | 85 | # This is normally unused 86 | # shellcheck disable=SC2034 87 | APP_BASE_NAME=${0##*/} 88 | # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) 89 | APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit 90 | 91 | # Use the maximum available, or set MAX_FD != -1 to use that value. 92 | MAX_FD=maximum 93 | 94 | warn () { 95 | echo "$*" 96 | } >&2 97 | 98 | die () { 99 | echo 100 | echo "$*" 101 | echo 102 | exit 1 103 | } >&2 104 | 105 | # OS specific support (must be 'true' or 'false'). 106 | cygwin=false 107 | msys=false 108 | darwin=false 109 | nonstop=false 110 | case "$( uname )" in #( 111 | CYGWIN* ) cygwin=true ;; #( 112 | Darwin* ) darwin=true ;; #( 113 | MSYS* | MINGW* ) msys=true ;; #( 114 | NONSTOP* ) nonstop=true ;; 115 | esac 116 | 117 | CLASSPATH="\\\"\\\"" 118 | 119 | 120 | # Determine the Java command to use to start the JVM. 121 | if [ -n "$JAVA_HOME" ] ; then 122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 123 | # IBM's JDK on AIX uses strange locations for the executables 124 | JAVACMD=$JAVA_HOME/jre/sh/java 125 | else 126 | JAVACMD=$JAVA_HOME/bin/java 127 | fi 128 | if [ ! -x "$JAVACMD" ] ; then 129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 130 | 131 | Please set the JAVA_HOME variable in your environment to match the 132 | location of your Java installation." 133 | fi 134 | else 135 | JAVACMD=java 136 | if ! command -v java >/dev/null 2>&1 137 | then 138 | die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 139 | 140 | Please set the JAVA_HOME variable in your environment to match the 141 | location of your Java installation." 142 | fi 143 | fi 144 | 145 | # Increase the maximum file descriptors if we can. 146 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 147 | case $MAX_FD in #( 148 | max*) 149 | # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. 150 | # shellcheck disable=SC2039,SC3045 151 | MAX_FD=$( ulimit -H -n ) || 152 | warn "Could not query maximum file descriptor limit" 153 | esac 154 | case $MAX_FD in #( 155 | '' | soft) :;; #( 156 | *) 157 | # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. 158 | # shellcheck disable=SC2039,SC3045 159 | ulimit -n "$MAX_FD" || 160 | warn "Could not set maximum file descriptor limit to $MAX_FD" 161 | esac 162 | fi 163 | 164 | # Collect all arguments for the java command, stacking in reverse order: 165 | # * args from the command line 166 | # * the main class name 167 | # * -classpath 168 | # * -D...appname settings 169 | # * --module-path (only if needed) 170 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 171 | 172 | # For Cygwin or MSYS, switch paths to Windows format before running java 173 | if "$cygwin" || "$msys" ; then 174 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 175 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 176 | 177 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 178 | 179 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 180 | for arg do 181 | if 182 | case $arg in #( 183 | -*) false ;; # don't mess with options #( 184 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 185 | [ -e "$t" ] ;; #( 186 | *) false ;; 187 | esac 188 | then 189 | arg=$( cygpath --path --ignore --mixed "$arg" ) 190 | fi 191 | # Roll the args list around exactly as many times as the number of 192 | # args, so each arg winds up back in the position where it started, but 193 | # possibly modified. 194 | # 195 | # NB: a `for` loop captures its iteration list before it begins, so 196 | # changing the positional parameters here affects neither the number of 197 | # iterations, nor the values presented in `arg`. 198 | shift # remove old arg 199 | set -- "$@" "$arg" # push replacement arg 200 | done 201 | fi 202 | 203 | 204 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 205 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 206 | 207 | # Collect all arguments for the java command: 208 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, 209 | # and any embedded shellness will be escaped. 210 | # * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be 211 | # treated as '${Hostname}' itself on the command line. 212 | 213 | set -- \ 214 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 215 | -classpath "$CLASSPATH" \ 216 | -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \ 217 | "$@" 218 | 219 | # Stop when "xargs" is not available. 220 | if ! command -v xargs >/dev/null 2>&1 221 | then 222 | die "xargs is not available" 223 | fi 224 | 225 | # Use "xargs" to parse quoted args. 226 | # 227 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 228 | # 229 | # In Bash we could simply go: 230 | # 231 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 232 | # set -- "${ARGS[@]}" "$@" 233 | # 234 | # but POSIX shell has neither arrays nor command substitution, so instead we 235 | # post-process each arg (as a line of input to sed) to backslash-escape any 236 | # character that might be a shell metacharacter, then use eval to reverse 237 | # that process (while maintaining the separation between arguments), and wrap 238 | # the whole thing up as a single "set" statement. 239 | # 240 | # This will of course break if any of these variables contains a newline or 241 | # an unmatched quote. 242 | # 243 | 244 | eval "set -- $( 245 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 246 | xargs -n1 | 247 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 248 | tr '\n' ' ' 249 | )" '"$@"' 250 | 251 | exec "$JAVACMD" "$@" 252 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | @rem SPDX-License-Identifier: Apache-2.0 17 | @rem 18 | 19 | @if "%DEBUG%"=="" @echo off 20 | @rem ########################################################################## 21 | @rem 22 | @rem Gradle startup script for Windows 23 | @rem 24 | @rem ########################################################################## 25 | 26 | @rem Set local scope for the variables with windows NT shell 27 | if "%OS%"=="Windows_NT" setlocal 28 | 29 | set DIRNAME=%~dp0 30 | if "%DIRNAME%"=="" set DIRNAME=. 31 | @rem This is normally unused 32 | set APP_BASE_NAME=%~n0 33 | set APP_HOME=%DIRNAME% 34 | 35 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 36 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 37 | 38 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 39 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 40 | 41 | @rem Find java.exe 42 | if defined JAVA_HOME goto findJavaFromJavaHome 43 | 44 | set JAVA_EXE=java.exe 45 | %JAVA_EXE% -version >NUL 2>&1 46 | if %ERRORLEVEL% equ 0 goto execute 47 | 48 | echo. 1>&2 49 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 50 | echo. 1>&2 51 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 52 | echo location of your Java installation. 1>&2 53 | 54 | goto fail 55 | 56 | :findJavaFromJavaHome 57 | set JAVA_HOME=%JAVA_HOME:"=% 58 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 59 | 60 | if exist "%JAVA_EXE%" goto execute 61 | 62 | echo. 1>&2 63 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 64 | echo. 1>&2 65 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 66 | echo location of your Java installation. 1>&2 67 | 68 | goto fail 69 | 70 | :execute 71 | @rem Setup the command line 72 | 73 | set CLASSPATH= 74 | 75 | 76 | @rem Execute Gradle 77 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* 78 | 79 | :end 80 | @rem End local scope for the variables with windows NT shell 81 | if %ERRORLEVEL% equ 0 goto mainEnd 82 | 83 | :fail 84 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 85 | rem the _cmd.exe /c_ return code! 86 | set EXIT_CODE=%ERRORLEVEL% 87 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 88 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 89 | exit /b %EXIT_CODE% 90 | 91 | :mainEnd 92 | if "%OS%"=="Windows_NT" endlocal 93 | 94 | :omega 95 | -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "config:base", 4 | ":disableDependencyDashboard" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':espresso-core-utils' --------------------------------------------------------------------------------