This file contains hidden or 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
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 |
This file contains hidden or 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
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) | |
} | |
} |
This file contains hidden or 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
@Inject | |
lateinit var okHttp: OkHttpClient | |
private lateinit var okHttp3IdlingResource: OkHttp3IdlingResource | |
@Before | |
fun setup() { | |
hiltRule.inject() | |
okHttp3IdlingResource = OkHttp3IdlingResource.create("okhttp", okHttp) | |
IdlingRegistry.getInstance().register(okHttp3IdlingResource) |
This file contains hidden or 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 showErrorWhenMovieLoadFailed() { | |
mockWebServer.dispatcher = MockServerDispatcher().ErrorDispatcher() | |
val scenario = launchActivity<MainActivity>() | |
onView(withText(Constants.ERROR_MESSAGE)).check(matches(isDisplayed())) | |
scenario.close() | |
} |
This file contains hidden or 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
@UninstallModules( | |
UrlModule::class | |
) | |
@HiltAndroidTest | |
@RunWith(AndroidJUnit4::class) | |
class MainActivityTest { | |
@get:Rule | |
val hiltRule = HiltAndroidRule(this) |
This file contains hidden or 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
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" -> |
This file contains hidden or 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
buildTypes { | |
getByName("release") { | |
isMinifyEnabled = false | |
proguardFiles( | |
getDefaultProguardFile("proguard-android-optimize.txt"), | |
"proguard-rules.pro" | |
) | |
resValue("string", "clear_text_config","false") | |
} | |
getByName("debug") { |
This file contains hidden or 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
<?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> |
This file contains hidden or 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
@UninstallModules( | |
UrlModule::class | |
) | |
@HiltAndroidTest | |
@RunWith(AndroidJUnit4::class) | |
class MainActivityTest { | |
@get:Rule | |
val hiltRule = HiltAndroidRule(this) |
This file contains hidden or 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
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) | |
} |