Java Code Examples for com.google.testing.compile.JavaFileObjects#forResource()
The following examples show how to use
com.google.testing.compile.JavaFileObjects#forResource() .
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: ProcessorIntegrationTest.java From litho with Apache License 2.0 | 6 votes |
@Ignore("T41117446") // Starts failing after updating gradle plugin to 3.3.1 @Test public void failsToCompileNonEmptyTestSpecInterface() throws IOException { final JavaFileObject javaFileObject = JavaFileObjects.forResource( Resources.getResource(getClass(), RES_PREFIX + "IncorrectNonEmptyTestSpec.java")); final JavaFileObject layoutSpecObject = JavaFileObjects.forResource( Resources.getResource(getClass(), RES_PREFIX + "BasicLayoutSpec.java")); Truth.assertAbout(JavaSourcesSubjectFactory.javaSources()) .that(ImmutableList.of(javaFileObject, layoutSpecObject)) .processedWith(new ComponentsTestingProcessor(), new ComponentsProcessor()) .failsToCompile() .withErrorCount(1) .withErrorContaining( "TestSpec interfaces must not contain any members. Please remove these function declarations: ()void test, ()java.util.List<java.lang.Integer> list") .in(javaFileObject) .onLine(24); }
Example 2
Source File: ModelProcessorTest.java From epoxy with Apache License 2.0 | 6 votes |
@Test public void testModelWithAnnotatedClassAndSuperClass() { JavaFileObject model = JavaFileObjects .forResource(GuavaPatch.patchResource("ModelWithAnnotatedClassAndSuperAttributes.java")); JavaFileObject generatedModel = JavaFileObjects .forResource(GuavaPatch.patchResource("ModelWithAnnotatedClassAndSuperAttributes_.java")); JavaFileObject generatedSubClassModel = JavaFileObjects.forResource(GuavaPatch.patchResource( "ModelWithAnnotatedClassAndSuperAttributes$SubModel" + "WithAnnotatedClassAndSuperAttributes_.java")); assert_().about(javaSource()) .that(model) .processedWith(processors()) .compilesWithoutError() .and() .generatesSources(generatedModel, generatedSubClassModel); }
Example 3
Source File: ResubscriptionProcessorTest.java From RxGroups with Apache License 2.0 | 6 votes |
@Test public void taggedObserver_worksWithAutoResubscribe() throws Exception { JavaFileObject source = JavaFileObjects.forResource("TaggedObserver_Pass_AutoResubscribe.java"); JavaFileObject resubscriberSource = JavaFileObjects.forSourceString("test.TaggedObserver_Pass_AutoResubscribe_ObservableResubscriber", "" + "package test;\n" + "import com.airbnb.rxgroups.BaseObservableResubscriber;\n" + "import com.airbnb.rxgroups.ObservableGroup;\n" + "public class TaggedObserver_Pass_AutoResubscribe_ObservableResubscriber extends BaseObservableResubscriber {\n" + " public TaggedObserver_ObservableResubscriber(TaggedObserver_Pass_AutoResubscribe target, ObservableGroup group) {\n" + " group.resubscribeAll(target.taggedObserver);\n" + " }\n" + "}\n" + "" ); Truth.assertAbout(JavaSourceSubjectFactory.javaSource()).that(source) .withCompilerOptions("-Xlint:-processing") .processedWith(new ResubscriptionProcessor()) .compilesWithoutWarnings() .and() .generatesSources(resubscriberSource); }
Example 4
Source File: ResubscriptionProcessorTest.java From RxGroups with Apache License 2.0 | 6 votes |
@Test public void autoResubscribeObserver_worksWithAll() throws Exception { JavaFileObject source = JavaFileObjects.forResource("AutoResubscribingObserver_Pass_All.java"); JavaFileObject resubscriberSource = JavaFileObjects.forSourceString("test.AutoResubscribingObserver_Pass_All", "" + "package test;\n" + "import com.airbnb.rxgroups.BaseObservableResubscriber;\n" + "import com.airbnb.rxgroups.ObservableGroup;\n" + "public class AutoResubscribingObserver_Pass_All_ObservableResubscriber extends BaseObservableResubscriber {\n" + " public AutoResubscribingObserver_Pass_All_ObservableResubscriber(AutoResubscribingObserver_Pass_All target, ObservableGroup group) {\n" + " setTag(target.observer, \"AutoResubscribingObserver_Pass_All_observer\");\n" + " group.resubscribeAll(target.observer);\n" + " setTag(target.observer1, \"AutoResubscribingObserver_Pass_All_observer1\");\n" + " }\n" + "}\n" + "" ); Truth.assertAbout(JavaSourceSubjectFactory.javaSource()).that(source) .withCompilerOptions("-Xlint:-processing") .processedWith(new ResubscriptionProcessor()) .compilesWithoutWarnings() .and() .generatesSources(resubscriberSource); }
Example 5
Source File: ProcessorIntegrationTest.java From litho with Apache License 2.0 | 6 votes |
@Ignore("T41117446") // Starts failing after updating gradle plugin to 3.3.1 @Test public void failsToCompileClassBasedTestSpec() throws IOException { final JavaFileObject javaFileObject = JavaFileObjects.forResource( Resources.getResource(getClass(), RES_PREFIX + "IncorrectClassBasedTestSpec.java")); final JavaFileObject layoutSpecObject = JavaFileObjects.forResource( Resources.getResource(getClass(), RES_PREFIX + "BasicLayoutSpec.java")); Truth.assertAbout(JavaSourcesSubjectFactory.javaSources()) .that(ImmutableList.of(javaFileObject, layoutSpecObject)) .processedWith(new ComponentsTestingProcessor(), new ComponentsProcessor()) .failsToCompile() .withErrorCount(1) .withErrorContaining( "Specs annotated with @TestSpecs must be interfaces and cannot be of kind CLASS.") .in(javaFileObject) .onLine(23); }
Example 6
Source File: DataBindingModelTest.java From epoxy with Apache License 2.0 | 6 votes |
@Test public void testFullyGeneratedModelWithoutDoNotHash() { JavaFileObject packageInfo = JavaFileObjects .forSourceString("com.airbnb.epoxy.package-info", "@EpoxyDataBindingLayouts(value = {R.layout" + ".model_with_data_binding_without_donothash}, enableDoNotHash = false)\n" + "package com.airbnb.epoxy;\n" ); JavaFileObject binding = JavaFileObjects .forResource(GuavaPatch.patchResource("ModelWithDataBindingWithoutDonothashBinding.java")); JavaFileObject generatedModel = JavaFileObjects.forResource(GuavaPatch.patchResource("ModelWithDataBindingWithoutDonothashBindingModel_.java")); assert_().about(javaSources()) .that(asList(packageInfo, binding, BR_CLASS, R)) .processedWith(processors()) .compilesWithoutError() .and() .generatesSources(generatedModel); }
Example 7
Source File: ResubscriptionProcessorTest.java From RxGroups with Apache License 2.0 | 5 votes |
@Test public void plainObserverFails_autoTag() throws Exception { JavaFileObject source = JavaFileObjects.forResource("PlainObserver_Fail_AutoTag.java"); Truth.assertAbout(JavaSourceSubjectFactory.javaSource()).that(source) .withCompilerOptions("-Xlint:-processing") .processedWith(new ResubscriptionProcessor()) .failsToCompile() .withErrorContaining(" AutoTag annotation may only be on interface com.airbnb.rxgroups.AutoTaggableObserver or class com.airbnb.rxgroups.AutoResubscribingObserver types."); }
Example 8
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 9
Source File: ConfigTest.java From epoxy with Apache License 2.0 | 5 votes |
@Test public void testConfigRequireHashCodeAutoValueAttributePasses() { // Verify that AutoValue class attributes pass the hashcode requirement JavaFileObject model = JavaFileObjects .forResource(GuavaPatch.patchResource("ModelRequiresHashCodeAutoValueClassPasses.java")); assert_().about(javaSources()) .that(asList(CONFIG_CLASS_REQUIRE_HASH, model)) .processedWith(processors()) .compilesWithoutError(); }
Example 10
Source File: ProcessorIntegrationTest.java From litho with Apache License 2.0 | 5 votes |
@Ignore("T41117446") // Enable them after switching target to AndroidX @Test public void compilesBasicTestSampleSpec() { final JavaFileObject testSpecObject = JavaFileObjects.forResource( Resources.getResource(getClass(), RES_PREFIX + "BasicTestSampleSpec.java")); final JavaFileObject layoutSpecObject = JavaFileObjects.forResource( Resources.getResource(getClass(), RES_PREFIX + "BasicLayoutSpec.java")); final JavaFileObject expectedOutput = JavaFileObjects.forResource( Resources.getResource(getClass(), RES_PREFIX + "BasicTestSample.java")); Truth.assertAbout(JavaSourcesSubjectFactory.javaSources()) .that(ImmutableList.of(testSpecObject, layoutSpecObject)) .processedWith(new ComponentsTestingProcessor(), new ComponentsProcessor()) .compilesWithoutError() .and() .generatesFileNamed(StandardLocation.CLASS_OUTPUT, RES_PACKAGE, "BasicTestSample.class") .and() .generatesFileNamed( StandardLocation.CLASS_OUTPUT, RES_PACKAGE, "BasicTestSample$Matcher.class") .and() .generatesFileNamed( StandardLocation.CLASS_OUTPUT, RES_PACKAGE, "BasicTestSample$Matcher$1.class") .and() .generatesFileNamed(StandardLocation.CLASS_OUTPUT, RES_PACKAGE, "BasicTestSampleSpec.class") .and() .generatesSources(expectedOutput); }
Example 11
Source File: ResubscriptionProcessorTest.java From RxGroups with Apache License 2.0 | 5 votes |
@Test public void taggedObserverFails_autoTag() throws Exception { JavaFileObject source = JavaFileObjects.forResource("TaggedObserver_Fail_AutoTag.java"); Truth.assertAbout(JavaSourceSubjectFactory.javaSource()).that(source) .withCompilerOptions("-Xlint:-processing") .processedWith(new ResubscriptionProcessor()) .failsToCompile() .withErrorContaining("AutoTag annotation may only be on interface com.airbnb.rxgroups.AutoTaggableObserver or class com.airbnb.rxgroups.AutoResubscribingObserver types."); }
Example 12
Source File: MyProcessorTest.java From AnnotationProcessorStarter with Apache License 2.0 | 5 votes |
@Test public void process_A_with_annotated_method() throws IOException { final JavaFileObject lInput = JavaFileObjects.forResource("assets/A.java"); final JavaFileObject lOutput = JavaFileObjects.forResource("assets/A$$MyAnnotation.java"); assert_() .about(JavaSourcesSubjectFactory.javaSources()) .that(Arrays.asList(lInput)) .processedWith(new MyProcessor()) .compilesWithoutError() .and() .generatesSources(lOutput); }
Example 13
Source File: ResubscriptionProcessorTest.java From RxGroups with Apache License 2.0 | 5 votes |
@Test public void privateObserver_fail_nonStatic() throws Exception { JavaFileObject source = JavaFileObjects.forResource("AutoResubscribingObserver_Fail_NonStatic.java"); Truth.assertAbout(JavaSourceSubjectFactory.javaSource()).that(source) .withCompilerOptions("-Xlint:-processing") .processedWith(new ResubscriptionProcessor()) .failsToCompile() .withErrorContaining("AutoResubscribe annotations must not be on private or static fields."); }
Example 14
Source File: MethodShortcutTest.java From shortbread with Apache License 2.0 | 5 votes |
@Test public void twoMethodShortcutsInOneActivity() { JavaFileObject source = JavaFileObjects.forResource("TwoMethodShortcutsActivity.java"); JavaFileObject generated = JavaFileObjects.forResource("TwoMethodShortcutsActivityGenerated.java"); assertAbout(javaSource()).that(source) .processedWith(new ShortcutProcessor()) .compilesWithoutError() .and() .generatesSources(generated); }
Example 15
Source File: SimplePreferencesProcessorTest.java From simple-preferences with Apache License 2.0 | 5 votes |
@Test public void testValidClassWithDefaultPref() { JavaFileObject modelFile = JavaFileObjects.forResource("ValidPrefsWithDefaultName.java"); assert_().about(javaSource()) .that(modelFile) .processedWith(new SimplePreferencesProcessor()) .compilesWithoutError(); }
Example 16
Source File: ModelProcessorTest.java From epoxy with Apache License 2.0 | 5 votes |
@Test public void modelWithViewClickLongListener() { JavaFileObject model = JavaFileObjects .forResource(GuavaPatch.patchResource("ModelWithViewLongClickListener.java")); JavaFileObject generatedNoLayoutModel = JavaFileObjects .forResource(GuavaPatch.patchResource("ModelWithViewLongClickListener_.java")); assert_().about(javaSource()) .that(model) .processedWith(processors()) .compilesWithoutError() .and() .generatesSources(generatedNoLayoutModel); }
Example 17
Source File: ActivityShortcutTest.java From shortbread with Apache License 2.0 | 5 votes |
@Test public void resourcesShortcutActivity() { JavaFileObject source = JavaFileObjects.forResource("ResourcesShortcutActivity.java"); JavaFileObject generated = JavaFileObjects.forResource("ResourcesShortcutActivityGenerated.java"); assertAbout(javaSource()).that(source) .processedWith(new ShortcutProcessor()) .compilesWithoutError() .and() .generatesSources(generated); }
Example 18
Source File: AutoBundleProcessorTest.java From AutoBundle with Apache License 2.0 | 5 votes |
@Test public void testNotPublicConstructorConverter() throws Exception { JavaFileObject source = JavaFileObjects.forResource("NotPublicConstructorConverter.java"); assert_().about(javaSource()) .that(source) .processedWith(new AutoBundleProcessor()) .failsToCompile() .withErrorCount(1) .withErrorContaining(" must have public empty constructor."); }
Example 19
Source File: AutoBundleProcessorTest.java From AutoBundle with Apache License 2.0 | 5 votes |
@Test public void testProcessorFragment() throws Exception { JavaFileObject source = JavaFileObjects.forResource("ValidFragment.java"); assert_().about(javaSource()) .that(source) .processedWith(new AutoBundleProcessor()) .compilesWithoutError(); }
Example 20
Source File: InteractorTestGeneratorProcessorTestBase.java From RIBs with Apache License 2.0 | 4 votes |
@NonNull protected JavaFileObject getResourceFile(@NonNull String file) { return JavaFileObjects.forResource(file); }