Home » Archives for Rafal Borowiec

Author Archives: Rafal Borowiec

Software developer, Team Leader, Agile practitioner, occasional blogger, lecturer. Open Source enthusiast, quality oriented and open-minded.

Parameterized tests in JavaScript with Jest

Parameterized tests are used to test the same code under different conditions. One can set up a test method that retrieves data from a data source. This data source can be a collection of objects, external file or maybe even a database. The general idea is to make it easy to test different conditions with the same test method to ...

Read More »

Testing promise rejection in JavaScript with Jest

The code Let’s consider a simple function that returns a Promise that can either resolve or reject depending on the value ofthe first argument: export default function promiseMe(result, timeout = 1000) { return new Promise((resolve, reject) => { setTimeout(() => { if (result instanceof Error || result.startsWith("Error")) { reject(result) } else { resolve(result) } }, timeout) }) } While testing ...

Read More »

Testing exceptions in JavaScript with Jest

The code Let’s consider a simple function that checks for equality of two passwords, and it throws an error when the first one is not provided: export default function samePasswordsValidator(password, otherPassword) { if (!password) { throw new Error("no password given"); } return password === otherPassword; } Try-catch idiom (bad) When testing the code that throws exceptions, one immediately comes up ...

Read More »

Convert time unit to duration in Java

java.util.concurrent.TimeUnit represents time durations in Java at a given unit of granularity and provides utility methods to convert across units. java.util.concurrent.TimeUnit was introduced back in the old Java days (1.5) but since then it has been extended several times already. In this blog post you will learn how to use java.util.concurrent.TimeUnit to convert a given time unit to a duration ...

Read More »

Switch as an expression in Java with Lambda-like syntax

As of Java 14, the switch expression has an additional Lambda-like (case ... -> labels) syntax and it can be used not only as a statement, but also as an expression that evaluates to a single value. Lambda-like syntax (case ... -> labels) With the new Lambda-like sytax, if a label is matched, then only the expression or statement to ...

Read More »

Record type in Java

JDK 14, released in March 2020, introduced records (preview language feature) which provide a compact syntax for declaring classes whose main purpose is to hold data. In records, all low-level, repetitive and error-prone code is like constructors, accessor and utlity methods such as equals(), hashCode(), toString() are automatically derived based on the record’s state description. Prerequisites You will need JDK ...

Read More »

Spring Boot tests with Testcontainers and PostgreSQL, MySQL or MariaDB

Testcontainers is a Java library that allows integrating Docker containers in JUnit tests with ease. In a Containerized World, there is little sense to complicate the tests configuration with embedded databases and services. Instead, use run your services in Docker and let the Testcontainers manage this for you. In this blog post you will learn how to configure Testcontainers to ...

Read More »

Docker Compose for Spring Boot application with PostgreSQL

In this blog post you will learn how to configure Spring Boot application with PostgreSQL for running with Docker Compose. This blog post covers: Spring Boot application Dockerfile configuration with clean separation between dependencies and resourcesDocker Compose configuration for running the application with PostgreSQL Prerequisites DockerJava 13Terminalhttpie (or curl) Application Generate the Maven based Spring Boot application with Spring Web, ...

Read More »

Deploy Quarkus application to AWS Elastic Beanstalk

java-interview-questions-answers

Elastic Beanstalk allows deploying and managing applications in the AWS Cloud without having to learn about the infrastructure that runs those applications. With Elastic Beanstalk you can run a website, web application, or web API that serves HTTP requests but you can also run a worker applications for running long tasks. The Elastic Beanstalk supports several preconfigured platforms including Go, ...

Read More »