This file contains 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 Activity { | |
fun selectImage() { | |
if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { | |
getImage() | |
} else { | |
askPermission() | |
} | |
} | |
private fun askPermission() { |
This file contains 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 Repository | |
class Presenter { | |
lateinit var repository: Repository by inject() | |
} | |
val module : Module = module { | |
single { Repository() } | |
} |
This file contains 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 testLoginSuccess() { | |
val loginRobot = LoginRobot() | |
loginRobot | |
.submit() | |
.assertUsernameError(R.string.required_field) | |
.assertPasswordError(R.string.required_field) | |
.inputUser("valid") | |
.submit() | |
.assertPasswordError(R.string.required_field) |
This file contains 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 ScreenRobot { | |
fun enterTextIntoView(@IdRes viewId: Int, text: String): T { | |
onView(withId(viewId)).perform(typeText(text)) | |
closeKeyboard() | |
return this as T | |
} | |
} | |
class LoginRobot { |
This file contains 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
val dispatcher = object : Dispatcher() { | |
@Throws(InterruptedException::class) | |
override fun dispatch(request: RecordedRequest): MockResponse { | |
return when { | |
request.path == "/v1/token" -> MockResponse().setResponseCode(200).setBody(getJson("json/token.json")) | |
request.path == "v1/events" -> MockResponse().setResponseCode(200).setBody(getJson("json/eventos.json")) | |
else -> MockResponse().setResponseCode(404) | |
} |
This file contains 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
lateinit var server: MockWebServer | |
@Before | |
fun setUp() { | |
server = MockWebServer() | |
server.start() | |
} | |
@Test | |
fun test() { |
This file contains 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
@Spy | |
lateinit var spyRepository: Repository |
This file contains 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
testImplementation 'com.squareup.okhttp3:mockwebserver:(insert latest version)' |
This file contains 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
@Before | |
fun setUpTest() { | |
MockitoAnnotations.initMocks(this) | |
} | |
@Test | |
fun test() { | |
Mockito.`when`(mockRepository.getList(anyInt(),anyString())).thenReturn(expectedValue) | |
presenter.loadList() | |
verify(mockView, times(1)).showLoading() |
This file contains 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
testCompile group: 'org.mockito', name: 'mockito-inline', version: '2.23.3' |