Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(processor): replace CI JRE condition by Junit conditions #37

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,5 @@ jobs:
java-version: ${{ matrix.java }}
distribution: 'temurin'
cache: maven
- name: Build with Java 11
if: ${{ matrix.java == 11 }}
run: mvn -B -ntp verify -Dtest=\!RecordsTest.java --file pom.xml

- name: Build with Java higher than 11
if: ${{ matrix.java > 11 }}
- name: Build with Maven
run: mvn -B -ntp verify --file pom.xml
27 changes: 27 additions & 0 deletions processor/src/test/java/io/jonasg/bob/BobTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

import java.util.List;

import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;

import io.toolisticon.cute.Cute;
import io.toolisticon.cute.CuteApi;
import io.toolisticon.cute.JavaFileObjectUtils;
import org.junit.jupiter.api.condition.EnabledForJreRange;
import org.junit.jupiter.api.condition.JRE;

public class BobTests {

Expand Down Expand Up @@ -240,4 +243,28 @@ void allPublicSettersThatHaveCorrespondingFieldsAreBuildable() {
"/tests/AllPublicSettersThatHaveCorrespondingFieldsAreBuildable/Expected_AllPublicSettersThatHaveCorrespondingFieldsAreBuildable.java"))
.executeTest();
}

@Nested
@EnabledForJreRange(min = JRE.JAVA_12, disabledReason = "Records do not exist yet")
class RecordTests {

@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();
}

}
}
30 changes: 0 additions & 30 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) {
}