Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
5d0fa31
add textView, rename id
RobertaMaria Mar 13, 2022
659c906
create dependencies using koin
RobertaMaria Mar 13, 2022
fbbc274
add dependencies in the project
RobertaMaria Mar 13, 2022
44c1abd
add AppApplication
RobertaMaria Mar 13, 2022
e8fde66
project downloaded file
RobertaMaria Mar 13, 2022
f6165ba
class example downloaded from project
RobertaMaria Mar 13, 2022
0da5e8e
project downloaded files
RobertaMaria Mar 13, 2022
fe36828
rename activity
RobertaMaria Mar 13, 2022
54c2f6b
refactor class user
RobertaMaria Mar 13, 2022
e49ccd9
create database and dao
RobertaMaria Mar 13, 2022
8787f7f
create activity and adapter
RobertaMaria Mar 13, 2022
d170ff3
remove class no used
RobertaMaria Mar 13, 2022
d72f441
create viewmodel
RobertaMaria Mar 13, 2022
2561909
create class userLocal
RobertaMaria Mar 13, 2022
f7118dc
create local data source
RobertaMaria Mar 13, 2022
7f1e664
create remote data source
RobertaMaria Mar 13, 2022
ad6685d
create test
RobertaMaria Mar 13, 2022
e04a562
create repository
RobertaMaria Mar 13, 2022
90341b4
create test
RobertaMaria Mar 13, 2022
a4e74b3
Create android.yml
RobertaMaria Mar 13, 2022
b7e3802
update test
RobertaMaria Mar 13, 2022
e083e2a
extend PagingDataAdapter
RobertaMaria Mar 13, 2022
6edc45c
add constraintlayout, update dependency gradle
RobertaMaria Mar 13, 2022
83983cc
Update android.yml
RobertaMaria Mar 13, 2022
c011c97
Update android.yml
RobertaMaria Mar 14, 2022
bc2d1c5
Update android.yml
RobertaMaria Mar 14, 2022
eee92d7
Update gradlew file
RobertaMaria Mar 14, 2022
13fb409
Update android.yml
RobertaMaria Mar 14, 2022
1ea92e2
Update android.yml
RobertaMaria Mar 14, 2022
272c39a
remove CI
RobertaMaria Mar 14, 2022
75e819c
rename function
RobertaMaria Mar 14, 2022
5b0cd76
implements MockWebServer
RobertaMaria Mar 14, 2022
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
3 changes: 0 additions & 3 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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

This file was deleted.

