Tabnine Logo
JavaFileObjects
Code IndexAdd Tabnine to your IDE (free)

How to use
JavaFileObjects
in
com.google.testing.compile

Best Java code snippets using com.google.testing.compile.JavaFileObjects (Showing top 20 results out of 540)

origin: robolectric/robolectric

@Test
public void unannotatedSource_shouldCompile() {
 assertAbout(javaSources())
  .that(ImmutableList.of(
    SHADOW_PROVIDER_SOURCE,
    SHADOW_EXTRACTOR_SOURCE,
    forSourceString("HelloWorld", "final class HelloWorld {}")))
  .processedWith(new RobolectricProcessor(DEFAULT_OPTS))
  .compilesWithoutError();
 //.and().generatesNoSources(); Should add this assertion onces
 // it becomes available in compile-testing
}
origin: robolectric/robolectric

@Test
public void generatedFile_shouldHandleNonPublicClasses() {
 assertAbout(javaSources())
  .that(ImmutableList.of(
    SHADOW_PROVIDER_SOURCE,
    SHADOW_EXTRACTOR_SOURCE,
    forResource("org/robolectric/annotation/processing/shadows/ShadowPrivate.java"),
    forResource("org/robolectric/annotation/processing/shadows/ShadowOuterDummy2.java"),
    forResource("org/robolectric/annotation/processing/shadows/ShadowDummy.java")))
  .processedWith(new RobolectricProcessor(DEFAULT_OPTS))
  .compilesWithoutError()
  .and()
  .generatesSources(forResource("org/robolectric/Robolectric_HiddenClasses.java"));
}
origin: google/error-prone

private JavaFileObject applyDiff(
  JavaFileObject sourceFileObject, Context context, JCCompilationUnit tree) throws IOException {
 ImportOrganizer importOrganizer = ImportOrderParser.getImportOrganizer(importOrder);
 final DescriptionBasedDiff diff = DescriptionBasedDiff.create(tree, importOrganizer);
 transformer(refactoringBugChecker)
   .apply(
     new TreePath(tree),
     context,
     new DescriptionListener() {
      @Override
      public void onDescribed(Description description) {
       if (!description.fixes.isEmpty()) {
        diff.handleFix(fixChooser.choose(description.fixes));
       }
      }
     });
 SourceFile sourceFile = SourceFile.create(sourceFileObject);
 diff.applyDifferences(sourceFile);
 JavaFileObject transformed =
   JavaFileObjects.forSourceString(getFullyQualifiedName(tree), sourceFile.getSourceText());
 return transformed;
}
origin: robolectric/robolectric

@Test
public void generatedFile_shouldHandleInnerClassCollisions() {
 // Because the Generated annotation has a retention of "source", it can't
 // be tested by a unit test - must run a source-level test.
 assertAbout(javaSources())
  .that(ImmutableList.of(
    SHADOW_PROVIDER_SOURCE,
    SHADOW_EXTRACTOR_SOURCE,
    forResource("org/robolectric/annotation/processing/shadows/ShadowDummy.java"),
    forResource("org/robolectric/annotation/processing/shadows/ShadowOuterDummy.java"),
    forResource("org/robolectric/annotation/processing/shadows/ShadowUniqueDummy.java")))
  .processedWith(new RobolectricProcessor(DEFAULT_OPTS))
  .compilesWithoutError()
  .and()
  .generatesSources(forResource("org/robolectric/Robolectric_InnerClassCollision.java"));
}
origin: airbnb/DeepLinkDispatch

@Test public void testProcessorWithEmptyCustomPrefixFail() {
 JavaFileObject emptyPrefixLink = JavaFileObjects
   .forSourceString("MyDeepLink", "package com.example;\n"
     + "import com.airbnb.deeplinkdispatch.DeepLinkSpec;\n"
     + "@DeepLinkSpec(prefix = { \"http://\", \"\" })\n"
     + "public @interface MyDeepLink {\n"
     + "    String[] value();\n"
     + "}");
 assertAbout(javaSources())
   .that(Arrays.asList(emptyPrefixLink, SIMPLE_DEEPLINK_ACTIVITY, SIMPLE_DEEPLINK_MODULE))
   .processedWith(new DeepLinkProcessor())
   .failsToCompile()
   .withErrorContaining("Prefix property cannot have null or empty strings");
}
origin: remkop/picocli

@Test
public void testCommandWithMixin() {
  Compilation compilation = compareCommandDump(slurp("/picocli/examples/mixin/CommandWithMixin.yaml"),
      JavaFileObjects.forResource("picocli/examples/mixin/CommandWithMixin.java"),
      JavaFileObjects.forResource("picocli/examples/mixin/CommonOption.java"));
  assertOnlySourceVersionWarning(compilation);
}
origin: airbnb/DeepLinkDispatch

