In this article, we will talk about Kotlin Coroutines, more specifically, about Flow. Probably the best way to understand it is by using a sample, we will explain how to use it with Firebase Realtime Database.
Before start is essential to make a small introduction: as you know Kotlin coroutines is the new Kotlin way to write asynchronous non-blocking code, you can implement it in various ways with different kinds of operators, the most common implementation is to invoke a suspend function and wait for a result, with Flow the game is different, because it allows us to create a…
It has been passed months since my last article on Kotlin coroutines lifecycle, and one year since an article about unit testing and mocking technique. Today I’m here to speak again about Unit Test focused on the mocking with the Kotlin library Mockk .
In object-oriented programming, mock objects are simulated objects that mimic the behaviour of real objects in controlled ways, most often as part of a software testing initiative
In this article I will not explain how to write a Unit Testing, I take it for granted, but I will explain how to use the mocking with same…
How to create a scheduled job (like a Unix Cron job) and execute it with the Google Firebase Functions.
On this blog, you are used to reading articles about Android, Kotlin, JUnit, etc, but today I want to talk about: Cloud Functions and Cloud Scheduler, two services that you can find inside the Google Cloud Services suite.
Cloud Functions for Firebase is a serverless framework that lets you automatically run backend code in response to events triggered by Firebase features and HTTPS requests. It’s server-less so you don’t need a remote server to host them and you pay only the…
I have just written an article about Kotlin Coroutines but now I want to go deep the topic of Coroutine Scope. What’s its lifecycle and the behavior of jobs.
When we launch a coroutine we need a Context to run it: a CoroutineScope. This one works like a RXJava Scheduler but it has many other features defined by four parameters listed below:
In these article we will understand how implement the new Kotlin coroutines and how test them with MockK library. I use these code in an Android project, but the principles are generic for all Kotlin project.
If you worked in past with RXJava you should understand the concept of Scheduler, a dispatcher is something of similar and the
CoroutineScope works in the same way to garante a scoping of function.
A scope controls…
I love Kotlin, when i have started to write application with it i said, “wow cool”, it’s clean, it’s easy to read (sometimes 😁) and helps you to create a better code, but when i have started to write tests I encountered some problems.
In this article i will help you to solve these troubles and how mock a unit test.
To explain how test a ViewModel with Mockito I have created a sample application to fetch the user’s repositories list, to do that i have create a ViewModel that use a Retrofit API to get data and a LiveData…
From the past Google IO 2017 we having a new set of tools called Android Architecture Components, I have just spoken about one of them (Room) in a past article, today i want to speak about the ViewModel.
I will not write what is a ViewModel, there are many articles about it, in this article i will explain how integrate it with Dagger without boilerplate code, and how create a scalable way to manage your ViewModel Factory with Multibindings.
To instantiate a ViewModel you need a ViewModelFactory: it’s a class that implements ViewModelProvider.Factory …
After Google I/O 2017 Kotlin is ufficially supported by Google, so in these months i have starting to code in Kotlin for work, the language is really cool, many feature are very useful, other strange, but allow you to have a clean code and easy to read.
The first thing i have noticed are the nullable variables, Kotlin forces you to valorize them to prevent “The Billion Dollar Mistake”, if a variable is not valorized you can manage it in different ways.
With these syntax is as we put the NonNull annotation and the variable cannot be NULL …
During the Google IO 2017 was showed the Android Architecture Components, in this libraries set we can find Room, Room is an ORM created by Google that allow Developers to create a SQL Lite database without boilerplate code but with fiew annotations, the rest of code is auto-generated by Android Studio.
I will not explained how use Room, the web is full of these articles, i will only show how use it with Dagger 2, and how inject DAO and Room dabatase instance.
I’ll assume that you already know how Dependency Injection works, and how create Entity and Dao in…
In DBFlow Part 1 we have seen how create a database and how populate it with tables, also we have explained what kind of data types exists and how manage them.
In this second part we will see how create relation one-to-one and one-to-many to add child elements in our data models, and finally we will see how to query too.
With DBFlow we can create two type of relations, the firsts is a single relation one-to-one where our data model has a child element saved inside an another table, this relation will be create by a foreign key, that…