Modifying mehtod's input parameters

Aug 5, 2019

During maintenance of the legacy projects, I sometimes see constructions like: void appendFooter(Report report); or void populate(Data data); I even saw something like this: void populate(Source source, Target target); What is wrong with these statements? They’re using so called output argument. In the examples above, we’re passing a report or data variable, which usually are going to be global variables available in the scope of the whole class. These methods takes them as an argument and modify them. ...

Get rid of the list null-checks

Jul 28, 2019

During development of the legacy Java applications, we still have to deal with null. It’s possible to avoid it completly when we’re designing application from the scratch, applying proper code constructions, static code analysis and we’re consistent during code reviews. Nevertheless in majority of the cases we will encounter null in daily projects. We may even expect them in the method inputs and we have to be prepared for it. With the functional programming in Java we can deal with them in quite elegant way, but I often see people are not using features available nowadays. ...

Zen of the Java library release process

Jun 8, 2019
java, gradle

In my previous article I published information about publishing JAR/AAR library to the Maven Central Repository. A few steps of that process were automated, but a few of them were still manual. I mean closing and release process which had to be done by manual clicking on the Sonatype website. Fortunately, it’s possible to automate it. In order to do that, I used gradle-nexus-staging-plugin developed by Codearte. Thanks to this plugin I could get rid of the remaining manual steps left in the release process. ...

Publishing a JAR/AAR to the Maven Central

May 24, 2019
java, gradle

Introduction # As a Java/JVM/Android developers we rely on the work of other people through frameworks and libraries. Many of them are open-source. Most of the developers are consumers of such projects. What if we would like to create our own library and distribute it to other developers? We can always create it and share a *.jar or *.aar file with others. Drawback of such solution is the fact that source of distribution may not be trusted. ...

Creating a fat AAR

Oct 2, 2018
java, gradle, android

I recently wrote a new library called NeuroSky Android SDK. It’s used for writing Android apps using signals of the brain waves received from the NeuroSky MindWave Mobile headsets. Probably I’ll write a separate article about it because it’s quite interesting topic. This library uses ThinkGear library, which is distributed by the NeuroSky as a *.jar file, so I couldn’t use it as a Gradle or Maven dependency in my project and I had to put this *. ...

Separate execution of unit and integration tests in Gradle

Sep 22, 2018
java, gradle, testing

During development process, we often write unit and integration tests. While unit tests verify corectness of the small pieces of code, integration tests verify software as a whole project and sometimes can treat it as a black box where concrete results are expected. During development of the REST API, we can write integration tests for such API with REST Assured. Integration tests are usually slower, because they need to start the server and sometimes do other stuff. ...

Excluding generated code from JaCoCo report

Sep 18, 2018
testing, java, gradle

I recently wrote a simple java app with Dagger 2 as a DI container and Gradle as a build system. I wanted to generate unit test coverage report for this app, so I used Jacoco. In my build.gradle file I configured JaCoCo as follows: plugins { id 'jacoco' } jacocoTestReport { reports { xml.enabled = true html.enabled = true } } Now, I could type: ...

Testing exceptions

Sep 4, 2018
java, testing

In Java, we can test exceptions via unit tests in a few different ways. In this article, I’ll present common methods of doing that. Nevertheless, I suppose we there are different methods as well. First method is basically wrapping a method call with try-catch block, assigning an exception to a variable and performing appropriate assertion. In these examples, I’m using JUnit for unit tests and Truth for assertions. @Test public void shouldTestExceptionWithTryCatch() { Exception caughtException = null; try { throw new RuntimeExcetpion("message"); } catch (final Exception e) { caughtException = e; } assertThat(caughtException). ...

Writing my first library in Kotlin

Aug 19, 2018
java, kotlin, android, gradle

Introduction # Recently, I decided to create a tiny Android library called RxBattery, which is monitoring battery state of the device with RxJava and RxKotlin. I created a few Java and Android libraries already and this time I decided to use Kotlin programming language instead of Java to learn something new and write something more complicated than “Hello World” app. Here are my observations. Build System # I used Gradle to build the project. ...

Releasing ReactiveNetwork v. 1.0.0 (paying the technical debt)

Jun 24, 2018
android, java, open-source

Today, I’ve released next version of my most popular open-source project - ReactiveNetwork. I’ve released version 0.12.4 for RxJava1.x and version 1.0.0 for RxJava2.x. Please note, RxJava1.x is no longer officially supported and I’m going to follow the same approach in my RxJava-based projects. It’s not the first release of this project, but I’m breaking the API and removing existing methods, so I decided to stick to proper versioning standard. I didn’t always do it properly in the past, but it’s never too late. ...