Skip to content

Commit

Permalink
test(processor): add prove that records are supported by the differen…
Browse files Browse the repository at this point in the history
…t strategies
  • Loading branch information
JoranVanBelle authored and jonas-grgt committed May 16, 2024
1 parent 94e4403 commit f978c25
Show file tree
Hide file tree
Showing 7 changed files with 199 additions and 33 deletions.
33 changes: 0 additions & 33 deletions processor/src/test/java/io/jonasg/bob/RecordsTest.java

This file was deleted.

51 changes: 51 additions & 0 deletions processor/src/test/java/io/jonasg/bob/StrategyTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {

Expand Down Expand Up @@ -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();
}
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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) {
}
Original file line number Diff line number Diff line change
@@ -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<String> make = ValidatableField.ofNoneNullableField("make", "RecordsAreBuildable");

private final ValidatableField<Integer> year = ValidatableField.ofNoneNullableField("year", "RecordsAreBuildable");

private final ValidatableField<Double> engineSize = ValidatableField.ofNoneNullableField("engineSize", "RecordsAreBuildable");

private final ValidatableField<Boolean> isElectric = ValidatableField.ofNoneNullableField("isElectric", "RecordsAreBuildable");

private final ValidatableField<Float> 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());
}
}
Original file line number Diff line number Diff line change
@@ -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) {
}

0 comments on commit f978c25

Please sign in to comment.