@Test public void testProcessorWithEmptyDeepLinkSpecPrefixesFail() {
 JavaFileObject emptyPrefixArrayLink = JavaFileObjects
   .forSourceString("MyDeepLink", "package com.example;\n"
     + "import com.airbnb.deeplinkdispatch.DeepLinkSpec;\n"
     + "@DeepLinkSpec(prefix = { })\n"
     + "public @interface MyDeepLink {\n"
     + "    String[] value();\n"
     + "}");
 assertAbout(javaSources())
   .that(Arrays.asList(emptyPrefixArrayLink, SIMPLE_DEEPLINK_ACTIVITY,
     SIMPLE_DEEPLINK_MODULE))
   .processedWith(new DeepLinkProcessor())
   .failsToCompile()
   .withErrorContaining("Prefix property cannot be empty");
}
origin: robolectric/robolectric

@Test
public void shouldGenerateMetaInfServicesFile() {
 assertAbout(javaSources())
   .that(ImmutableList.of(
     SHADOW_PROVIDER_SOURCE,
     SHADOW_EXTRACTOR_SOURCE,
     forResource("org/robolectric/annotation/processing/shadows/ShadowClassNameOnly.java"),
     forResource("org/robolectric/annotation/processing/shadows/ShadowDummy.java")))
   .processedWith(new RobolectricProcessor(DEFAULT_OPTS))
   .compilesWithoutError()
   .and()
   .generatesFiles(forResource("META-INF/services/org.robolectric.internal.ShadowProvider"));
}
origin: JakeWharton/butterknife

@Test public void textChangedWithWrongParameter() {
 JavaFileObject source = JavaFileObjects.forSourceString("test.Test", ""
     + "package test;\n"
     + "import butterknife.OnTextChanged;\n"
     + "public class Test {\n"
     + "  @OnTextChanged(1) void doStuff(String p0, int p1, int p2, int p3) {}\n"
     + "}"
 );
 assertAbout(javaSource()).that(source)
     .withCompilerOptions("-Xlint:-processing")
     .processedWith(new ButterKnifeProcessor())
     .failsToCompile();
}
origin: robolectric/robolectric

@Test
public void generatedFile_shouldHandleClassNameOnlyShadows() {
 assertAbout(javaSources())
  .that(ImmutableList.of(
    SHADOW_PROVIDER_SOURCE,
    SHADOW_EXTRACTOR_SOURCE,
    forResource("org/robolectric/annotation/processing/shadows/ShadowClassNameOnly.java"),
    forResource("org/robolectric/annotation/processing/shadows/ShadowDummy.java")))
  .processedWith(new RobolectricProcessor(DEFAULT_OPTS))
  .compilesWithoutError()
  .and()
  .generatesSources(forResource("org/robolectric/Robolectric_ClassNameOnly.java"));
}
origin: JakeWharton/butterknife

@Test public void fieldVisibility() {
 JavaFileObject source = JavaFileObjects.forSourceString("test.Test", ""
   + "package test;\n"
   + "import android.view.View;\n"
   + "import butterknife.BindViews;\n"
   + "import java.util.List;\n"
   + "public class Test {\n"
   + "  @BindViews(1) public List<View> thing1;\n"
   + "  @BindViews(2) List<View> thing2;\n"
   + "  @BindViews(3) protected List<View> thing3;\n"
   + "}"
 );
 assertAbout(javaSource()).that(source)
   .withCompilerOptions("-Xlint:-processing")
   .processedWith(new ButterKnifeProcessor())
   .compilesWithoutWarnings();
}
origin: robolectric/robolectric

@Test
public void shouldGenerateGenericShadowOf() {
 assertAbout(javaSources())
  .that(ImmutableList.of(
    SHADOW_PROVIDER_SOURCE,
    SHADOW_EXTRACTOR_SOURCE,
    forResource("org/robolectric/annotation/processing/shadows/ShadowDummy.java"),
    forResource("org/robolectric/annotation/processing/shadows/ShadowParameterizedDummy.java")))
  .processedWith(new RobolectricProcessor(DEFAULT_OPTS))
  .compilesWithoutError()
  .and()
  .generatesSources(forResource("org/robolectric/Robolectric_Parameterized.java"));
}
origin: JakeWharton/butterknife

@Test public void fieldVisibility() {
 JavaFileObject source = JavaFileObjects.forSourceString("test.Test", ""
   + "package test;\n"
   + "import android.view.View;\n"
   + "import butterknife.BindView;\n"
   + "public class Test {\n"
   + "  @BindView(1) public View thing1;\n"
   + "  @BindView(2) View thing2;\n"
   + "  @BindView(3) protected View thing3;\n"
   + "}"
 );
 assertAbout(javaSource()).that(source)
   .withCompilerOptions("-Xlint:-processing")
   .processedWith(new ButterKnifeProcessor())
   .compilesWithoutWarnings();
}
origin: robolectric/robolectric

 @Test
 public void generatedShadowProvider_canConfigureInstrumentingPackages() {
  Map<String, String> options = new HashMap<>(DEFAULT_OPTS);
  options.put(SHOULD_INSTRUMENT_PKG_OPT, "false");

  assertAbout(javaSources())
  .that(ImmutableList.of(
    SHADOW_PROVIDER_SOURCE,
    SHADOW_EXTRACTOR_SOURCE,
    forResource("org/robolectric/annotation/processing/shadows/ShadowDummy.java")))
  .processedWith(new RobolectricProcessor(options))
  .compilesWithoutError()
  .and()
  .generatesSources(forResource("org/robolectric/Robolectric_EmptyProvidedPackageNames.java"));
 }
}
origin: JakeWharton/butterknife

