diff --git a/processor/src/test/java/io/jonasg/bob/RecordsTest.java b/processor/src/test/java/io/jonasg/bob/RecordsTest.java deleted file mode 100644 index 640ed79..0000000 --- a/processor/src/test/java/io/jonasg/bob/RecordsTest.java +++ /dev/null @@ -1,33 +0,0 @@ -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 org.junit.jupiter.api.condition.EnabledForJreRange; -import org.junit.jupiter.api.condition.JRE; - -import java.util.List; - -public class RecordsTest { - - @Test - @EnabledForJreRange(min = JRE.JAVA_12, disabledReason = "Records do not exist yet") - public void recordsAreBuildableWithStepwise() { - 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/java/io/jonasg/bob/StrategyTests.java b/processor/src/test/java/io/jonasg/bob/StrategyTests.java index cbfe7b4..00d7cd2 100644 --- a/processor/src/test/java/io/jonasg/bob/StrategyTests.java +++ b/processor/src/test/java/io/jonasg/bob/StrategyTests.java @@ -8,6 +8,8 @@ import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.EnabledForJreRange; +import org.junit.jupiter.api.condition.JRE; public class StrategyTests { @Nested @@ -116,6 +118,27 @@ void customFactoryMethodName() { .executeTest(); } + @Test + @EnabledForJreRange(min = JRE.JAVA_12, disabledReason = "Records do not exist yet") + void recordsAreBuildable() { + Cute.blackBoxTest() + .given() + .processors(List.of(BuildableProcessor.class)) + .andSourceFiles( + "/tests/Strategies/Strict/RecordsAreBuildable/RecordsAreBuildable.java") + .whenCompiled() + .thenExpectThat() + .compilationSucceeds() + .andThat() + .generatedSourceFile( + "io.jonasg.bob.test.RecordsAreBuildableBuilder") + .matches( + CuteApi.ExpectedFileObjectMatcherKind.BINARY, + JavaFileObjectUtils.readFromResource( + "/tests/Strategies/Strict/RecordsAreBuildable/Expected_RecordsAreBuildableBuilder.java")) + .executeTest(); + } + @Nested class AllowNulls { @@ -319,5 +342,33 @@ void setterWithCustomPrefix() { "/tests/Strategies/StepWise/SetterWithCustomPrefix/Expected_DefaultSetterWithCustomPrefixBuilder.java")) .executeTest(); } + + @Test + @EnabledForJreRange(min = JRE.JAVA_12, disabledReason = "Records do not exist yet") + void recordsAreBuildable() { + Cute.blackBoxTest() + .given() + .processors(List.of(BuildableProcessor.class)) + .andSourceFiles( + "tests/Strategies/StepWise/RecordsAreBuildable/RecordsAreBuildable.java") + .whenCompiled() + .thenExpectThat() + .compilationSucceeds() + .andThat() + .generatedSourceFile( + "io.jonasg.bob.test.RecordsAreBuildableBuilder") + .matches( + CuteApi.ExpectedFileObjectMatcherKind.BINARY, + JavaFileObjectUtils.readFromResource( + "tests/Strategies/StepWise/RecordsAreBuildable/Expected_RecordsAreBuildableBuilder.java")) + .andThat() + .generatedSourceFile( + "io.jonasg.bob.test.DefaultRecordsAreBuildableBuilder") + .matches( + CuteApi.ExpectedFileObjectMatcherKind.BINARY, + JavaFileObjectUtils.readFromResource( + "tests/Strategies/StepWise/RecordsAreBuildable/Expected_DefaultRecordsAreBuildableBuilder.java")) + .executeTest(); + } } } diff --git a/processor/src/test/resources/tests/Strategies/StepWise/RecordsAreBuildable/Expected_DefaultRecordsAreBuildableBuilder.java b/processor/src/test/resources/tests/Strategies/StepWise/RecordsAreBuildable/Expected_DefaultRecordsAreBuildableBuilder.java new file mode 100644 index 0000000..9a267c4 --- /dev/null +++ b/processor/src/test/resources/tests/Strategies/StepWise/RecordsAreBuildable/Expected_DefaultRecordsAreBuildableBuilder.java @@ -0,0 +1,47 @@ +package io.jonasg.bob.test; + +import java.lang.String; + +public final class DefaultRecordsAreBuildableBuilder implements RecordsAreBuildableBuilder.BuildStep, RecordsAreBuildableBuilder.EngineSizeStep, RecordsAreBuildableBuilder.IsElectricStep, RecordsAreBuildableBuilder.YearStep, RecordsAreBuildableBuilder.FuelEfficiencyStep, RecordsAreBuildableBuilder { + private String make; + + private int year; + + private double engineSize; + + private boolean isElectric; + + private float fuelEfficiency; + + public DefaultRecordsAreBuildableBuilder() { + } + + public DefaultRecordsAreBuildableBuilder make(String make) { + this.make = make; + return this; + } + + public DefaultRecordsAreBuildableBuilder year(int year) { + this.year = year; + return this; + } + + public DefaultRecordsAreBuildableBuilder engineSize(double engineSize) { + this.engineSize = engineSize; + return this; + } + + public DefaultRecordsAreBuildableBuilder isElectric(boolean isElectric) { + this.isElectric = isElectric; + return this; + } + + public DefaultRecordsAreBuildableBuilder 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/Strategies/StepWise/RecordsAreBuildable/Expected_RecordsAreBuildableBuilder.java b/processor/src/test/resources/tests/Strategies/StepWise/RecordsAreBuildable/Expected_RecordsAreBuildableBuilder.java new file mode 100644 index 0000000..28bfbd1 --- /dev/null +++ b/processor/src/test/resources/tests/Strategies/StepWise/RecordsAreBuildable/Expected_RecordsAreBuildableBuilder.java @@ -0,0 +1,31 @@ +package io.jonasg.bob.test; + +import java.lang.String; + +public interface RecordsAreBuildableBuilder { + static RecordsAreBuildableBuilder newBuilder() { + return new DefaultRecordsAreBuildableBuilder(); + } + + YearStep make(String make); + + interface BuildStep { + RecordsAreBuildable build(); + } + + interface FuelEfficiencyStep { + BuildStep fuelEfficiency(float fuelEfficiency); + } + + interface IsElectricStep { + FuelEfficiencyStep isElectric(boolean isElectric); + } + + interface EngineSizeStep { + IsElectricStep engineSize(double engineSize); + } + + interface YearStep { + EngineSizeStep year(int year); + } +} diff --git a/processor/src/test/resources/tests/Strategies/StepWise/RecordsAreBuildable/RecordsAreBuildable.java b/processor/src/test/resources/tests/Strategies/StepWise/RecordsAreBuildable/RecordsAreBuildable.java new file mode 100644 index 0000000..f0b6dcc --- /dev/null +++ b/processor/src/test/resources/tests/Strategies/StepWise/RecordsAreBuildable/RecordsAreBuildable.java @@ -0,0 +1,10 @@ +package io.jonasg.bob.test; + +import io.jonasg.bob.Buildable; +import io.jonasg.bob.Strategy; + +import java.lang.String; + +@Buildable(strategy = Strategy.STEP_WISE) +public record RecordsAreBuildable(String make, int year, double engineSize, boolean isElectric, float fuelEfficiency) { +} \ No newline at end of file diff --git a/processor/src/test/resources/tests/Strategies/Strict/RecordsAreBuildable/Expected_RecordsAreBuildableBuilder.java b/processor/src/test/resources/tests/Strategies/Strict/RecordsAreBuildable/Expected_RecordsAreBuildableBuilder.java new file mode 100644 index 0000000..40ed811 --- /dev/null +++ b/processor/src/test/resources/tests/Strategies/Strict/RecordsAreBuildable/Expected_RecordsAreBuildableBuilder.java @@ -0,0 +1,52 @@ +package io.jonasg.bob.test; + +import io.jonasg.bob.ValidatableField; +import java.lang.Boolean; +import java.lang.Double; +import java.lang.Float; +import java.lang.Integer; +import java.lang.String; + +public final class RecordsAreBuildableBuilder { + private final ValidatableField make = ValidatableField.ofNoneNullableField("make", "RecordsAreBuildable"); + + private final ValidatableField year = ValidatableField.ofNoneNullableField("year", "RecordsAreBuildable"); + + private final ValidatableField engineSize = ValidatableField.ofNoneNullableField("engineSize", "RecordsAreBuildable"); + + private final ValidatableField isElectric = ValidatableField.ofNoneNullableField("isElectric", "RecordsAreBuildable"); + + private final ValidatableField fuelEfficiency = ValidatableField.ofNoneNullableField("fuelEfficiency", "RecordsAreBuildable"); + + public RecordsAreBuildableBuilder() { + } + + public RecordsAreBuildableBuilder make(String make) { + this.make.set(make); + return this; + } + + public RecordsAreBuildableBuilder year(int year) { + this.year.set(year); + return this; + } + + public RecordsAreBuildableBuilder engineSize(double engineSize) { + this.engineSize.set(engineSize); + return this; + } + + public RecordsAreBuildableBuilder isElectric(boolean isElectric) { + this.isElectric.set(isElectric); + return this; + } + + public RecordsAreBuildableBuilder fuelEfficiency(float fuelEfficiency) { + this.fuelEfficiency.set(fuelEfficiency); + return this; + } + + public RecordsAreBuildable build() { + return new RecordsAreBuildable(make.orElseThrow(), year.orElseThrow(), engineSize.orElseThrow(), isElectric.orElseThrow(), fuelEfficiency.orElseThrow()); + } +} diff --git a/processor/src/test/resources/tests/Strategies/Strict/RecordsAreBuildable/RecordsAreBuildable.java b/processor/src/test/resources/tests/Strategies/Strict/RecordsAreBuildable/RecordsAreBuildable.java new file mode 100644 index 0000000..e7d745b --- /dev/null +++ b/processor/src/test/resources/tests/Strategies/Strict/RecordsAreBuildable/RecordsAreBuildable.java @@ -0,0 +1,8 @@ +package io.jonasg.bob.test; + +import io.jonasg.bob.Buildable; +import io.jonasg.bob.Strategy; + +@Buildable(strategy = Strategy.STRICT) +public record RecordsAreBuildable(String make, int year, double engineSize, boolean isElectric, float fuelEfficiency) { +}