This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| object SelectsActions { | |
| fun logout() { | |
| onView(allOf(withId(R.id.login_button), withText(R.string.logout))).perform(click()) | |
| } | |
| fun login() { | |
| onView(allOf(withId(R.id.login_button), withText(R.string.login))).perform(click()) | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| infix fun User.selects(block: SelectsActions.() -> Unit): User { | |
| block.invoke(SelectsActions) | |
| return this | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| user selects { login() } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| infix fun Any.given(block: () -> Unit) = block.invoke() | |
| infix fun Any.whenever(block: () -> Unit) = block.invoke() | |
| infix fun Any.then(block: () -> Unit) = block.invoke() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Test | |
| fun logsInWhenUserSelectsLogin() { | |
| given { | |
| user has { loggedOut() } | |
| } whenever { | |
| user launches { | |
| app() | |
| } selects { | |
| login() | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * Copyright 2017 Shazam Entertainment Limited | |
| * | |
| * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. | |
| * | |
| * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | |
| * | |
| * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. | |
| */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class SomeCustomView : View(...) { | |
| private val picasso by viewDependency { picasso() } | |
| fun bindData(imageUrl: String) { | |
| picasso.load(imageUrl).into(...) | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class SomeCustomView : View(...) { | |
| private val picasso by viewDependency { picasso() } | |
| ... | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class SomeCustomView @JvmOverloads constructor(context: Context, | |
| attrs: AttributeSet? = null, | |
| defStyleAttr: Int = 0) | |
| : View(context, attrs, defStyleAttr) { | |
| private val picasso by viewDependency { picasso() } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fun <T> View.viewDependency(initializer: () -> T): ViewDependency<T> = | |
| if (isInEditMode) { | |
| EditModeViewDependency(this, initializer) | |
| } else { | |
| ImmediateViewDependency(initializer) | |
| } |
NewerOlder