diff options
author | Christian Edward Gruber <cgruber@google.com> | 2014-07-18 16:03:42 -0700 |
---|---|---|
committer | Christian Edward Gruber <cgruber@google.com> | 2014-07-18 16:22:45 -0700 |
commit | e9523204728838a3b9380e1cd908fcad4596d9d0 (patch) | |
tree | 1dfff96c130fef546b10daceb0b0e185fef9ce56 /common/src/test | |
parent | 4874fbf0c227a62a90af31f37ad2753e6a0adf80 (diff) | |
download | auto-e9523204728838a3b9380e1cd908fcad4596d9d0.tar.gz |
Automated g4 rollback of changelist 70831442.
*** Reason for rollback ***
Broke tests
*** Original change description ***
Add a utility that does quick, superficial validation on elements to ensure that all type information is present while running a processor.
***
-------------
Created by MOE: http://code.google.com/p/moe-java
MOE_MIGRATED_REVID=70836339
Diffstat (limited to 'common/src/test')
-rw-r--r-- | common/src/test/java/com/google/auto/common/SuperficialValidationTest.java | 157 |
1 files changed, 0 insertions, 157 deletions
diff --git a/common/src/test/java/com/google/auto/common/SuperficialValidationTest.java b/common/src/test/java/com/google/auto/common/SuperficialValidationTest.java deleted file mode 100644 index b886cae8..00000000 --- a/common/src/test/java/com/google/auto/common/SuperficialValidationTest.java +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Copyright (C) 2014 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 com.google.auto.common; - -import com.google.common.collect.ImmutableSet; -import com.google.testing.compile.JavaFileObjects; -import java.util.Set; -import javax.annotation.processing.AbstractProcessor; -import javax.annotation.processing.RoundEnvironment; -import javax.lang.model.element.TypeElement; -import javax.tools.JavaFileObject; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -import static com.google.common.truth.Truth.assert_; -import static com.google.testing.compile.JavaSourceSubjectFactory.javaSource; - -@RunWith(JUnit4.class) -public class SuperficialValidationTest { - @Test - public void missingReturnType() { - JavaFileObject javaFileObject = JavaFileObjects.forSourceLines( - "test.TestClass", - "package test;", - "", - "abstract class TestClass {", - " abstract MissingType blah();", - "}"); - assert_().about(javaSource()) - .that(javaFileObject) - .processedWith(new AssertingProcessor() { - @Override void runAssertions() { - TypeElement testClassElement = - processingEnv.getElementUtils().getTypeElement("test.TestClass"); - assert_().that(SuperficialValidation.validateElement(testClassElement)).isFalse(); - } - }) - .failsToCompile(); - } - - @Test - public void missingGenericReturnType() { - JavaFileObject javaFileObject = JavaFileObjects.forSourceLines( - "test.TestClass", - "package test;", - "", - "abstract class TestClass {", - " abstract MissingType<?> blah();", - "}"); - assert_().about(javaSource()) - .that(javaFileObject) - .processedWith(new AssertingProcessor() { - @Override void runAssertions() { - TypeElement testClassElement = - processingEnv.getElementUtils().getTypeElement("test.TestClass"); - assert_().that(SuperficialValidation.validateElement(testClassElement)).isFalse(); - } - }) - .failsToCompile(); - } - - @Test - public void missingReturnTypeTypeParameter() { - JavaFileObject javaFileObject = JavaFileObjects.forSourceLines( - "test.TestClass", - "package test;", - "", - "import java.util.Map;", - "import java.util.Set;", - "", - "abstract class TestClass {", - " abstract Map<Set<?>, MissingType<?>> blah();", - "}"); - assert_().about(javaSource()) - .that(javaFileObject) - .processedWith(new AssertingProcessor() { - @Override void runAssertions() { - TypeElement testClassElement = - processingEnv.getElementUtils().getTypeElement("test.TestClass"); - assert_().that(SuperficialValidation.validateElement(testClassElement)).isFalse(); - } - }) - .failsToCompile(); - } - - @Test - public void missingTypeParameter() { - JavaFileObject javaFileObject = JavaFileObjects.forSourceLines( - "test.TestClass", - "package test;", - "", - "class TestClass<T extends MissingType> {}"); - assert_().about(javaSource()) - .that(javaFileObject) - .processedWith(new AssertingProcessor() { - @Override void runAssertions() { - TypeElement testClassElement = - processingEnv.getElementUtils().getTypeElement("test.TestClass"); - assert_().that(SuperficialValidation.validateElement(testClassElement)).isFalse(); - } - }) - .failsToCompile(); - } - - @Test - public void missingAnnotation() { - JavaFileObject javaFileObject = JavaFileObjects.forSourceLines( - "test.TestClass", - "package test;", - "", - "@MissingAnnotation", - "class TestClass {}"); - assert_().about(javaSource()) - .that(javaFileObject) - .processedWith(new AssertingProcessor() { - @Override void runAssertions() { - TypeElement testClassElement = - processingEnv.getElementUtils().getTypeElement("test.TestClass"); - assert_().that(SuperficialValidation.validateElement(testClassElement)).isFalse(); - } - }) - .failsToCompile(); - } - - private static abstract class AssertingProcessor extends AbstractProcessor { - @Override - public Set<String> getSupportedAnnotationTypes() { - return ImmutableSet.of("*"); - } - - @Override - public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { - try { - runAssertions(); - } catch (Exception e) { - throw new RuntimeException(e); - } - return false; - } - - abstract void runAssertions() throws Exception; - } -} |