Skip to content

Instantly share code, notes, and snippets.

View Audhil's full-sized avatar
🎯
Focusing

Mohammed Audhil Audhil

🎯
Focusing
View GitHub Profile
@Audhil
Audhil / TestAPIModule.kt
Created August 23, 2020 17:02
instrumentation tests - Test equivalent of app module
@Module
@InstallIn(ApplicationComponent::class)
class TestAPIModule {
@Provides
fun giveRetrofitAPIService(): API =
Retrofit.Builder()
.baseUrl("http://localhost:8080/")
// .baseUrl("http://127.0.0.1:8080") // this too works
.addConverterFactory(MoshiConverterFactory.create())
@Audhil
Audhil / build.gradle
Created August 23, 2020 16:54
instrumentation tests - app/build.gradle
android {
...
defaultConfig {
...
testInstrumentationRunner "com.example.newsapp.runner.NewsRunner"
...
}
}
@Audhil
Audhil / NewsRunner.kt
Created August 23, 2020 16:50
instrumentation tests - custom runner
class NewsRunner : AndroidJUnitRunner() {
override fun newApplication(
cl: ClassLoader?,
className: String?,
context: Context?
): Application {
return super.newApplication(cl, HiltTestApplication::class.java.name, context)
}
}
@Audhil
Audhil / build.gradle
Created August 23, 2020 16:44
instrumention tests dependencies - app/build.gradle
dependencies {
...
// For instrumented tests.
androidTestImplementation 'com.google.dagger:hilt-android-testing:2.28-alpha'
kaptAndroidTest 'com.google.dagger:hilt-android-compiler:2.28-alpha'
androidTestImplementation "io.mockk:mockk-android:1.9.3"
androidTestImplementation "com.squareup.okhttp3:mockwebserver:4.6.0"
...
}
@Audhil
Audhil / balParenthesis.java
Created August 23, 2020 11:16
check is it given string is balanced parenthesis?!
public static void main(String[] args) {
HashMap<Character, Character> map = new HashMap<>();
map.put('(', ')');
map.put('{', '}');
map.put('[', ']');
String ipString = "{[}]";
System.out.println(isBalancedParenthesis(map, ipString));
}
@Audhil
Audhil / bxUbx.java
Created August 20, 2020 19:11
wrapper classes - (auto)boxing & (auto)unboxing
public static void main(String[] args) {
int i = 10;
Integer ii = new Integer(i); // boxing - putting primitive type in wrapper classes
Integer iii = i; // auto-boxing - putting primitive type in wrapper classes
int j = ii.intValue(); // unboxing - getting primitive type from wrapper classes
int jj = iii; // auto-unboxing - gettingg primitive types from wrapper classes
System.out.println(i);
System.out.println(ii);
@Audhil
Audhil / operatorOverLoading.kt
Last active August 18, 2020 19:53
kotlin operator overloading - ref: https://kotlinlang.org/docs/reference/operator-overloading.html to find allowed operators to overload
fun main() {
val bluePen = Pen(inkColor = "Blue")
bluePen.showInkColor()
val blackPen = Pen(inkColor = "Black")
blackPen.showInkColor()
val blueBlackPen = bluePen + blackPen
blueBlackPen.showInkColor()
}
@Audhil
Audhil / dataClassDemo.kt
Last active August 17, 2020 15:55
data class in kotlin demo - auto implemented equals(), hashcode(), and toString() methods. special function copy() make new reference or new object when data modified
fun main() {
val emp1 = Employee(name = "audhil", id = 33)
val emp2 = Employee(name = "audhil", id = 33)
if (emp1 == emp2) {
println("equal")
} else
println("not equal")
println(emp1.hashCode())
@Audhil
Audhil / DummyActivity.kt
Created August 14, 2020 16:46
app to display - current time in different timezones - keeping this for reference
// based on http://www.theappguruz.com/blog/android-time-zone-demo
class DummyActivity : Activity() {
private var spinnerAvailableID: Spinner? = null
private var current: Calendar? = null
private var textTimeZone: TextView? = null
private var txtCurrentTime: TextView? = null
private var txtTimeZoneTime: TextView? = null
private var miliSeconds: Long = 0
private var idAdapter: ArrayAdapter<String>? = null
@Audhil
Audhil / DummyActivity.kt
Created August 14, 2020 16:46
app to display - current time in different timezones - keeping this for reference
// based on http://www.theappguruz.com/blog/android-time-zone-demo
class DummyActivity : Activity() {
private var spinnerAvailableID: Spinner? = null
private var current: Calendar? = null
private var textTimeZone: TextView? = null
private var txtCurrentTime: TextView? = null
private var txtTimeZoneTime: TextView? = null
private var miliSeconds: Long = 0
private var idAdapter: ArrayAdapter<String>? = null