Test Micronaut POJOs are annotated with @Introspected

I always annotate my model classes with @Introspected. It is easy to test you don't forget the annotation.

Given a POJO:

import io.micronaut.core.annotation.Introspected;
import io.micronaut.core.annotation.NonNull;

import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.time.LocalDate;

@Introspected
public class EuroExchangeResponse {

    @NonNull
    @NotNull
    private BigDecimal rate;

    @NonNull
    @NotNull
    private Currency target;

    @NonNull
    @NotNull
    private LocalDate date;

    public EuroExchangeResponse(@NonNull BigDecimal rate,
                                @NonNull Currency target,
                                @NonNull LocalDate date) {
        this.rate = rate;
        this.target = target;
        this.date = date;
    }

    // Getters & Setters
}

I write a Spock specification to verify that no exception is thrown when I attempt to retrieve the Bean Introspection:

import io.micronaut.core.beans.BeanIntrospection
import spock.lang.Specification

class EuroExchangeResponseSpec extends Specification {

    void "EuroExchangeResponse is annotated with @Introspected"() {
        when:
        BeanIntrospection.getIntrospection(EuroExchangeResponse)

        then:
        noExceptionThrown()
    }
}

Tags: #micronaut #spock #test