Skip to content

Instantly share code, notes, and snippets.

View Audhil's full-sized avatar
🎯
Focusing

Mohammed Audhil Audhil

🎯
Focusing
View GitHub Profile
@RunWith(AndroidJUnit4::class)
class BasicActivityTest {
private lateinit var mockServer: MockWebServer
@Rule
@JvmField
val rule = ActivityTestRule(DummyActivity::class.java, false, false)
@Before
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)
from flask import Flask, request, jsonify
app = Flask(__name__)
# root
@app.route("/")
def index():
"""
this is a root dir of my server
:return: str
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>
}
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> {
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) {
@Module
open class ApplicationModule(private val application: GDelegate) {
@Provides
@Singleton
fun giveContext(): Context = this.application
@Provides
@Singleton
fun givePackageManager(): PackageManager = application.packageManager
@Singleton
@Component(
modules = [
(ApplicationModule::class)
]
)
interface ApplicationComponent {
fun inject(into: GDelegate)
fun inject(into: BaseRepository)
fun inject(into: BaseViewModel)
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion rootProject.compileSdkVersion
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()
}