com.google.testing.compile.JavaFileObjects Java Examples
The following examples show how to use
com.google.testing.compile.JavaFileObjects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FeatureProcessorTests.java From featured with Apache License 2.0 | 6 votes |
@Test public void checkOnEventErrorInheritFeature() throws Exception { JavaFileObject source = JavaFileObjects .forSourceLines("de.halfbit.featured.test.TestFeature", "", "package de.halfbit.featured.test;", "import de.halfbit.featured.FeatureEvent;", "import de.halfbit.featured.Feature;", "public class TestFeature {", " @FeatureEvent protected void onStart() { }", "}" ); assertAbout(javaSource()).that(source) .processedWith(new FeatureProcessor()) .failsToCompile() .withErrorContaining("must inherit from"); }
Example #2
Source File: PaperParcelAutoValueExtensionTest.java From paperparcel with Apache License 2.0 | 6 votes |
@Test public void failWhenWriteToParcelAlreadyDefinedTest() throws Exception { JavaFileObject source = JavaFileObjects.forSourceString("test.Test", Joiner.on('\n').join( "package test;", "import com.google.auto.value.AutoValue;", "import android.os.Parcel;", "import android.os.Parcelable;", "@AutoValue", "public abstract class Test implements Parcelable {", " public abstract int count();", " @Override", " public void writeToParcel(Parcel dest, int flags) {", " }", "}" )); assertAbout(javaSource()).that(source) .processedWith(new PaperParcelProcessor(), new AutoValueProcessor()) .failsToCompile() .withErrorContaining(String.format(ErrorMessages.MANUAL_IMPLEMENTATION_OF_WRITE_TO_PARCEL, "test.Test")) .in(source) .onLine(9); }
Example #3
Source File: TestProcessor.java From android-state with Eclipse Public License 1.0 | 6 votes |
@Test public void testTypeNotSupported() { JavaFileObject javaFileObject = JavaFileObjects.forSourceString(getName("TestTypeNotSupported"), "" + "package com.evernote.android.state.test;\n" + "\n" + "import com.evernote.android.state.State;\n" + "\n" + "public class TestTypeNotSupported {\n" + " @State\n" + " public Other test;\n" + "\n" + " public static final class Other {}\n" + "}\n"); Compilation compilation = Compiler.javac().withProcessors(new StateProcessor()).compile(javaFileObject); assertThat(compilation).failed(); assertThat(compilation) .hadErrorContaining("Don't know how to put com.evernote.android.state.test.TestTypeNotSupported.Other into a bundle") .inFile(javaFileObject) .onLine(7) .atColumn(18); }
Example #4
Source File: TelemetryAnnotationProcessorTest.java From ScreenshotGo with Mozilla Public License 2.0 | 6 votes |
@Test public void should_generate_one_document() { final ImmutableList<JavaFileObject> telemetryWrapper = Compiler.javac() .withProcessors(new TelemetryAnnotationProcessor()) .compile( JavaFileObjects.forSourceLines( "TelemetryWrapper", "package com.bumptech.glide.test;", "import org.mozilla.telemetry.annotation.TelemetryDoc;\n", "import org.mozilla.telemetry.annotation.TelemetryExtra;\n", "class TelemetryWrapper {" + "@TelemetryDoc(\n" + " name = \"n\",\n" + " category = \"a\",\n" + " method = \"m\",\n" + " object = \"o\",\n" + " value = \"v\",\n" + " extras = {@TelemetryExtra(name = \"a\", value = \"v\")})", " public void send(){" + "}", "}" )).generatedFiles(); assert (telemetryWrapper.size() > 0); }
Example #5
Source File: ApplicationTest.java From nalu with Apache License 2.0 | 6 votes |
@Test void testApplicationWithComposite02() { Compilation compilation = javac().withProcessors(new NaluProcessor()) .compile(Arrays.asList(JavaFileObjects.forResource("com/github/nalukit/nalu/processor/common/ui/controllerWithComposite02/ControllerWithComposite02.java"), JavaFileObjects.forResource("com/github/nalukit/nalu/processor/common/MockContext.java"), JavaFileObjects.forResource("com/github/nalukit/nalu/processor/common/ui/MockShell.java"), JavaFileObjects.forResource("com/github/nalukit/nalu/processor/common/ui/controllerWithComposite02/IComponent02.java"), JavaFileObjects.forResource("com/github/nalukit/nalu/processor/common/ui/controllerWithComposite02/Component02.java"), JavaFileObjects.forResource("com/github/nalukit/nalu/processor/common/ui/controllerWithComposite02/composite/CompositeController02.java"), JavaFileObjects.forResource("com/github/nalukit/nalu/processor/common/ui/controllerWithComposite02/composite/ICompositeComponent02.java"), JavaFileObjects.forResource("com/github/nalukit/nalu/processor/common/ui/controllerWithComposite02/composite/CompositeComponent02.java"), JavaFileObjects.forResource("com/github/nalukit/nalu/processor/common/application/applicationWithComposite02/ApplicationWithComposite02.java"))); CompilationSubject.assertThat(compilation) .succeeded(); CompilationSubject.assertThat(compilation) .generatedSourceFile("com/github/nalukit/nalu/processor/common/application/applicationWithComposite02/ApplicationWithComposite02Impl") .hasSourceEquivalentTo(JavaFileObjects.forResource("com/github/nalukit/nalu/processor/common/application/applicationWithComposite02/ApplicationWithComposite02Impl.java")); }
Example #6
Source File: ModelProcessorTest.java From epoxy with Apache License 2.0 | 6 votes |
@Test public void testGeneratedDefaultMethodWithLayoutSpecifiedInParent() { JavaFileObject model = JavaFileObjects .forResource(GuavaPatch.patchResource("GenerateDefaultLayoutMethodParentLayout.java")); JavaFileObject generatedNoLayoutModel = JavaFileObjects .forResource(GuavaPatch.patchResource("GenerateDefaultLayoutMethodParentLayout$NoLayout_.java")); JavaFileObject generatedWithLayoutModel = JavaFileObjects.forResource(GuavaPatch.patchResource("GenerateDefaultLayoutMethodParentLayout$WithLayout_.java")); assert_().about(javaSource()) .that(model) .processedWith(processors()) .compilesWithoutError() .and() .generatesSources(generatedNoLayoutModel, generatedWithLayoutModel); }
Example #7
Source File: ErrorPopUpControllerTest.java From nalu with Apache License 2.0 | 6 votes |
@Test void testControllerCreatorOk() { Compilation compilation = javac().withProcessors(new NaluProcessor()) .compile(Arrays.asList(JavaFileObjects.forResource("com/github/nalukit/nalu/processor/errorPopUpController/errorPopUpAnnotationOk/ErrorPopUpAnnotationOk.java"), JavaFileObjects.forResource("com/github/nalukit/nalu/processor/common/ui/MockShell.java"), JavaFileObjects.forResource("com/github/nalukit/nalu/processor/common/ui/MockErrorShell.java"), JavaFileObjects.forResource("com/github/nalukit/nalu/processor/common/ui/component01/Controller01.java"), JavaFileObjects.forResource("com/github/nalukit/nalu/processor/common/ui/component01/IComponent01.java"), JavaFileObjects.forResource("com/github/nalukit/nalu/processor/common/ui/component01/Component01.java"), JavaFileObjects.forResource("com/github/nalukit/nalu/processor/common/ui/errorPopUp01/ErrorEventController01.java"), JavaFileObjects.forResource("com/github/nalukit/nalu/processor/common/ui/errorPopUp01/IErrorEventComponent01.java"), JavaFileObjects.forResource("com/github/nalukit/nalu/processor/common/ui/errorPopUp01/ErrorEventComponent01.java"))); CompilationSubject.assertThat(compilation) .succeeded(); CompilationSubject.assertThat(compilation) .generatedSourceFile("com/github/nalukit/nalu/processor/errorPopUpController/errorPopUpAnnotationOk/ErrorPopUpAnnotationOkImpl") .hasSourceEquivalentTo(JavaFileObjects.forResource("com/github/nalukit/nalu/processor/errorPopUpController/errorPopUpAnnotationOk/ErrorPopUpAnnotationOkImpl.java")); }
Example #8
Source File: ModuleFactoryGeneratorTest.java From dagger2-sample with Apache License 2.0 | 6 votes |
@Test public void providesOverridesNonProvides() { JavaFileObject parent = JavaFileObjects.forSourceLines("test.Parent", "package test;", "", "import dagger.Module;", "", "@Module", "class Parent {", " String foo() { return null; }", "}"); JavaFileObject child = JavaFileObjects.forSourceLines("test.Child", "package test;", "", "import dagger.Module;", "import dagger.Provides;", "", "@Module", "class Child extends Parent{", " @Provides String foo() { return null; }", "}"); assertAbout(javaSources()).that(ImmutableList.of(parent, child)) .processedWith(new ComponentProcessor()) .failsToCompile() .withErrorContaining(String.format(ErrorMessages.PROVIDES_METHOD_OVERRIDES_ANOTHER, "Provides", "String test.Parent.foo()")); }
Example #9
Source File: EncodableProcessorTest.java From firebase-android-sdk with Apache License 2.0 | 6 votes |
@Test public void compileNested_shouldSucceed() { Compilation result = javac() .withProcessors(new EncodableProcessor()) .compile( JavaFileObjects.forSourceLines( "SimpleClass", "import com.google.firebase.encoders.annotations.Encodable;", "public class SimpleClass {", "@Encodable public static class Nested {", "public int getInt() { return 0; }", "}}")); assertThat(result).succeededWithoutWarnings(); assertThat(result).generatedSourceFile("AutoSimpleClassNestedEncoder"); }
Example #10
Source File: ApplicationTest.java From nalu with Apache License 2.0 | 6 votes |
@Test void testApplicationWithComposite01() { Compilation compilation = javac().withProcessors(new NaluProcessor()) .compile(Arrays.asList(JavaFileObjects.forResource("com/github/nalukit/nalu/processor/common/ui/controllerWithComposite01/ControllerWithComposite01.java"), JavaFileObjects.forResource("com/github/nalukit/nalu/processor/common/MockContext.java"), JavaFileObjects.forResource("com/github/nalukit/nalu/processor/common/ui/MockShell.java"), JavaFileObjects.forResource("com/github/nalukit/nalu/processor/common/ui/controllerWithComposite01/IComponent01.java"), JavaFileObjects.forResource("com/github/nalukit/nalu/processor/common/ui/controllerWithComposite01/Component01.java"), JavaFileObjects.forResource("com/github/nalukit/nalu/processor/common/ui/controllerWithComposite01/composite/CompositeController01.java"), JavaFileObjects.forResource("com/github/nalukit/nalu/processor/common/ui/controllerWithComposite01/composite/ICompositeComponent01.java"), JavaFileObjects.forResource("com/github/nalukit/nalu/processor/common/ui/controllerWithComposite01/composite/CompositeComponent01.java"), JavaFileObjects.forResource("com/github/nalukit/nalu/processor/common/application/applicationWithComposite01/ApplicationWithComposite01.java"))); CompilationSubject.assertThat(compilation) .succeeded(); CompilationSubject.assertThat(compilation) .generatedSourceFile("com/github/nalukit/nalu/processor/common/application/applicationWithComposite01/ApplicationWithComposite01Impl") .hasSourceEquivalentTo(JavaFileObjects.forResource("com/github/nalukit/nalu/processor/common/application/applicationWithComposite01/ApplicationWithComposite01Impl.java")); }
Example #11
Source File: ProducerModuleFactoryGeneratorTest.java From dagger2-sample with Apache License 2.0 | 6 votes |
@Test public void producesMethodStatic() { JavaFileObject moduleFile = JavaFileObjects.forSourceLines("test.TestModule", "package test;", "", "import dagger.producers.ProducerModule;", "import dagger.producers.Produces;", "", "@ProducerModule", "final class TestModule {", " @Produces static String produceString() {", " return \"\";", " }", "}"); assertAbout(javaSource()).that(moduleFile) .processedWith(new ComponentProcessor()) .failsToCompile() .withErrorContaining(formatErrorMessage(BINDING_METHOD_STATIC)); }
Example #12
Source File: CompilationTest.java From RetroFacebook with Apache License 2.0 | 6 votes |
public void testAnnotationOnEnum() throws Exception { JavaFileObject javaFileObject = JavaFileObjects.forSourceLines( "foo.bar.Baz", "package foo.bar;", "", "import retrofacebook.RetroFacebook;", "", "@RetroFacebook", "public enum Baz {}"); assertAbout(javaSource()) .that(javaFileObject) .processedWith(new RetroFacebookProcessor()) .failsToCompile() .withErrorContaining("RetroFacebook only applies to classes") .in(javaFileObject).onLine(6); }
Example #13
Source File: PaperParcelProcessorTest.java From paperparcel with Apache License 2.0 | 6 votes |
@Test public void failIfNonSingletonTypeAdapterConstructorIsNonPublic() { JavaFileObject typeAdapter = JavaFileObjects.forSourceString("test.MyTypeAdapter", Joiner.on('\n').join( "package test;", "import paperparcel.Adapter;", "import paperparcel.ProcessorConfig;", "import paperparcel.TypeAdapter;", "import android.os.Parcel;", "@ProcessorConfig(adapters = @Adapter(MyTypeAdapter.class))", "public class MyTypeAdapter implements TypeAdapter<Integer> {", " MyTypeAdapter() {}", " public Integer readFromParcel(Parcel in) {", " return null;", " }", " public void writeToParcel(Integer value, Parcel dest, int flags) {", " }", "}" )); assertAbout(javaSource()).that(typeAdapter) .processedWith(new PaperParcelProcessor()) .failsToCompile() .withErrorContaining(ErrorMessages.ADAPTER_MUST_HAVE_PUBLIC_CONSTRUCTOR) .in(typeAdapter) .onLine(7); }
Example #14
Source File: InvalidModelTest.java From ngAndroid with Apache License 2.0 | 6 votes |
@Test public void testStringScope() { String content = "" + "package com.x.y;" + "import com.ngandroid.lib.annotations.NgModel;\n" + "import com.ngandroid.lib.annotations.NgScope;\n\n" + "@NgScope\n" + "public final class StringScope {\n" + " @NgModel\n" + " android.view.View model;\n" + "}"; JavaFileObject file = JavaFileObjects.forSourceString("com.x.y.StringScope", content); ASSERT.about(javaSource()) .that(file) .processedWith(Collections.singletonList(new NgProcessor(Option.of("ng-processor/src/test/resources/emptylayout")))) .failsToCompile() .withErrorContaining("is missing a corresponding getter"); }
Example #15
Source File: PopUpControllerCreatorTest.java From nalu with Apache License 2.0 | 6 votes |
@Test void testControllerCreatorOk() { Compilation compilation = javac().withProcessors(new NaluProcessor()) .compile(Arrays.asList(JavaFileObjects.forResource("com/github/nalukit/nalu/processor/common/MockContext.java"), JavaFileObjects.forResource("com/github/nalukit/nalu/processor/popUpControllerCreator/ok/Controller01.java"), JavaFileObjects.forResource("com/github/nalukit/nalu/processor/popUpControllerCreator/ok/IComponent01.java"), JavaFileObjects.forResource("com/github/nalukit/nalu/processor/popUpControllerCreator/ok/Component01.java"), JavaFileObjects.forResource("com/github/nalukit/nalu/processor/popUpControllerCreator/ok/PopUpController01.java"), JavaFileObjects.forResource("com/github/nalukit/nalu/processor/popUpControllerCreator/ok/IPopUpComponent01.java"), JavaFileObjects.forResource("com/github/nalukit/nalu/processor/popUpControllerCreator/ok/PopUpComponent01.java"))); CompilationSubject.assertThat(compilation) .succeeded(); CompilationSubject.assertThat(compilation) .generatedSourceFile("com/github/nalukit/nalu/processor/popUpControllerCreator/ok/PopUpController01CreatorImpl") .hasSourceEquivalentTo(JavaFileObjects.forResource("com/github/nalukit/nalu/processor/popUpControllerCreator/ok/PopUpController01CreatorImpl.java")); }
Example #16
Source File: CompilationTest.java From RetroFacebook with Apache License 2.0 | 6 votes |
public void testRetroFacebookBuilderWrongTypeSetterWithGetPrefix() { JavaFileObject javaFileObject = JavaFileObjects.forSourceLines( "foo.bar.Baz", "package foo.bar;", "", "import retrofacebook.RetroFacebook;", "", "@RetroFacebook", "public abstract class Baz {", " abstract int getBlim();", " abstract String getBlam();", "", " @RetroFacebook.Builder", " public interface Builder {", " Builder blim(String x);", " Builder blam(String x);", " Baz build();", " }", "}"); assertAbout(javaSource()) .that(javaFileObject) .processedWith(new RetroFacebookProcessor(), new RetroFacebookBuilderProcessor()) .failsToCompile() .withErrorContaining("Parameter type should be int") .in(javaFileObject).onLine(12); }
Example #17
Source File: CompilationTest.java From RetroFacebook with Apache License 2.0 | 6 votes |
public void testRetroFacebookBuilderOnTopLevelClass() throws Exception { JavaFileObject javaFileObject = JavaFileObjects.forSourceLines( "foo.bar.Builder", "package foo.bar;", "", "import retrofacebook.RetroFacebook;", "", "@RetroFacebook.Builder", "public interface Builder {", " Builder foo(int x);", " Object build();", "}"); assertAbout(javaSource()) .that(javaFileObject) .processedWith(new RetroFacebookProcessor(), new RetroFacebookBuilderProcessor()) .failsToCompile() .withErrorContaining("can only be applied to a class or interface inside") .in(javaFileObject).onLine(6); }
Example #18
Source File: ResubscriptionProcessorTest.java From RxGroups with Apache License 2.0 | 6 votes |
@Test public void autoTaggableObserver_worksWithAll_customTag() throws Exception { JavaFileObject source = JavaFileObjects.forResource("AutoTaggableObserver_Pass_All_CustomTag.java"); JavaFileObject resubscriberSource = JavaFileObjects.forSourceString("test.AutoTaggableObserver_Pass_All_CustomTag", "" + "package test;\n" + "import com.airbnb.rxgroups.BaseObservableResubscriber;\n" + "import com.airbnb.rxgroups.ObservableGroup;\n" + "\n" + "public class AutoTaggableObserver_Pass_All_CustomTag_ObservableResubscriber extends BaseObservableResubscriber {\n" + " public AutoTaggableObserver_Pass_All_CustomTag_ObservableResubscriber(AutoTaggableObserver_Pass_All_CustomTag target, ObservableGroup group) {\n" + " setTag(target.resubscribeObserver, \"tag1\");\n" + " group.resubscribeAll(target.resubscribeObserver);\n" + " setTag(target.autoTag, \"tag2\");\n" + " }\n" + "}\n" + "" ); Truth.assertAbout(JavaSourceSubjectFactory.javaSource()).that(source) .withCompilerOptions("-Xlint:-processing") .processedWith(new ResubscriptionProcessor()) .compilesWithoutWarnings() .and() .generatesSources(resubscriberSource); }
Example #19
Source File: ObjectMappableProcessorNotValidAnnotatedClassTest.java From sqlbrite-dao with Apache License 2.0 | 6 votes |
@Test public void setterUnsupportedTypeDerivedFromPrivateField() { JavaFileObject file = JavaFileObjects.forSourceLines("test.SetterUnsupportedType", "package test;", "", "@"+ ObjectMappable.class.getCanonicalName(), "public class SetterUnsupportedType {", " @"+ Column.class.getCanonicalName()+"(\"foo\")", " private java.util.List foo;", " public void setFoo(java.util.List foo){ this.foo = foo; }", "}" ); Truth.assertAbout(JavaSourceSubjectFactory.javaSource()) .that(file) .processedWith(new ObjectMappableProcessor()) .failsToCompile() .withErrorContaining("Unsupported type java.util.List as parameter in method setFoo(java.util.List)() in class test.SetterUnsupportedType annotated with @Column."); }
Example #20
Source File: FactoryTest.java From toothpick with Apache License 2.0 | 6 votes |
@Test public void testPrivateConstructor() { JavaFileObject source = JavaFileObjects.forSourceString( "test.TestPrivateConstructor", Joiner.on('\n') .join( // "package test;", // "import javax.inject.Inject;", // "public class TestPrivateConstructor {", // " @Inject private TestPrivateConstructor() {}", // "}" // )); assert_() .about(javaSource()) .that(source) .processedWith(ProcessorTestUtilities.factoryProcessors()) .failsToCompile() .withErrorContaining( "@Inject constructors must not be private in class test.TestPrivateConstructor"); }
Example #21
Source File: GraphValidationTest.java From dagger2-sample with Apache License 2.0 | 6 votes |
@Test public void constructorInjectionWithoutAnnotation() { JavaFileObject component = JavaFileObjects.forSourceLines("test.TestClass", "package test;", "", "import dagger.Component;", "import dagger.Module;", "import dagger.Provides;", "import javax.inject.Inject;", "", "final class TestClass {", " static class A {", " A() {}", " }", "", " @Component()", " interface AComponent {", " A getA();", " }", "}"); String expectedError = "test.TestClass.A cannot be provided without an " + "@Inject constructor or from an @Provides-annotated method."; assertAbout(javaSource()).that(component) .processedWith(new ComponentProcessor()) .failsToCompile() .withErrorContaining(expectedError).in(component).onLine(15); }
Example #22
Source File: CompilationTest.java From SimpleWeibo with Apache License 2.0 | 6 votes |
public void testNoMultidimensionalPrimitiveArrays() throws Exception { JavaFileObject javaFileObject = JavaFileObjects.forSourceLines( "foo.bar.Baz", "package foo.bar;", "", "import retroweibo.RetroWeibo;", "", "@RetroWeibo", "public abstract class Baz {", " public abstract int[][] ints();", "", " public static Baz create(int[][] ints) {", " return new RetroWeibo_Baz(ints);", " }", "}"); assertAbout(javaSource()) .that(javaFileObject) .processedWith(new RetroWeiboProcessor()) .failsToCompile() .withErrorContaining("RetroWeibo class cannot define an array-valued property " + "unless it is a primitive array") .in(javaFileObject).onLine(7); }
Example #23
Source File: CompilationTest.java From RetroFacebook with Apache License 2.0 | 6 votes |
public void testAnnotationOnInterface() throws Exception { JavaFileObject javaFileObject = JavaFileObjects.forSourceLines( "foo.bar.Baz", "package foo.bar;", "", "import retrofacebook.RetroFacebook;", "", "@RetroFacebook", "public interface Baz {}"); assertAbout(javaSource()) .that(javaFileObject) .processedWith(new RetroFacebookProcessor()) .failsToCompile() .withErrorContaining("RetroFacebook only applies to classes") .in(javaFileObject).onLine(6); }
Example #24
Source File: CompilationTest.java From RetroFacebook with Apache License 2.0 | 6 votes |
public void testRetroFacebookBuilderOnEnum() throws Exception { JavaFileObject javaFileObject = JavaFileObjects.forSourceLines( "foo.bar.Baz", "package foo.bar;", "", "import retrofacebook.RetroFacebook;", "", "@RetroFacebook", "public abstract class Baz {", " abstract int foo();", "", " static Builder builder() {", " return null;", " }", "", " @RetroFacebook.Builder", " public enum Builder {}", "}"); assertAbout(javaSource()) .that(javaFileObject) .processedWith(new RetroFacebookProcessor(), new RetroFacebookBuilderProcessor()) .failsToCompile() .withErrorContaining("can only apply to a class or an interface") .in(javaFileObject).onLine(14); }
Example #25
Source File: ComponentProcessorTest.java From dagger2-sample with Apache License 2.0 | 6 votes |
@Test public void cannotReferToAbstractModules() { JavaFileObject moduleFile = JavaFileObjects.forSourceLines("test.TestModule", "package test;", "", "import dagger.Module;", "", "@Module", "abstract class TestModule {}"); JavaFileObject componentFile = JavaFileObjects.forSourceLines("test.BadComponent", "package test;", "", "import dagger.Component;", "", "@Component(modules = TestModule.class)", "interface BadComponent {}"); assertAbout(javaSources()).that(ImmutableList.of(moduleFile, componentFile)) .processedWith(new ComponentProcessor()) .failsToCompile() .withErrorContaining( String.format(REFERENCED_MODULES_MUST_NOT_BE_ABSTRACT, "test.TestModule")); }
Example #26
Source File: CompilationTest.java From RetroFacebook with Apache License 2.0 | 6 votes |
public void testExceptionBecomesError() throws Exception { // Ensure that if the annotation processor code gets an unexpected exception, it is converted // into a compiler error rather than being propagated. Otherwise the output can be very // confusing to the user who stumbles into a bug that causes an exception, whether in // RetroFacebookProcessor or javac. // We inject an exception by subclassing RetroFacebookProcessor in order to poison its processingEnv // in a way that will cause an exception the first time it tries to get the Filer. IllegalArgumentException exception = new IllegalArgumentException("I don't understand the question, and I won't respond to it"); JavaFileObject javaFileObject = JavaFileObjects.forSourceLines( "foo.bar.Baz", "package foo.bar;", "", "import retrofacebook.RetroFacebook;", "", "@RetroFacebook", "public abstract class Baz {", " public abstract int foo();", "}"); assertAbout(javaSource()) .that(javaFileObject) .processedWith(new PoisonedRetroFacebookProcessor(exception)) .failsToCompile() .withErrorContaining(exception.toString()) .in(javaFileObject).onLine(6); }
Example #27
Source File: ActionProcessorTest.java From syndesis with Apache License 2.0 | 6 votes |
@Test public void test() throws URISyntaxException, MalformedURLException { Compilation compilation = Compiler.javac() .withProcessors(new ActionProcessor()) .compile(JavaFileObjects.forSourceString( "test.AnnotatedClassTest", "package test;\n" + "\n" + "@io.syndesis.extension.api.annotations.Action(\n" + " id = \"action-id\",\n" + " name = \"action-name\",\n" + " description = \"action-description\"\n" + ")\n" + "public class AnnotatedClassTest {\n" + "}" ) ); assertTrue(compilation.generatedFile(StandardLocation.SOURCE_OUTPUT, "test/AnnotatedClassTest-action-id.json").isPresent()); }
Example #28
Source File: AnnotationProcessorTest.java From peapod with Apache License 2.0 | 5 votes |
@Test public void testCompileForAbstractClasses() { List<JavaFileObject> input = new ArrayList<>(); input.add(JavaFileObjects.forResource("peapod/internal/classes/Person.java")); input.add(JavaFileObjects.forResource("peapod/internal/classes/Knows.java")); JavaFileObject framedVertex = JavaFileObjects.forResource("peapod/internal/classes/Person$Impl.java"); JavaFileObject framedEdge = JavaFileObjects.forResource("peapod/internal/classes/Knows$Impl.java"); assert_().about(javaSources()) .that(input) .processedWith(new AnnotationProcessor()) .compilesWithoutError() .and().generatesSources(framedVertex, framedEdge); }
Example #29
Source File: InjectConstructorFactoryGeneratorTest.java From dagger2-sample with Apache License 2.0 | 5 votes |
@Test public void multipleQualifiersOnInjectMethodParameter() { JavaFileObject file = JavaFileObjects.forSourceLines("test.MultipleQualifierMethodParam", "package test;", "", "import javax.inject.Inject;", "", "class MultipleQualifierMethodParam {", " @Inject void method(@QualifierA @QualifierB String s) {}", "}"); assertAbout(javaSources()).that(ImmutableList.of(file, QUALIFIER_A, QUALIFIER_B)) .processedWith(new ComponentProcessor()) .failsToCompile() // for whatever reason, javac only reports the error once on the method .withErrorContaining(MULTIPLE_QUALIFIERS).in(file).onLine(6); }
Example #30
Source File: IntegrationTest.java From dataenum with Apache License 2.0 | 5 votes |
@Test public void shouldReportDuplicateCaseNames() throws Exception { Compilation compilation = javac() .withProcessors(new DataEnumProcessor()) .compile(JavaFileObjects.forResource("DuplicateCases_dataenum.java")); assertThat(compilation).failed(); assertThat(compilation).hadErrorCount(2); assertThat(compilation).hadErrorContaining("Duplicate case name 'value'"); assertThat(compilation).hadErrorContaining("Duplicate case name 'caseisimportant'"); }