@Test public void typeMustBeTypeface() {
 JavaFileObject source = JavaFileObjects.forSourceString("test.Test", ""
   + "package test;\n"
   + "import butterknife.BindFont;\n"
   + "public class Test {\n"
   + "  @BindFont(1) String one;\n"
   + "}"
 );
 assertAbout(javaSource()).that(source)
   .processedWith(new ButterKnifeProcessor())
   .failsToCompile()
   .withErrorContaining("@BindFont field type must be 'Typeface'. (test.Test.one)")
   .in(source).onLine(4);
}
origin: MatthiasRobbers/shortbread

  @Test
  public void twoMethodShortcutActivities() {
    JavaFileObject source1 = JavaFileObjects.forResource("MethodShortcutActivity.java");
    JavaFileObject source2 = JavaFileObjects.forResource("MethodShortcutActivity2.java");
    JavaFileObject generated = JavaFileObjects.forResource("TwoMethodShortcutActivitiesGenerated.java");
    assertAbout(javaSources()).that(Arrays.asList(source1, source2))
        .processedWith(new ShortcutProcessor())
        .compilesWithoutError()
        .and()
        .generatesSources(generated);
  }
}
origin: JakeWharton/butterknife

@Test public void failsWithInvalidId() {
 JavaFileObject source = JavaFileObjects.forSourceString("test.Test", ""
   + "package test;\n"
   + "import butterknife.OnItemClick;\n"
   + "public class Test {\n"
   + "  @OnItemClick({1, -1}) void doStuff() {}\n"
   + "}"
 );
 assertAbout(javaSource()).that(source)
   .processedWith(new ButterKnifeProcessor())
   .failsToCompile()
   .withErrorContaining("@OnItemClick annotation contains invalid ID -1. (test.Test.doStuff)")
   .in(source).onLine(4);
}
origin: robolectric/robolectric

@Test
public void generatedFile_shouldNotGenerateShadowOfMethodsForExcludedClasses() {
 assertAbout(javaSources())
   .that(ImmutableList.of(
     SHADOW_PROVIDER_SOURCE,
     SHADOW_EXTRACTOR_SOURCE,
     forResource("org/robolectric/annotation/processing/shadows/ShadowExcludedFromAndroidSdk.java")))
   .processedWith(new RobolectricProcessor(DEFAULT_OPTS))
   .compilesWithoutError()
   .and()
   .generatesSources(forResource("org/robolectric/Robolectric_NoExcludedTypes.java"));
}
origin: JakeWharton/butterknife

 @Test public void typeMustBeBitmap() {
  JavaFileObject source = JavaFileObjects.forSourceString("test.Test", ""
    + "package test;\n"
    + "import butterknife.BindBitmap;\n"
    + "public class Test {\n"
    + "  @BindBitmap(1) String one;\n"
    + "}"
  );

  assertAbout(javaSource()).that(source)
    .processedWith(new ButterKnifeProcessor())
    .failsToCompile()
    .withErrorContaining("@BindBitmap field type must be 'Bitmap'. (test.Test.one)")
    .in(source).onLine(4);
 }
}
origin: robolectric/robolectric

public SingleClassSubject(FailureMetadata failureMetadata, String subject) {
 super(failureMetadata, subject);
 source = JavaFileObjects.forResource(Utils.toResourcePath(subject));
 tester =
   assertAbout(javaSources())
     .that(ImmutableList.of(source, Utils.SHADOW_EXTRACTOR_SOURCE))
     .processedWith(new RobolectricProcessor(DEFAULT_OPTS));
}
com.google.testing.compileJavaFileObjects

Javadoc

A utility class for creating JavaFileObject instances.

Most used methods

  • forSourceString
    Creates a JavaFileObject with a path corresponding to the fullyQualifiedNamecontaining the give sour
  • forResource
    Returns a JavaFileObject for the resource at the given URL. The returned object will always be read-
  • forSourceLines
    Behaves exactly like #forSourceString, but joins lines so that multi-line source strings may omit th
  • asByteSource
  • deduceKind

Popular in Java

  • Parsing JSON documents to java classes using gson
  • runOnUiThread (Activity)
  • compareTo (BigDecimal)
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • Container (java.awt)
    A generic Abstract Window Toolkit(AWT) container object is a component that can contain other AWT co
  • URI (java.net)
    A Uniform Resource Identifier that identifies an abstract or physical resource, as specified by RFC
  • LinkedList (java.util)
    Doubly-linked list implementation of the List and Dequeinterfaces. Implements all optional list oper
  • ResourceBundle (java.util)
    ResourceBundle is an abstract class which is the superclass of classes which provide Locale-specifi
  • Callable (java.util.concurrent)
    A task that returns a result and may throw an exception. Implementors define a single method with no
  • Response (javax.ws.rs.core)
    Defines the contract between a returned instance and the runtime when an application needs to provid
  • Best IntelliJ plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now