Skip to content

Instantly share code, notes, and snippets.

🎯
Focusing

Mohammed Audhil Audhil

🎯
Focusing
Block or report user

Report or block Audhil

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View AppRepositoryInjectTest.kt
class AppRepositoryInjectTest {
@Inject
lateinit var appAPIs: AppAPIs
@Before
fun setUp() {
val component = DaggerTestAppComponent.builder()
.applicationModule(TestApplicationModule(GDelegate()))
.build()
View TestAppComponent.kt
@Singleton
@Component(
modules = [
(ApplicationModule::class)
]
)
interface TestAppComponent : ApplicationComponent {
fun into(appRepositoryTest: AppRepositoryInjectNamedTest)
fun into(appRepositoryTest: AppRepositoryInjectTest)
fun into(baseTest: BaseTest)
View TestApplicationModule.kt
class TestApplicationModule(delegate: GDelegate) : ApplicationModule(delegate) {
override fun giveAppAPIs(): AppAPIs = mockk()
override fun giveRetrofitService(okHttpClient: OkHttpClient): AppAPIs = mockk()
override fun giveOkHttpClient(loggingInterceptor: HttpLoggingInterceptor): OkHttpClient = mockk()
override fun giveLoggingInterceptor(): HttpLoggingInterceptor = mockk()
}
View build.gradle
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion rootProject.compileSdkVersion
View ApplicationComponent.kt
@Singleton
@Component(
modules = [
(ApplicationModule::class)
]
)
interface ApplicationComponent {
fun inject(into: GDelegate)
fun inject(into: BaseRepository)
fun inject(into: BaseViewModel)
View ApplicationModule.kt
@Module
open class ApplicationModule(private val application: GDelegate) {
@Provides
@Singleton
fun giveContext(): Context = this.application
@Provides
@Singleton
fun givePackageManager(): PackageManager = application.packageManager
View somefile.kt
class MainActivity : AppCompatActivity() {
@Inject lateinit var info: Info
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
DaggerMagicBox.create().poke(this)
text_view.text = info.text
}
View gist:0570c90fa9dc56b0e67b1f9cfd6b6d98
# development way
if __name__ == '__main__':
app.run()
## server on http://127.0.0.1:5000/
## (invisible across the network) won't work on other device, other than development machine
# suggested way
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)
View BasicActivityTest.kt
@RunWith(AndroidJUnit4::class)
class BasicActivityTest {
private lateinit var mockServer: MockWebServer
@Rule
@JvmField
val rule = ActivityTestRule(DummyActivity::class.java, false, false)
@Before
View MockServerDispatcher.kt
class MockServerDispatcher {
// response dispatcher
class ResponseDispatcher : Dispatcher() {
override fun dispatch(request: RecordedRequest): MockResponse {
if (request.path.equals("/todos/1", true))
return MockResponse().setResponseCode(200).setBody(
"{\n" +
" \"id\" : 1,\n" +
" \"title\" : \"delectus aut autem\",\n" +
You can’t perform that action at this time.