21 changes: 21 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ android {
vectorDrawables.useSupportLibrary = true

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
//testInstrumentationRunner "com.picpay.desafio.android.user.MockTestRunner"
}
buildTypes {
debug {}
Expand Down Expand Up @@ -62,6 +63,7 @@ dependencies {
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle_version"

implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.3"
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"
Expand Down Expand Up @@ -89,4 +91,23 @@ dependencies {
androidTestImplementation "androidx.test:runner:$test_runner_version"
androidTestImplementation "androidx.test.espresso:espresso-core:$espresso_version"
androidTestImplementation "androidx.test:core-ktx:$core_ktx_test_version"

implementation 'com.squareup.okhttp3:logging-interceptor:4.9.1'

def room_version = "2.4.2"
implementation "androidx.room:room-runtime:$room_version"
kapt "androidx.room:room-compiler:2.4.2"
annotationProcessor "androidx.room:room-compiler:2.4.2"

testImplementation "io.mockk:mockk:1.11.0"

testImplementation 'org.hamcrest:hamcrest-all:1.3'

def paging_version = "3.0.0"
implementation("androidx.paging:paging-runtime:$paging_version")

androidTestImplementation 'com.jakewharton.espresso:okhttp3-idling-resource:1.0.0'

androidTestImplementation 'com.android.support.test:rules:1.0.2'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
}
8 changes: 8 additions & 0 deletions app/src/androidTest/assets/success_response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[
{
"id": 1001,
"name": "Eduardo Santos",
"img": "https://randomuser.me/api/portraits/men/9.jpg",
"username": "@eduardo.santos"
}
]
Original file line number Diff line number Diff line change
@@ -1,68 +1,63 @@
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.IdlingRegistry
import androidx.test.espresso.assertion.ViewAssertions.matches
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 androidx.test.espresso.matcher.ViewMatchers.withId
import com.jakewharton.espresso.OkHttp3IdlingResource
import com.picpay.desafio.android.ui.UserListActivity
import com.picpay.desafio.android.user.FileReader
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import okhttp3.mockwebserver.MockResponse
import okhttp3.mockwebserver.MockWebServer
import okhttp3.mockwebserver.RecordedRequest
import org.junit.After
import org.junit.Before
import org.junit.Test


class MainActivityTest {

private val server = MockWebServer()

private val context = InstrumentationRegistry.getInstrumentation().targetContext

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

moveToState(Lifecycle.State.RESUMED)
@Before
fun setUp() {
server.start(8080)
IdlingRegistry.getInstance().register(
OkHttp3IdlingResource.create(
"okhttp",
getClient()
)
)
}

onView(withText(expectedTitle)).check(matches(isDisplayed()))
}
fun getClient(): OkHttpClient {
val logging = HttpLoggingInterceptor()
logging.level = HttpLoggingInterceptor.Level.BODY
return OkHttpClient.Builder()
.addInterceptor(logging)
.build()
}


@Test
fun shouldDisplayListItem() {
server.dispatcher = object : Dispatcher() {
override fun dispatch(request: RecordedRequest): MockResponse {
return when (request.path) {
"/users" -> successResponse
else -> errorResponse
}
}
}
fun must_display_list_when_api_return_success() {
server.enqueue(
MockResponse().setResponseCode(200)
.setBody(FileReader.readStringFromFile("success_response.json"))
)

server.start(serverPort)
launchActivity<UserListActivity>().apply {
onView(withId(R.id.user_list_recyclerView)).check(matches(isDisplayed()))

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

@After
fun tearDown(){
server.close()
}

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) }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.picpay.desafio.android.user

import androidx.test.platform.app.InstrumentationRegistry

object FileReader {
fun readStringFromFile(fileName: String): String {

val assets = InstrumentationRegistry.getInstrumentation().context.assets
return assets.open(fileName).reader().readText()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.picpay.desafio.android.user

import android.app.Application
import android.content.Context
import androidx.test.runner.AndroidJUnitRunner

class MockTestRunner : AndroidJUnitRunner () {

override fun newApplication (cl: ClassLoader ?, className: String ?,
context: Context ?) : Application {
return super .newApplication(cl, UserTestApp:: class .java.name, context)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.picpay.desafio.android.user

import com.picpay.desafio.android.AppApplication
import com.picpay.desafio.android.di.URL_BASE
import com.picpay.desafio.android.di.appModules
import org.koin.android.ext.koin.androidContext
import org.koin.android.ext.koin.androidLogger
import org.koin.core.context.startKoin

class UserTestApp: AppApplication() {

override fun onCreate() {
super.onCreate()

startKoin {
androidContext(this@UserTestApp)
androidLogger()
modules(appModules)
properties(mapOf(URL_BASE to "http://localhost:8080"))

}
}

var url = "http://localhost:8080"

fun getBaseUrl () : String {
return url
}
}
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<uses-permission android:name="android.permission.INTERNET" />

<application
android:name=".AppApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
Expand All @@ -14,7 +15,7 @@
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="AllowBackup,GoogleAppIndexingWarning">
<activity android:name=".MainActivity">
<activity android:name=".ui.UserListActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
22 changes: 22 additions & 0 deletions app/src/main/java/com/picpay/desafio/android/AppApplication.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.picpay.desafio.android

import android.app.Application
import com.picpay.desafio.android.di.URL_BASE
import com.picpay.desafio.android.di.appModules
import org.koin.android.ext.koin.androidContext
import org.koin.android.ext.koin.androidLogger
import org.koin.core.context.startKoin

open class AppApplication : Application() {
override fun onCreate() {
super.onCreate()

startKoin {
androidContext(this@AppApplication)
androidLogger()
modules(appModules)
properties(mapOf(URL_BASE to "https://609a908e0f5a13001721b74e.mockapi.io/picpay/api/"))

}
}
}
Loading