aboutsummaryrefslogtreecommitdiff
path: root/value/src/it
diff options
context:
space:
mode:
authorÉamonn McManus <emcmanus@google.com>2021-06-24 13:56:13 -0700
committerGoogle Java Core Libraries <java-libraries-firehose+copybara@google.com>2021-06-24 13:57:00 -0700
commit05ea13561169d5c6c0ea6711f1b7b3eb1492920d (patch)
treeb227d4b2cef17d95e0e792c38ca469e080599284 /value/src/it
parente688dd708e2202e0ac8a00be49fca0b9bcf252df (diff)
downloadauto-05ea13561169d5c6c0ea6711f1b7b3eb1492920d.tar.gz
Ensure that AutoBuilder works with property builders.
Previously it worked, but only if the builder interface also had a setter for the property. Otherwise you would get an exception because the template referenced the `$toBuilderMethods` variable, which was undefined. RELNOTES=Fixed a bug with AutoBuilder and property builder methods. PiperOrigin-RevId: 381330964
Diffstat (limited to 'value/src/it')
-rw-r--r--value/src/it/functional/src/test/java/com/google/auto/value/AutoBuilderTest.java24
1 files changed, 24 insertions, 0 deletions
diff --git a/value/src/it/functional/src/test/java/com/google/auto/value/AutoBuilderTest.java b/value/src/it/functional/src/test/java/com/google/auto/value/AutoBuilderTest.java
index a1c4eccd..952edaac 100644
--- a/value/src/it/functional/src/test/java/com/google/auto/value/AutoBuilderTest.java
+++ b/value/src/it/functional/src/test/java/com/google/auto/value/AutoBuilderTest.java
@@ -405,6 +405,30 @@ public final class AutoBuilderTest {
}
}
+ static <T> String concatList(ImmutableList<T> list) {
+ // We're avoiding streams for now so we compile this in Java 7 mode in CompileWithEclipseTest.
+ StringBuilder sb = new StringBuilder();
+ for (T element : list) {
+ sb.append(element);
+ }
+ return sb.toString();
+ }
+
+ @AutoBuilder(callMethod = "concatList")
+ interface ConcatListCaller<T> {
+ ImmutableList.Builder<T> listBuilder();
+
+ String call();
+ }
+
+ @Test
+ public void propertyBuilderWithoutSetter() {
+ ConcatListCaller<Integer> caller = new AutoBuilder_AutoBuilderTest_ConcatListCaller<>();
+ caller.listBuilder().add(1, 1, 2, 3, 5, 8);
+ String s = caller.call();
+ assertThat(s).isEqualTo("112358");
+ }
+
static <K, V extends Number> Map<K, V> singletonMap(K key, V value) {
return Collections.singletonMap(key, value);
}