Skip to content

Commit fa6bb08

Browse files
committed
Merge branch 'master' into enable_custom_list_child_interactions
2 parents 911675d + 87cd5a7 commit fa6bb08

File tree

74 files changed

+2005
-356
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+2005
-356
lines changed

.github/FUNDING.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
custom: "https://github.com/AdevintaSpain/Barista/issues/344"

.github/ISSUE_TEMPLATE/Feature_request.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ about: Suggest an idea for this library
88

99
**Description what you'd like to happen:**
1010

11-
A clear description if the feature or behavior you'd like implemented.
11+
A clear description of the feature or behavior you'd like implemented.
1212

1313
**Example espresso code if available**
1414

.github/workflows/main.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- master
7+
push:
8+
branches:
9+
- master
10+
11+
jobs:
12+
tests:
13+
runs-on: macOS-latest
14+
15+
steps:
16+
- uses: actions/checkout@v1
17+
name: Checkout
18+
- uses: reactivecircus/android-emulator-runner@v2.11.0
19+
name: Run tests
20+
with:
21+
api-level: 28
22+
profile: Nexus 6
23+
headless: true
24+
disable-animations: true
25+
script: ./gradlew connectedCheck
26+
27+
- uses: actions/cache@v1
28+
with:
29+
path: ~/.gradle/caches
30+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }}-${{ hashFiles('**/gradle/wrapper/gradle-wrapper.properties') }}
31+
restore-keys: ${{ runner.os }}-gradle-

.travis.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,19 @@ env:
99
global:
1010
- secure: "pus/Wv/014aNnUbUDNBpAk12o3w/zEO+/0oPomdnFs5034tsUOk53VbV69qKdWGKtH8Gm9LGBL50GLjSiB9Cx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21/Mar6nKc4tj2/wEtBcwfXL0Jo4c6O1GrUanyXLh4fXxIyuetoYIqwkG6hAvshXyoe0RP6UdifWiWnyEKu5Db6JV8IzjuR1QHCbcXjtXpl7Z6JodkRMw5bQzW9rrXTybRqK+ha+p3e/d1iynhjerxzavMadqSamWv02wQYD+vmeuf58SwZcy6XJJtJZ4M6yVL8msiVpsxpX/ln1jWHFEUKwJRRxKBkTHZo="
12+
13+
before_install:
14+
- yes | sdkmanager "platforms;android-30"
15+
1216
android:
1317
components:
1418
- tools
1519
- tools
1620
- platform-tools
1721
- build-tools-28.0.3
18-
- android-29
22+
- android-30
1923
- extra
20-
- addon
24+
- add-on
2125

2226
licenses:
2327
- 'android-sdk-license-.+'

README.md

Lines changed: 49 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Barista
2-
**The guy who serves a great Espresso**
2+
**The one who serves a great Espresso**
33

