aboutsummaryrefslogtreecommitdiff
path: root/factory/src/test
diff options
context:
space:
mode:
authorsameb <sameb@google.com>2015-01-22 16:13:20 -0800
committerChristian Edward Gruber <cgruber@google.com>2015-02-02 13:47:07 -0800
commite0e2394ec33cb3d58e39fa142f138fefd517b1a3 (patch)
tree52f88844034479804b6cf56c528a7b6a201a996d /factory/src/test
parentdbd841562137595e365ccf2ad1524ecfdee958c9 (diff)
downloadauto-e0e2394ec33cb3d58e39fa142f138fefd517b1a3.tar.gz
Don't make autofactories final based on a new "allowSubclasses" parameter.
------------- Created by MOE: http://code.google.com/p/moe-java MOE_MIGRATED_REVID=84575988
Diffstat (limited to 'factory/src/test')
-rw-r--r--factory/src/test/java/com/google/auto/factory/processor/AutoFactoryProcessorTest.java32
-rw-r--r--factory/src/test/resources/bad/MixedFinals.java27
-rw-r--r--factory/src/test/resources/expected/ConstructorAnnotatedNonFinalFactory.java45
-rw-r--r--factory/src/test/resources/expected/SimpleClassNonFinalFactory.java28
-rw-r--r--factory/src/test/resources/good/ConstructorAnnotatedNonFinal.java29
-rw-r--r--factory/src/test/resources/good/SimpleClassNonFinal.java21
6 files changed, 182 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 d1341292..8c88c1bc 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
@@ -41,6 +41,15 @@ public class AutoFactoryProcessorTest {
.and().generatesSources(JavaFileObjects.forResource("expected/SimpleClassFactory.java"));
}
+ @Test public void simpleClassNonFinal() {
+ assert_().about(javaSource())
+ .that(JavaFileObjects.forResource("good/SimpleClassNonFinal.java"))
+ .processedWith(new AutoFactoryProcessor())
+ .compilesWithoutError()
+ .and().generatesSources(
+ JavaFileObjects.forResource("expected/SimpleClassNonFinalFactory.java"));
+ }
+
@Test public void publicClass() {
assert_().about(javaSource())
.that(JavaFileObjects.forResource("good/PublicClass.java"))
@@ -98,6 +107,15 @@ public class AutoFactoryProcessorTest {
JavaFileObjects.forResource("expected/ConstructorAnnotatedFactory.java"));
}
+ @Test public void constructorAnnotatedNonFinal() {
+ assert_().about(javaSource())
+ .that(JavaFileObjects.forResource("good/ConstructorAnnotatedNonFinal.java"))
+ .processedWith(new AutoFactoryProcessor())
+ .compilesWithoutError()
+ .and().generatesSources(
+ JavaFileObjects.forResource("expected/ConstructorAnnotatedNonFinalFactory.java"));
+ }
+
@Test public void simpleClassImplementingMarker() {
assert_().about(javaSource())
.that(JavaFileObjects.forResource("good/SimpleClassImplementingMarker.java"))
@@ -125,6 +143,20 @@ public class AutoFactoryProcessorTest {
JavaFileObjects.forResource("expected/MixedDepsImplementingInterfacesFactory.java"));
}
+ @Test public void failsWithMixedFinals() {
+ JavaFileObject file = JavaFileObjects.forResource("bad/MixedFinals.java");
+ assert_().about(javaSource())
+ .that(file)
+ .processedWith(new AutoFactoryProcessor())
+ .failsToCompile()
+ .withErrorContaining(
+ "Cannot mix allowSubclasses=true and allowSubclasses=false in one factory.")
+ .in(file).onLine(25).atColumn(3)
+ .and().withErrorContaining(
+ "Cannot mix allowSubclasses=true and allowSubclasses=false in one factory.")
+ .in(file).onLine(26).atColumn(3);
+ }
+
@Test public void failsOnGenericClass() {
JavaFileObject file = JavaFileObjects.forResource("bad/GenericClass.java");
assert_().about(javaSource())
diff --git a/factory/src/test/resources/bad/MixedFinals.java b/factory/src/test/resources/bad/MixedFinals.java
new file mode 100644
index 00000000..da7130a6
--- /dev/null
+++ b/factory/src/test/resources/bad/MixedFinals.java
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2013 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 javax.annotation.Generated;
+
+import com.google.auto.factory.AutoFactory;
+import com.google.auto.factory.Provided;
+
+final class MixedFinals {
+ @AutoFactory(allowSubclasses = false) MixedFinals() {}
+ @AutoFactory(allowSubclasses = true) MixedFinals(String s) {}
+ @AutoFactory(allowSubclasses = true) MixedFinals(String s, Integer i) {}
+}
diff --git a/factory/src/test/resources/expected/ConstructorAnnotatedNonFinalFactory.java b/factory/src/test/resources/expected/ConstructorAnnotatedNonFinalFactory.java
new file mode 100644
index 00000000..e5017abd
--- /dev/null
+++ b/factory/src/test/resources/expected/ConstructorAnnotatedNonFinalFactory.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2013 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 javax.annotation.Generated;
+import javax.inject.Inject;
+import javax.inject.Provider;
+
+@Generated("com.google.auto.factory.processor.AutoFactoryProcessor")
+class ConstructorAnnotatedNonFinalFactory {
+ private final Provider<Object> objProvider;
+
+ @Inject ConstructorAnnotatedNonFinalFactory(Provider<Object> objProvider) {
+ this.objProvider = objProvider;
+ }
+
+ ConstructorAnnotatedNonFinal create() {
+ return new ConstructorAnnotatedNonFinal();
+ }
+
+ ConstructorAnnotatedNonFinal create(String s) {
+ return new ConstructorAnnotatedNonFinal(s);
+ }
+
+ ConstructorAnnotatedNonFinal create(int i) {
+ return new ConstructorAnnotatedNonFinal(objProvider.get(), i);
+ }
+
+ ConstructorAnnotatedNonFinal create(char c) {
+ return new ConstructorAnnotatedNonFinal(objProvider.get(), c);
+ }
+}
diff --git a/factory/src/test/resources/expected/SimpleClassNonFinalFactory.java b/factory/src/test/resources/expected/SimpleClassNonFinalFactory.java
new file mode 100644
index 00000000..ec5c8fb8
--- /dev/null
+++ b/factory/src/test/resources/expected/SimpleClassNonFinalFactory.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2013 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 javax.annotation.Generated;
+import javax.inject.Inject;
+
+@Generated("com.google.auto.factory.processor.AutoFactoryProcessor")
+class SimpleClassNonFinalFactory {
+ @Inject SimpleClassNonFinalFactory() {}
+
+ SimpleClassNonFinal create() {
+ return new SimpleClassNonFinal();
+ }
+}
diff --git a/factory/src/test/resources/good/ConstructorAnnotatedNonFinal.java b/factory/src/test/resources/good/ConstructorAnnotatedNonFinal.java
new file mode 100644
index 00000000..7bc5d0a6
--- /dev/null
+++ b/factory/src/test/resources/good/ConstructorAnnotatedNonFinal.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2013 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 javax.annotation.Generated;
+
+import com.google.auto.factory.AutoFactory;
+import com.google.auto.factory.Provided;
+
+final class ConstructorAnnotatedNonFinal {
+ @AutoFactory(allowSubclasses = true) ConstructorAnnotatedNonFinal() {}
+ ConstructorAnnotatedNonFinal(Object obj) {}
+ @AutoFactory(allowSubclasses = true) ConstructorAnnotatedNonFinal(String s) {}
+ @AutoFactory(allowSubclasses = true) ConstructorAnnotatedNonFinal(@Provided Object obj, int i) {}
+ @AutoFactory(allowSubclasses = true) ConstructorAnnotatedNonFinal(@Provided Object obj, char c) {}
+}
diff --git a/factory/src/test/resources/good/SimpleClassNonFinal.java b/factory/src/test/resources/good/SimpleClassNonFinal.java
new file mode 100644
index 00000000..d552ab98
--- /dev/null
+++ b/factory/src/test/resources/good/SimpleClassNonFinal.java
@@ -0,0 +1,21 @@
+/*
+ * Copyright (C) 2013 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(allowSubclasses = true)
+final class SimpleClassNonFinal {}