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
@RunWith(AndroidJUnit4::class) | |
class BasicActivityTest { | |
private lateinit var mockServer: MockWebServer | |
@Rule | |
@JvmField | |
val rule = ActivityTestRule(DummyActivity::class.java, false, false) | |
@Before |
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
class DummyActivity : AppCompatActivity() { | |
// it'll be passed from TestCases | |
private val mockUrl by lazy { | |
intent?.extras?.getString(ConstantsUtil.MOCK_URL, null) | |
} | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_dummy) |
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 flask import Flask, request, jsonify | |
app = Flask(__name__) | |
# root | |
@app.route("/") | |
def index(): | |
""" | |
this is a root dir of my server | |
:return: str |
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
class APIKindaStuff { | |
interface APIService { | |
@GET("/users/{user}") | |
fun greetUser(@Path("user") user: String): Call<ResponseBody> | |
@Headers("Content-type: application/json") | |
@POST("/api/post_some_data") | |
fun getVectors(@Body body: JsonObject): Call<ResponseBody> | |
} |
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
val jsonObj = JsonObject() | |
jsonObj.addProperty("title", "rhythm") | |
jsonObj.addProperty("singer", "meee") | |
jsonObj.addProperty("text", "Jack and jill went up the hill to fetch a pail of water!") | |
// POST demo | |
APIKindaStuff | |
.service | |
.getVectors(jsonObj) | |
.enqueue(object : Callback<ResponseBody> { |
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
APIKindaStuff | |
.service | |
.greetUser("Audhil") | |
.enqueue(object : Callback<ResponseBody> { | |
override fun onFailure(call: Call<ResponseBody>, t: Throwable) { | |
println("---TTTT :: GET Throwable EXCEPTION:: " + t.message) | |
} | |
override fun onResponse(call: Call<ResponseBody>, response: Response<ResponseBody>) { | |
if (response.isSuccessful) { |
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
@Module | |
open class ApplicationModule(private val application: GDelegate) { | |
@Provides | |
@Singleton | |
fun giveContext(): Context = this.application | |
@Provides | |
@Singleton | |
fun givePackageManager(): PackageManager = application.packageManager |
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
@Singleton | |
@Component( | |
modules = [ | |
(ApplicationModule::class) | |
] | |
) | |
interface ApplicationComponent { | |
fun inject(into: GDelegate) | |
fun inject(into: BaseRepository) | |
fun inject(into: BaseViewModel) |
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
apply plugin: 'com.android.application' | |
apply plugin: 'kotlin-android' | |
apply plugin: 'kotlin-android-extensions' | |
apply plugin: 'kotlin-kapt' | |
android { | |
compileSdkVersion rootProject.compileSdkVersion |
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
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() | |
} |