AssertJ cheatsheet

Update: This post is now available at a new location:
https://blog.ngeor.com/2018/04/22/assertj-cheatsheet.html

AssertJ is a an assertions library for unit tests in Java that is well worth considering. Here are some examples.

Continue reading AssertJ cheatsheet

Advertisements

Using swagger code generator with maven

Update: This post is now available at a new location:
https://blog.ngeor.com/2018/04/21/using-swagger-code-generator-with-maven.html

Following up the previous post about swagger, in this post I’m using the maven plugin version of swagger code generator.

Continue reading Using swagger code generator with maven

Copy InputStream to OutputStream

Update: This post is now available at a new location:
https://blog.ngeor.com/2018/04/21/copy-inputstream-to-outputstream.html

To copy from a stream into a file:

import java.nio.file.Files;
import java.nio.file.Path;

Files.copy(inputStream, path);

To copy from a stream into another stream, assuming you’re using Spring:

import org.springframework.util.StreamUtils;

StreamUtils.copy(inputStream, outputStream);

Swagger Formats

Update: This post is now available at a new location:
https://blog.ngeor.com/2018/04/21/swagger-formats.html

Some handy format combinations with Swagger:

type: string
format: byte
Creates a property of type byte[] (but it is serialized as a string).

type: integer
format: int64
Creates a property of type Long.

type: string
format: date-time
Creates a property of type OffsetDateTime (when using the java8 date library).

type: string
format: date
Creates a property of type LocalDate.

Exclude class from JaCoCo coverage

Update: This post is now available at a new location:
https://blog.ngeor.com/2018/04/21/exclude-class-from-jacoco-coverage.html

JaCoCo’s exclude configuration works with classes, so the .class extension is relevant in specifying the path.

Example:


<plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <version>0.8.1</version>
    <configuration>
        <excludes>
            <exclude>com/acme/models/Spring*</exclude>

            <exclude>com/acme/api/*Api.class</exclude>

            <exclude>com/acme/generated/**/*</exclude>

        </excludes>
    </configuration>