diff options
author | ronshapiro <ronshapiro@google.com> | 2016-08-19 13:23:38 -0700 |
---|---|---|
committer | Éamonn McManus <eamonn@mcmanus.net> | 2016-08-29 17:21:56 -0700 |
commit | 1fececc3116d66f67af520a46681e5eed66eea02 (patch) | |
tree | 661f1cb12700441bb5bb368714681435ca8412f9 /factory/src/test | |
parent | ac41c11d4232c532604aa9df0e5a477e1835ed2c (diff) | |
download | auto-1fececc3116d66f67af520a46681e5eed66eea02.tar.gz |
Allow varargs on @AutoFactory methods
Github: Fixes google/auto#326
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=130784801
Diffstat (limited to 'factory/src/test')
3 files changed, 76 insertions, 0 deletions
diff --git a/factory/src/test/java/com/google/auto/factory/processor/AutoFactoryProcessorTest.java b/factory/src/test/java/com/google/auto/factory/processor/AutoFactoryProcessorTest.java index bf172bc0..58228ee4 100644 --- a/factory/src/test/java/com/google/auto/factory/processor/AutoFactoryProcessorTest.java +++ b/factory/src/test/java/com/google/auto/factory/processor/AutoFactoryProcessorTest.java @@ -387,4 +387,12 @@ public class AutoFactoryProcessorTest { JavaFileObjects.forResource( "expected/MultipleFactoriesConflictingParameterNamesFactory.java")); } + + @Test public void factoryVarargs() { + assertThat(JavaFileObjects.forResource("good/SimpleClassVarargs.java")) + .processedWith(new AutoFactoryProcessor()) + .compilesWithoutError() + .and() + .generatesSources(JavaFileObjects.forResource("expected/SimpleClassVarargsFactory.java")); + } } diff --git a/factory/src/test/resources/expected/SimpleClassVarargsFactory.java b/factory/src/test/resources/expected/SimpleClassVarargsFactory.java new file mode 100644 index 00000000..e8b13161 --- /dev/null +++ b/factory/src/test/resources/expected/SimpleClassVarargsFactory.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2016 Google, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package tests; + +import com.google.auto.factory.internal.Preconditions; +import javax.annotation.Generated; +import javax.inject.Inject; + +@Generated( + value = "com.google.auto.factory.processor.AutoFactoryProcessor", + comments = "https://github.com/google/auto/tree/master/factory" +) +final class SimpleClassVarargsFactory implements SimpleClassVarargs.InterfaceWithVarargs { + @Inject SimpleClassVarargsFactory() {} + + SimpleClassVarargs create(String... args) { + return new SimpleClassVarargs(Preconditions.checkNotNull(args, 1)); + } + + @Override + public SimpleClassVarargs build(String... args) { + return create(args); + } +} diff --git a/factory/src/test/resources/good/SimpleClassVarargs.java b/factory/src/test/resources/good/SimpleClassVarargs.java new file mode 100644 index 00000000..125f35eb --- /dev/null +++ b/factory/src/test/resources/good/SimpleClassVarargs.java @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2016 Google, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package tests; + +import com.google.auto.factory.AutoFactory; + +@AutoFactory(implementing = SimpleClassVarargs.InterfaceWithVarargs.class) +final class SimpleClassVarargs { + private final String[] args; + + SimpleClassVarargs(String... args) { + this.args = args; + } + + interface InterfaceWithVarargs { + SimpleClassVarargs build(String... args); + } +} |