diff --git a/blackbox-test-records/src/main/java/io/avaje/recordbuilder/test/Address.java b/blackbox-test-records/src/main/java/io/avaje/recordbuilder/test/Address.java index b93272e..c3e20d6 100644 --- a/blackbox-test-records/src/main/java/io/avaje/recordbuilder/test/Address.java +++ b/blackbox-test-records/src/main/java/io/avaje/recordbuilder/test/Address.java @@ -2,11 +2,18 @@ import io.avaje.recordbuilder.RecordBuilder; -@RecordBuilder +@RecordBuilder(getters = true) public record Address( String line1, String line2, String city, String country ) { + + /** + * Return a new builder for Address + */ + public static AddressBuilder builder() { + return AddressBuilder.builder(); + } } diff --git a/blackbox-test-records/src/main/java/io/avaje/recordbuilder/test/Order.java b/blackbox-test-records/src/main/java/io/avaje/recordbuilder/test/Order.java index 0018433..1ea4cf9 100644 --- a/blackbox-test-records/src/main/java/io/avaje/recordbuilder/test/Order.java +++ b/blackbox-test-records/src/main/java/io/avaje/recordbuilder/test/Order.java @@ -11,7 +11,15 @@ public record Order( List lines ) { + /** + * Return a new builder for Order + */ public static OrderBuilder builder() { return OrderBuilder.builder(); } + + public static OrderBuilder from(Order source) { + return OrderBuilder.builder(source); + } + } diff --git a/blackbox-test-records/src/test/java/io/avaje/recordbuilder/test/AddressTest.java b/blackbox-test-records/src/test/java/io/avaje/recordbuilder/test/AddressTest.java new file mode 100644 index 0000000..a11bb82 --- /dev/null +++ b/blackbox-test-records/src/test/java/io/avaje/recordbuilder/test/AddressTest.java @@ -0,0 +1,25 @@ +package io.avaje.recordbuilder.test; + +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.*; + +class AddressTest { + + @Test + void hasGetter() { + + var builder = Address.builder() + .line1("1") + .line2("2"); + + assertThat(builder.line1()).isEqualTo("1"); + assertThat(builder.line2()).isEqualTo("2"); + + Address address = builder.build(); + + assertThat(address.line1()).isEqualTo("1"); + assertThat(address.line2()).isEqualTo("2"); + } +} \ No newline at end of file diff --git a/blackbox-test-records/src/test/java/io/avaje/recordbuilder/test/OrderTest.java b/blackbox-test-records/src/test/java/io/avaje/recordbuilder/test/OrderTest.java index a7e5eee..664adc4 100644 --- a/blackbox-test-records/src/test/java/io/avaje/recordbuilder/test/OrderTest.java +++ b/blackbox-test-records/src/test/java/io/avaje/recordbuilder/test/OrderTest.java @@ -24,5 +24,12 @@ void build() { assertThat(order.id()).isEqualTo(42); //assertThat(order.lines()).isEmpty(); + + Order fromOrder = Order.from(order) + .id(95) + .build(); + + assertThat(fromOrder.id()).isEqualTo(95); + assertThat(fromOrder.customer()).isSameAs(order.customer()); } } \ No newline at end of file