From 9cf5ff9eebed52d1767de15e93fd955d4b1003de Mon Sep 17 00:00:00 2001 From: Joran Van Belle Date: Wed, 24 Apr 2024 20:05:05 +0200 Subject: [PATCH] chore(processor): add test for record support --- .github/workflows/maven.yml | 3 +- .../test/java/io/jonasg/bob/RecordsTest.java | 30 ++++++++++++ .../Expected_RecordsAreBuildable.java | 47 +++++++++++++++++++ .../RecordsAreBuildable.java | 8 ++++ 4 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 processor/src/test/java/io/jonasg/bob/RecordsTest.java create mode 100644 processor/src/test/resources/tests/RecordsAreBuildable/Expected_RecordsAreBuildable.java create mode 100644 processor/src/test/resources/tests/RecordsAreBuildable/RecordsAreBuildable.java diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 2c9ab5b..7a853cf 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -30,4 +30,5 @@ jobs: distribution: 'temurin' cache: maven - name: Build with Maven - run: mvn -B -ntp verify --file pom.xml \ No newline at end of file + if: ${{ matrix.java }} == 11 + run: mvn -B -ntp verify -Dtest=\!RecordsTest.java --file pom.xml \ No newline at end of file diff --git a/processor/src/test/java/io/jonasg/bob/RecordsTest.java b/processor/src/test/java/io/jonasg/bob/RecordsTest.java new file mode 100644 index 0000000..1ed1d32 --- /dev/null +++ b/processor/src/test/java/io/jonasg/bob/RecordsTest.java @@ -0,0 +1,30 @@ +package io.jonasg.bob; + +import io.toolisticon.cute.Cute; +import io.toolisticon.cute.CuteApi; +import io.toolisticon.cute.JavaFileObjectUtils; +import org.junit.jupiter.api.Test; + +import java.util.List; + +public class RecordsTest { + + @Test + public void recordsAreBuildable() { + Cute.blackBoxTest() + .given() + .processors(List.of(BuildableProcessor.class)) + .andSourceFiles("/tests/RecordsAreBuildable/RecordsAreBuildable.java") + .whenCompiled() + .thenExpectThat() + .compilationSucceeds() + .andThat() + .generatedSourceFile("io.jonasg.bob.test.RecordsAreBuildableBuilder") + .matches( + CuteApi.ExpectedFileObjectMatcherKind.BINARY, + JavaFileObjectUtils.readFromResource( + "/tests/RecordsAreBuildable/Expected_RecordsAreBuildable.java")) + .executeTest(); + } + +} diff --git a/processor/src/test/resources/tests/RecordsAreBuildable/Expected_RecordsAreBuildable.java b/processor/src/test/resources/tests/RecordsAreBuildable/Expected_RecordsAreBuildable.java new file mode 100644 index 0000000..4fbc9d6 --- /dev/null +++ b/processor/src/test/resources/tests/RecordsAreBuildable/Expected_RecordsAreBuildable.java @@ -0,0 +1,47 @@ +package io.jonasg.bob.test; + +import java.lang.String; + +public final class RecordsAreBuildableBuilder { + private String make; + + private int year; + + private double engineSize; + + private boolean isElectric; + + private float fuelEfficiency; + + public RecordsAreBuildableBuilder() { + } + + public RecordsAreBuildableBuilder make(String make) { + this.make = make; + return this; + } + + public RecordsAreBuildableBuilder year(int year) { + this.year = year; + return this; + } + + public RecordsAreBuildableBuilder engineSize(double engineSize) { + this.engineSize = engineSize; + return this; + } + + public RecordsAreBuildableBuilder isElectric(boolean isElectric) { + this.isElectric = isElectric; + return this; + } + + public RecordsAreBuildableBuilder fuelEfficiency(float fuelEfficiency) { + this.fuelEfficiency = fuelEfficiency; + return this; + } + + public RecordsAreBuildable build() { + return new RecordsAreBuildable(make, year, engineSize, isElectric, fuelEfficiency); + } +} diff --git a/processor/src/test/resources/tests/RecordsAreBuildable/RecordsAreBuildable.java b/processor/src/test/resources/tests/RecordsAreBuildable/RecordsAreBuildable.java new file mode 100644 index 0000000..21c9d4e --- /dev/null +++ b/processor/src/test/resources/tests/RecordsAreBuildable/RecordsAreBuildable.java @@ -0,0 +1,8 @@ +package io.jonasg.bob.test; + +import io.jonasg.bob.Buildable; +import java.lang.String; + +@Buildable +public record RecordsAreBuildable(String make, int year, double engineSize, boolean isElectric, float fuelEfficiency) { +} \ No newline at end of file