Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
/.idea/*
125 changes: 0 additions & 125 deletions .idea/codeStyles/Project.xml

This file was deleted.

18 changes: 0 additions & 18 deletions .idea/gradle.xml

This file was deleted.

14 changes: 0 additions & 14 deletions .idea/misc.xml

This file was deleted.

12 changes: 0 additions & 12 deletions .idea/runConfigurations.xml

This file was deleted.

73 changes: 39 additions & 34 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

apply plugin: 'kotlin-kapt'
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-parcelize'
id 'kotlin-kapt'
}

android {
compileSdkVersion 29
compileSdkVersion 31
defaultConfig {
applicationId "com.picpay.desafio.android"
minSdkVersion 21
targetSdkVersion 29
targetSdkVersion 31
versionCode 1
versionName "1.0"

vectorDrawables.useSupportLibrary = true

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
testInstrumentationRunner "com.picpay.desafio.android.PicPayAppTestRunner"
}
buildTypes {
debug {}
Expand All @@ -29,9 +27,13 @@ android {
}
}

buildFeatures {
viewBinding true
}

compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

kotlinOptions {
Expand All @@ -42,51 +44,54 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

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

implementation "androidx.core:core-ktx:$core_ktx_version"

implementation "androidx.appcompat:appcompat:$appcompat_version"
implementation "androidx.fragment:fragment-ktx:$fragment_ktx_version"
implementation "androidx.legacy:legacy-support-v4:$legacy_support_version"
implementation "androidx.constraintlayout:constraintlayout:$constraintlayout_version"

implementation "com.google.android.material:material:$material_version"

implementation "org.koin:koin-core:$koin_version"
implementation "org.koin:koin-android:$koin_version"
implementation "org.koin:koin-androidx-viewmodel:$koin_version"
// Lifecycle dependencies
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"

implementation "com.google.dagger:dagger:$dagger_version"
kapt "com.google.dagger:dagger-compiler:$dagger_version"
implementation "com.google.code.gson:gson:$gson_version"
implementation "com.google.android.material:material:$material_version"

implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle_version"
// Koin dependencies
implementation "io.insert-koin:koin-core:$koin_version"
implementation "io.insert-koin:koin-android:$koin_version"
implementation "io.insert-koin:koin-androidx-viewmodel:$koin_version"
testImplementation "io.insert-koin:koin-test:$koin_version"

// Coroutines dependencies
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version"
testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutines_version"

implementation "io.reactivex.rxjava2:rxjava:$rxjava_version"
implementation "io.reactivex.rxjava2:rxandroid:$rxandroid_version"

implementation 'com.google.code.gson:gson:2.8.6'

// Retrofit/Network dependencies
implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
implementation "com.squareup.retrofit2:adapter-rxjava2:$retrofit_version"
implementation "com.squareup.retrofit2:converter-gson:$retrofit_version"
implementation "com.squareup.okhttp3:okhttp:$okhttp_version"
implementation "com.squareup.okhttp3:mockwebserver:$okhttp_version"

// Utils dependencies
implementation "com.squareup.picasso:picasso:$picasso_version"
implementation "de.hdodenhof:circleimageview:$circleimageview_version"

// Tests dependencies
testImplementation "junit:junit:$junit_version"
testImplementation "org.mockito:mockito-core:$mockito_version"
testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:$mockito_kotlin_version"
testImplementation "io.mockk:mockk:$mockk_version"

debugImplementation "androidx.fragment:fragment-testing:$fragment_ktx_version"
testImplementation "androidx.arch.core:core-testing:$core_testing_version"
implementation "org.koin:koin-test:$koin_version"

androidTestImplementation "androidx.test:runner:$test_runner_version"
androidTestImplementation "androidx.test.ext:junit-ktx:$test_ext_junit_ktx_version"
androidTestImplementation "androidx.test.espresso:espresso-core:$espresso_version"
androidTestImplementation "androidx.test:core-ktx:$core_ktx_test_version"
androidTestImplementation "androidx.test:runner:$test_runner_version"
androidTestImplementation "androidx.test:rules:$test_rules_version"

}
Original file line number Diff line number Diff line change
@@ -1,68 +1,31 @@
package com.picpay.desafio.android

import androidx.lifecycle.Lifecycle
import androidx.test.core.app.launchActivity
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.platform.app.InstrumentationRegistry
import okhttp3.mockwebserver.Dispatcher
import okhttp3.mockwebserver.MockResponse
import okhttp3.mockwebserver.MockWebServer
import okhttp3.mockwebserver.RecordedRequest
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.ext.junit.rules.activityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith


@RunWith(AndroidJUnit4::class)
class MainActivityTest {

private val server = MockWebServer()

private val context = InstrumentationRegistry.getInstrumentation().targetContext
@get: Rule
val rule = activityScenarioRule<MainActivity>()

@Test
fun shouldDisplayTitle() {
launchActivity<MainActivity>().apply {
val expectedTitle = context.getString(R.string.title)

moveToState(Lifecycle.State.RESUMED)

onView(withText(expectedTitle)).check(matches(isDisplayed()))
}
onView(withId(R.id.title)).check(matches(isDisplayed()))
onView(ViewMatchers.withText(R.string.title)).check(matches(isDisplayed()))
}

@Test
fun shouldDisplayListItem() {
server.dispatcher = object : Dispatcher() {
override fun dispatch(request: RecordedRequest): MockResponse {
return when (request.path) {
"/users" -> successResponse
else -> errorResponse
}
}
}

server.start(serverPort)

launchActivity<MainActivity>().apply {
// TODO("validate if list displays items returned by server")
}

server.close()
fun shouldDisplayFragmentContainer() {
onView(withId(R.id.fcvContainer)).check(matches(isDisplayed()))
}

companion object {
private const val serverPort = 8080

private val successResponse by lazy {
val body =
"[{\"id\":1001,\"name\":\"Eduardo Santos\",\"img\":\"https://randomuser.me/api/portraits/men/9.jpg\",\"username\":\"@eduardo.santos\"}]"

MockResponse()
.setResponseCode(200)
.setBody(body)
}

private val errorResponse by lazy { MockResponse().setResponseCode(404) }
}
}
Loading