Skip to content

Instantly share code, notes, and snippets.

View tugceaktepe's full-sized avatar
🏠
Working from home

Tugce Aktepe tugceaktepe

🏠
Working from home
  • Trendyol
  • Istanbul
View GitHub Profile
@tugceaktepe
tugceaktepe / UrlModule.kt
Last active June 15, 2023 19:28
UrlModule.kt
package com.aktepetugce.pagingmovieexample.di
import com.aktepetugce.pagingmovieexample.util.ApiConstants
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton
@Module
@tugceaktepe
tugceaktepe / MainActivityTest.kt
Last active June 15, 2023 19:45
Replace a binding
@UninstallModules(
UrlModule::class
)
@HiltAndroidTest
@RunWith(AndroidJUnit4::class)
class MainActivityTest {
@get:Rule
val hiltRule = HiltAndroidRule(this)
@tugceaktepe
tugceaktepe / success_response.json
Created June 15, 2023 20:03
TMDB GET Success Response
{
"page": 1,
"results": [
{
"adult": false,
"backdrop_path": "/nGxUxi3PfXDRm7Vg95VBNgNM8yc.jpg",
"genre_ids": [
28,
12,
16,
@tugceaktepe
tugceaktepe / FileReader.kt
Created June 15, 2023 20:06
FileReader for json parse
object FileReader {
fun readStringFromFile(fileName: String): String {
try {
val inputStream = (InstrumentationRegistry.getInstrumentation().targetContext
.applicationContext as HiltTestApplication).assets.open(fileName)
val builder = StringBuilder()
val reader = InputStreamReader(inputStream, "UTF-8")
reader.readLines().forEach {
builder.append(it)
}
@tugceaktepe
tugceaktepe / MainActivityTest.kt
Last active June 15, 2023 20:13
Adding mockWebServer for the first time.
@UninstallModules(
UrlModule::class
)
@HiltAndroidTest
@RunWith(AndroidJUnit4::class)
class MainActivityTest {
@get:Rule
val hiltRule = HiltAndroidRule(this)
@tugceaktepe
tugceaktepe / network_security_config.xml
Created June 15, 2023 20:30
Network security config xml file
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="@string/clear_text_config">
<trust-anchors>
<certificates src="system" />
</trust-anchors>
</base-config>
</network-security-config>
@tugceaktepe
tugceaktepe / build.gradle
Created June 15, 2023 20:33
buildTypes for network security config
buildTypes {
getByName("release") {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
resValue("string", "clear_text_config","false")
}
getByName("debug") {
@tugceaktepe
tugceaktepe / MockWebServerDispatcher.kt
Created June 15, 2023 20:57
MockWebServerDispatcher to match path while making HTTP call
import okhttp3.mockwebserver.Dispatcher
import okhttp3.mockwebserver.MockResponse
import okhttp3.mockwebserver.RecordedRequest
class MockWebServerDispatcher {
internal inner class RequestDispatcher : Dispatcher() {
override fun dispatch(request: RecordedRequest): MockResponse {
return when (request.path) {
"/movie/top_rated?api_key=${API_KEY}&language=en-US&page=1" ->
@tugceaktepe
tugceaktepe / MainActivityTest.kt
Created June 15, 2023 21:45
Add success test
@UninstallModules(
UrlModule::class
)
@HiltAndroidTest
@RunWith(AndroidJUnit4::class)
class MainActivityTest {
@get:Rule
val hiltRule = HiltAndroidRule(this)
@tugceaktepe
tugceaktepe / MainActivityTest.kt
Created June 15, 2023 21:50
Test for receiving error from api
@Test
fun showErrorWhenMovieLoadFailed() {
mockWebServer.dispatcher = MockServerDispatcher().ErrorDispatcher()
val scenario = launchActivity<MainActivity>()
onView(withText(Constants.ERROR_MESSAGE)).check(matches(isDisplayed()))
scenario.close()
}