Exploring the Android build process: Caching

One of my last tasks @ASOS was to investigate the slow build speeds of the Android application. This post is part of a short series about how we approached the problem, what we tried and what we found out. To be clear, don’t expect miracles and 🦄 here, but you’ll get a better understanding of what you can do to optimise your builds.
read more

Use custom Hamcrest Matchers to level-up your tests

Ideally automated tests should be predictable, isolated and precise, allowing you to find an issue quickly. If these conditions are met, you’ll never have to change a test unless to accommodate a changed requirement. This sounds great on paper, but in practice we often forget the isolated bit and start testing multiple things in a single test. If abused, we’ll end up with tests that need updating all the time, causing developer frustration and wasting time.

One tool that can help with isolation of tests is using matchers. As the name suggests, matchers allow you to match an object agains certain conditions.
read more

Managing the Content Security Policy on Jenkins

Many Jenkins plugins require changes to the default Content Security Policy (or CSP) to work correctly. A refresher on what CSP is and why you should care about it can be found HERE and HERE. If you use a hosted Jenkins installation, you’ll probably need to contact your service provider to do the necessary changes for you. However if you have a self-managed installation, please read on.
read more

Updating Mockito to mock Kotlin classes

With the exponentially increasing usage of Kotlin these days, many developers face the issue of how to test the newly created Kotlin classes. As we know all classes and methods are final be default in Kotlin, unless specifically open-ed. Unfortunately Mockito, one of the most popular mocking libraries for Java projects, can’t easily mock final classes. Since we don’t want to open up everything just for testing purposes, we need another solution.

Hadi Hariri highlighted in his excellent blog post that Mockito version 2.1.0 and above can perform the magic of mocking final classes. Since mocking is something used only in tests … and usually it just works, we’ve neglected Mockito and were still using a very outdated version (1.10.19) in our project. There were a few pain-points while updating to the latest one, so hopefully this post will save you some time when going through the same process.
read more

Simple RxJava mistakes and how to avoid them

1. Observable creation and error handling

Consider the following example:

public Observable<Book> getFavoriteBook(User user) {
	return Observable.just(user.getFavoriteBookId())
                .flatMap(bookId -> bookService.getById(bookId))
                .onErrorReturn(throwable -> DEFAULT_FAVORITE_BOOK);
}

Focus on the error handling part. In my experience in 95% of the cases the expectation behind the statement .onErrorReturn(...); is to ensure that the method getFavoriteBook() is “safe”, e.g. that an exception cannot be thrown from it at all, as if it was surrounded by a giant try-catch.

read more