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 / Dockerfile
Created June 18, 2023 10:47
Android SDK Setup in Docker image
FROM example-registry.company-domain.com/image/openjdk:11
ENV ANDROID_COMPILE_SDK=33
ENV ANDROID_BUILD_TOOLS=33.0.0
ENV ANDROID_SDK_TOOLS=6514223
ENV EMULATOR_VERSION=24
SHELL ["/bin/bash", "-c"]
RUN apt-get --quiet update --yes
@tugceaktepe
tugceaktepe / MockWebServerDispatcher.kt
Created June 15, 2023 22:34
throttleBody example
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" ->
MockResponse().setResponseCode(200)
.setBody(FileReader.readStringFromFile("success_response.json"))
.throttleBody(1024, 200L, TimeUnit.MILLISECONDS)
else -> MockResponse().setResponseCode(400)
}
}
@tugceaktepe
tugceaktepe / MainActivityTest.kt
Created June 15, 2023 22:29
OkHttp3IdlingResource usage in a UI test
@Inject
lateinit var okHttp: OkHttpClient
private lateinit var okHttp3IdlingResource: OkHttp3IdlingResource
@Before
fun setup() {
hiltRule.inject()
okHttp3IdlingResource = OkHttp3IdlingResource.create("okhttp", okHttp)
IdlingRegistry.getInstance().register(okHttp3IdlingResource)
@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()
}
@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 / 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 / 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 / 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 / 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 / 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)
}