Why the question “Where are you from” makes us uncomfortable.

Many of us have experienced the question “Where are you from?” during the everyday conversations which are totally normal to ask/hear and we hear it every day.

Last month when I was traveling in Austria, It happened to me multiple times when hanging out in locals, someone approaching me and asking my name and where I am from. But yesterday, I had a quite interesting experience when I was hanging out in a local event in Germany and talking to a group of random people.

squidward_whereareyoufrom Continue reading Why the question “Where are you from” makes us uncomfortable.


Unit testing Android LiveData using Espresso with Kotlin? Not a mess anymore!

After searching a lot about how to test the live data returned by Room DAOs for unit testing, I found it would be a good idea to share it with other people. The language is Kotlin and I am using Robolectric to mock the context; But here, I just focus on the problem itself and I’m not gonna explain how to write the tests. You can of course check the links provided in the text.


I also have to mention that there are also other workarounds to achieve this, like using Mockito, but honestly in my opinion, this was the most clean approach. But if you prefer those ones, good luck with that. 😊


What did I want to do? Check if the LiveData objects returned by a DAO method are correct; And to have 100% test coverage on those files. 😉

What I did? Created a Kotlin extension function for LiveData object in my test class to block the main thread and wait for the observer to call onChange method and return the value. How? Using CountdownLatch. Read the answer to this Stack Overflow post.

private fun <T> LiveData<T>.blockingObserve(): T? {

    var value: T? = null
    val latch = CountDownLatch(1)
    val observer = Observer<T> {

        t ->
        value = t


    latch.await(2, TimeUnit.SECONDS)
    return value

The Problem: Although CountDownLatch is used to block the thread and wait for the value, but it would not block the thread and the value was always null. This is probably because of LiveData’s main feature which is usually being used in the main thread and obviously, it is not supposed to block the main thread, never!

Solution: Well, that’s pretty easy! You just need to add this rule to your test class:

val rule = InstantTaskExecutorRule()

It will allow the liveData observer to block the main thread and Viola!

Just don’t forget to add the core-testing dependency which is part of the Architecture library to your project and also match its version to the version of your current Architecture library that you’re using and everything will work like a charm:

testImplementation "android.arch.core:core-testing:1.1.1"

The answer to this post on StackOverflow also explains it.

Now the tests should work fine and as a reminder, I am running the tests as Local Unit Tests using Robolectric and not as Android Instrumented tests.

Good Luck Unit Testing 😊

New Site Migration

The old blog is now migrated to wordpress.com as a  casual weblog. 😎 –NEAT!
The old posts may seem a little bit unorganized since the last website was using the self-hosted version of WordPress with many plugins to support different languages and blah blah! 😀  Why am I keeping such content cram? Just in case I’m gonna miss my old posts about Assembly x86 code and the whole NOOB-ish content I wrote back then. (As well as some of my students in my university workshops when I was their Teaching Assistant!).

So I hope you accept my apology. 🙂 Thank you. And now that I’m a free human being from all those WordPress self-hosted stuff, I’m gonna focus only on posting Android-Dev related content. So whenever there’s something to say about the beautiful and colorful world of Android Development, I’ll post it here with NO hesitation!

It’s gonna be fun, guys. So please don’t hesitate to share your opinions with me. 👍