New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create base tests #1
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I add only small cosmetic changes! really good job bro.
|
||
RecyclerViewInteraction.onRecyclerView<SuperHero>(withId(R.id.recycler_view)) | ||
.withItems(superHeroes) | ||
.check({ (name), view, e -> matches(hasDescendant(withText(name))).check(view, e) }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like use exception instead e, but it is not important.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replaced
|
||
RecyclerViewInteraction.onRecyclerView<SuperHero>(withId(R.id.recycler_view)) | ||
.withItems(superHeroes) | ||
.check({ (name), view, e -> matches(hasDescendant(withText(name))).check(view, e) }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is name between parenthesis?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a neat trick: https://kotlinlang.org/docs/reference/multi-declarations.html
We are basically destructuring the data class: (name, photo, isAvenger, description)
~=[iff 3 last properties are ignored] (name, _, _, _)
~= (name)
|
||
@Test | ||
fun doesNotShowAvengersBadgeIfASuperHeroIsNotPartOfTheAvengersTeam() { | ||
val superHeroes = givenThereAreSomeSuperHeroes(ANY_NUMBER_OF_SUPER_HEROES, false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
by default is false no? you don't need set this false arg.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is the default value, we are just making it explicit what we want. To me, removing the flag would mean we don't really care if they are avengers or not (I'm adding a name to the parameter to make that clear though)
} | ||
|
||
private fun givenThereAreSomeAvengers(numberOfAvengers: Int): List<SuperHero> = | ||
givenThereAreSomeSuperHeroes(numberOfAvengers, true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if I didn't remember bad in the screenshot tests, you use named arguments, like avengers = true. should be a good idea if we make it too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I'm going to make it explicit here too, good catch! 👌
|
||
private fun givenThereAreSomeSuperHeroes(numberOfSuperHeroes: Int = ANY_NUMBER_OF_SUPER_HEROES, avengers: Boolean = false): List<SuperHero> { | ||
val superHeroes = LinkedList<SuperHero>() | ||
for (i in 0 until numberOfSuperHeroes) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in screenshot superhero we used IntRange(0, numberOfSuperHeroes - 1).map { id -> /**/} instead the for, I don't konw if you llike it or not. I more or less de same, but more kotlin stye.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure
on(repository.getAllSuperHeroes()).thenReturn(emptyList<SuperHero>()) | ||
} | ||
|
||
companion object { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are we going to add companion objects in the top of the class or in the bottom?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep it at the top of the classes just because 👍
|
||
@After | ||
fun tearDown() { | ||
val idlingResources = IdlingRegistry.getInstance().resources |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you remove this code?
|
||
@Test | ||
fun doesNotShowAvengersBadgeIfSuperHeroIsNotPartOfTheAvengersTeam() { | ||
val superHero = givenThereIsASuperHero(false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you prefer use named arguments?
} | ||
|
||
fun check(assertion: (item: A, view: View, e: NoMatchingViewException?) -> Unit): RecyclerViewInteraction<A> { | ||
for (i in items.indices) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and use iitems.indices.forEach ??
return this | ||
} | ||
|
||
companion object { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the same questions about companion objects, only for define a standard :)
…oks like it's inclusive :P
117cf0a
to
9c1d426
Compare
🌀 Git merge message