├── .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.