4-
[![Travis](https://img.shields.io/travis/rust-lang/rust.svg?label=Travis+CI)](https://travis-ci.org/SchibstedSpain/Barista)
4+
[![Travis](https://img.shields.io/travis/rust-lang/rust.svg?label=Travis+CI)](https://travis-ci.org/github/AdevintaSpain/Barista)
55
[![Download](https://api.bintray.com/packages/schibstedspain/maven/barista/images/download.svg)](https://bintray.com/schibstedspain/maven/barista/_latestVersion)
66
[![Hex.pm](https://img.shields.io/hexpm/l/plug.svg)](LICENSE.md)
77

@@ -27,8 +27,7 @@ Barista makes developing UI test faster, easier and more predictable. Built on t
2727

2828
Import Barista as a testing dependency:
2929
```gradle
30-
androidTestImplementation('com.schibsted.spain:barista:3.2.0') {
31-
exclude group: 'com.android.support'
30+
androidTestImplementation('com.schibsted.spain:barista:3.7.0') {
3231
exclude group: 'org.jetbrains.kotlin' // Only if you already use Kotlin in your project
3332
}
3433
```
@@ -67,6 +66,11 @@ longClickOn("Next");
6766
clickMenu(R.id.menu_item);
6867
```
6968

69+
#### Open the overflow menu without clicking any item
70+
```java
71+
openMenu();
72+
```
73+
7074
#### Writing into widgets
7175
```java
7276
writeTo(R.id.edittext, "A great text");
@@ -80,13 +84,13 @@ clickListItem(R.id.list, 4);
8084
clickListItemChild(R.id.list, 3, R.id.row_button);
8185
doOnListItemChild(R.id.list, 5, R.id.edittext, replaceText("Yet another great text"));
8286
scrollListToPosition(R.id.list, 4);
83-
assertListItemCount(R.id.listId, 5)
84-
assertListNotEmpty(R.id.listId)
85-
assertDisplayedAtPosition(R.id.recycler, 0, "text");
86-
assertDisplayedAtPosition(R.id.listId, 0, R.id.text_field, "text");
87-
assertDisplayedAtPosition(R.id.recycler, 0, R.string.hello_world);
88-
assertDisplayedAtPosition(R.id.listId, 0, R.id.text_field, R.string.hello_world);
89-
assertCustomAssertionAtPosition(R.id.recycler, 0, customViewAssertion);
87+
assertListItemCount(R.id.list, 5)
88+
assertListNotEmpty(R.id.list)
89+
assertDisplayedAtPosition(R.id.list, 0, "text");
90+
assertDisplayedAtPosition(R.id.list, 0, R.id.text_field, "text");
91+
assertDisplayedAtPosition(R.id.list, 0, R.string.hello_world);
92+
assertDisplayedAtPosition(R.id.list, 0, R.id.text_field, R.string.hello_world);
93+
assertCustomAssertionAtPosition(R.id.list, 0, customViewAssertion);
9094

9195
clickSpinnerItem(R.id.spinner, 1);
9296
```
@@ -295,30 +299,31 @@ assertNotContains(R.id.textview, R.string.text);
295299

296300
#### Check text is given color
297301
```java
298-
assertTextColorIs(R.id.someRedText, R.color.red);
299-
assertTextColorIs(R.id.someColorListText, R.color.state_list);
302+
assertTextColorIs(R.id.some_red_text, R.color.red);
303+
assertTextColorIs(R.id.some_color_list_text, R.color.state_list);
300304

301305
// ...or not?
302-
assertTextColorIsNot(R.id.someRedText, R.color.blue);
303-
assertTextColorIsNot(R.id.someColorListText, R.color.another_state_list);
306+
assertTextColorIsNot(R.id.some_red_text, R.color.blue);
307+
assertTextColorIsNot(R.id.some_color_list_text, R.color.another_state_list);
304308
```
305309

306-
#### Check recyclerView item count against expected item count
307-
```java
308-
assertRecyclerViewItemCount(R.id.recycler, 10);
309-
```
310+
`assertTextColorIs` and its variant `assertTextColorIsNot` work with:
310311

311-
#### And another tricky feature
312-
```java
313-
assertThatBackButtonClosesTheApp();
314-
```
315-
#### Is this ImageView showing a drawable?
312+
- *Color int*: `Color.parse("#ff00ff")`
313+
- *Color resource*: `R.color.green`
314+
- *Color attribute*: `R.attr.colorPrimary`
315+
316+
Also Barista can check colors parsed from `declarable-style` custom attribute:
316317
```java
317-
assertHasAnyDrawable(R.id.image_view);
318-
assertHasDrawable(R.id.image_view, R.drawable.ic_barista);
318+
assertTextColorIs(R.id.customTextView, R.styleable.SampleCustomView, R.style.SampleCustomStyle, R.styleable.SampleCustomView_customColor);
319319

320320
// ...or not?
321-
assertHasNoDrawable(R.id.image_view);
321+
assertTextColorIsNot(R.id.customTextView, R.styleable.SampleCustomView, R.style.SampleCustomStyle_Green, R.styleable.SampleCustomView_customColor);
322+
```
323+
324+
#### Check recyclerView item count against expected item count
325+
```java
326+
assertRecyclerViewItemCount(R.id.recycler, 10);
322327
```
323328

324329
#### Is this ProgressBar/SeekBar progress?
@@ -328,6 +333,11 @@ assertProgressIsMin(R.id.seek_bar)
328333
assertProgressIsMax(R.id.seek_bar)
329334
```
330335

336+
#### And another tricky feature
337+
```java
338+
assertThatBackButtonClosesTheApp();
339+
```
340+
331341
### Custom assertions
332342

333343
If you have a special case not covered by the given assertions API, we encourage you to assert these special cases with our custom assertions API. It's a convenient way to replace plain `Matcher`s with complex assertions. With Barista, you can match any kind of view by knowing its type and passing its `viewId`, `text`, or a `Matcher<View>`. Once you matched it, you will be able to assert all its properties without adding any complex `Matcher` to your project.
@@ -355,10 +365,17 @@ assertAny<RadioGroup>(R.id.radioGroup, "selected option is the second one") {
355365
}
356366
```
357367

358-
## Barista’s Intents API
368+
## Mocking the Intent results
369+
370+
Mocking the Android Camera Intent is a tricky thing to do. To accomplish it in no time, Barista gives a way to do it in one line: the method `mockAndroidCamera()`. This method does all the magic to mock the result of the camera. One more thing to do: you have to call `Intents.init()` before calling `mockAndroidCamera()`, and `Intents.release()` after doing the action that launches the camera. You could also use `IntentsTestRule` instead of the common `ActivityTestRule` to skip it, but as we recommend the use of `BaristaRule`, it's easier to just call both methods manually when needed.
371+
372+
Here's an example to copy paste:
373+
359374
```java
360-
// Creates a Bitmap on a camera provided URI
375+
Intents.init();
361376
mockAndroidCamera();
377+
clickOn(R.id.launch_camera);
378+
Intents.release();
362379
```
363380

364381
## Runtime Permissions
@@ -367,6 +384,9 @@ The new Marshmallow permissions system requires checking for permissions at runt
367384
```java
368385
PermissionGranter.allowPermissionsIfNeeded(Manifest.permission.GET_ACCOUNTS);
369386
```
387+
```java
388+
PermissionGranter.allowPermissionOneTime(Manifest.permission.GET_ACCOUNTS);
389+
```
370390

371391
## Useful test rules
372392
Barista includes a set of useful test rules to help you:

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ task clean(type: Delete) {
2323
}
2424

2525
ext.minSdkVersionDeclared = 19
26-
ext.compileSdkVersionDeclared = 29
26+
ext.compileSdkVersionDeclared = 30
2727

2828
ext.supportLibVersion = '27.1.1'
2929
ext.espressoVersion = '3.0.2'
3030
ext.uiAutomatorVersion = '2.1.3'
31-
ext.baristaVersion = '3.2.0'
31+
ext.baristaVersion = '3.7.0'

gradle.properties

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
android.enableJetifier=true
21
android.useAndroidX=true
32
org.gradle.jvmargs=-Xmx1536m

library/build.gradle

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ android {
1515
lintOptions {
1616
disable 'InvalidPackage'
1717
}
18+
kotlinOptions.freeCompilerArgs += ["-module-name", "barista"]
1819
}
1920

2021
dependencies {
@@ -27,13 +28,16 @@ dependencies {
2728
implementation 'androidx.legacy:legacy-support-core-ui:1.0.0'
2829
implementation 'androidx.vectordrawable:vectordrawable-animated:1.0.0'
2930
implementation 'androidx.recyclerview:recyclerview:1.0.0'
31+
api 'androidx.viewpager2:viewpager2:1.0.0'
32+
33+
implementation 'com.google.android.material:material:1.2.0'
3034

3135
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
3236

3337
testImplementation 'junit:junit:4.12'
3438
testImplementation 'pl.pragmatists:JUnitParams:1.1.0'
3539
testImplementation 'org.assertj:assertj-core:1.7.0'
36-
testImplementation 'org.mockito:mockito-core:2.13.0'
40+
testImplementation 'org.mockito:mockito-core:2.28.2'
3741
}
3842

3943
publish {

library/src/androidTest/java/com/schibsted/spain/barista/internal/util/BitmapComparatorTest.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package com.schibsted.spain.barista.internal.util
22

3+
import android.content.Context
34
import android.graphics.BitmapFactory
4-
import androidx.test.InstrumentationRegistry
5+
import androidx.test.core.app.ApplicationProvider
56
import com.schibsted.spain.barista.test.R
67
import org.junit.Assert.assertFalse
78
import org.junit.Assert.assertTrue
@@ -11,8 +12,8 @@ class BitmapComparatorTest {
1112

1213
@Test
1314
fun returnTrueWhenComparingTheSameDrawable() {
14-
val aBitmap = BitmapFactory.decodeResource(InstrumentationRegistry.getTargetContext().resources, R.drawable.ic_barista)
15-
val theSameBitmap = BitmapFactory.decodeResource(InstrumentationRegistry.getTargetContext().resources, R.drawable.ic_barista)
15+
val aBitmap = BitmapFactory.decodeResource(ApplicationProvider.getApplicationContext<Context>().resources, R.drawable.ic_barista)
16+
val theSameBitmap = BitmapFactory.decodeResource(ApplicationProvider.getApplicationContext<Context>().resources, R.drawable.ic_barista)
1617

1718
val result = BitmapComparator.compare(aBitmap, theSameBitmap)
1819

@@ -21,8 +22,8 @@ class BitmapComparatorTest {
2122

2223
@Test
2324
fun returnFalseWhenComparingDifferentDrawables() {
24-
val aBitmap = BitmapFactory.decodeResource(InstrumentationRegistry.getTargetContext().resources, R.drawable.ic_barista)
25-
val aDifferentBitmap = BitmapFactory.decodeResource(InstrumentationRegistry.getTargetContext().resources, R.drawable.ic_launcher)
25+
val aBitmap = BitmapFactory.decodeResource(ApplicationProvider.getApplicationContext<Context>().resources, R.drawable.ic_barista)
26+
val aDifferentBitmap = BitmapFactory.decodeResource(ApplicationProvider.getApplicationContext<Context>().resources, R.drawable.ic_launcher)
2627

2728
val result = BitmapComparator.compare(aBitmap, aDifferentBitmap)
2829

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.schibsted.spain.barista.assertion
2+
3+
import android.view.View
4+
import androidx.annotation.IdRes
5+
import com.google.android.material.chip.ChipGroup
6+
import com.schibsted.spain.barista.assertion.BaristaAssertions.assertAny
7+
8+
object BaristaChipAssertions {
9+
10+
@JvmStatic
11+
fun assertAnyChipSelected(@IdRes viewId: Int) {
12+
assertAny<ChipGroup>(viewId) {
13+
it.checkedChipId != View.NO_ID
14+
}
15+
}
16+
}

0 commit comments

Comments
 (0)