Java

Testing Java Spring Boot Microservices

Testing Java Spring Boot Microservices

Tests are an essential part of our codebase. At the very least, they minimize the risk of regression when we modify our code. There are several types of tests, and each has a specific role: unit tests, integration tests, component tests, contract tests and end-to-end tests. Therefore, it is crucial to understand the role of each type of test to leverage its potential.

This article describes a strategy to use them to test Java Spring Boot microservices. It presents each type of test’s role, scope, and tooling.

Continue reading
Setup a Circuit Breaker with Hystrix, Feign Client and Spring Boot

Setup a Circuit Breaker with Hystrix, Feign Client and Spring Boot

In a microservices architecture, several things could go wrong. For example, a middleware, the network or the service you want to contact could be down. In this world of uncertainty, you have to anticipate problems to avoid breaking the entire chain and throwing an error to the end-user when you could offer a partially degraded service instead.

This article aims to show how to implement the circuit breaker pattern using Hystrix, Feign Client and Spring Boot.

Continue reading
Refactoring Conditional Structures with Map

Refactoring Conditional Structures with Map

I often encounter pieces of code that look like this:

public class Day {
  public void start(Weather weather) {
    switch(weather) {
      case RAINY:
          takeAnUmbrella();
          break;
      case SUNNY:
          takeAHat();
          break;
      case STORMY:
          stayHome();
          break;
      default:
          doNothing();
          break;
    }
  }
}

Here, a specific action must be taken depending on the weather. This kind of code is pretty hard to test and maintain. This short article aims to refactor it using a Map.

Continue reading
Gérer les dépendances circulaires

Gérer les dépendances circulaires

Durant mon travail, j’ai rencontré des dépendances circulaires dans une application sur laquelle je suis intervenue. Dans sa plus simple forme, il s’agit de deux classes qui dépendent l’une de l’autre. Ceci est, selon moi, un problème pour plusieurs raisons. L’objectif de cet article est de montrer ce qu’est une dépendance circulaire, en quoi cela peut poser problème, et comment les éliminer.

Continue reading