@Test public void shouldGenerateJavadocJson() throws Exception { assertAbout(javaSources()) .that( ImmutableList.of( forResource("org/robolectric/DocumentedObjectOuter.java"), forResource( "org/robolectric/annotation/processing/shadows/DocumentedObjectShadow.java"))) .processedWith(new RobolectricProcessor(DEFAULT_OPTS)) .compilesWithoutError(); JsonParser jsonParser = new JsonParser(); String jsonDocsDir = DEFAULT_OPTS.get(JSON_DOCS_DIR); String jsonFile = jsonDocsDir + "/org.robolectric.DocumentedObjectOuter.DocumentedObject.json"; JsonElement json = jsonParser.parse(Files.newBufferedReader(Paths.get(jsonFile), UTF_8)); assertThat(((JsonObject) json).get("documentation").getAsString()) .isEqualTo("DocumentedObjectOuter Javadoc goes here! "); // must list imported classes, including inner classes... assertThat(((JsonObject) json).get("imports").getAsJsonArray()) .containsExactly( new JsonPrimitive("org.robolectric.DocumentedObjectOuter"), new JsonPrimitive("org.robolectric.annotation.Implementation"), new JsonPrimitive("org.robolectric.annotation.Implements"), new JsonPrimitive("java.util.Map"), new JsonPrimitive( "org.robolectric.annotation.processing.shadows.DocumentedObjectShadow.SomeEnum")); } }
.withCompilerOptions("-Xlint:-processing") .processedWith(new ButterKnifeProcessor()) .compilesWithoutWarnings() .and()
@Test public void generatedFile_shouldUseSpecifiedPackage() throws IOException { StringBuilder expected = new StringBuilder(); InputStream in = RobolectricProcessorTest.class.getClassLoader() .getResourceAsStream("org/robolectric/Robolectric_ClassNameOnly.java"); BufferedReader reader = new BufferedReader(new InputStreamReader(in, UTF_8)); String line; while ((line = reader.readLine()) != null) { expected.append(line).append("\n"); } line = expected.toString(); line = line.replace("package org.robolectric", "package my.test.pkg"); ImmutableMap<String, String> opts = ImmutableMap.of( PACKAGE_OPT, "my.test.pkg", JSON_DOCS_DIR, Files.createTempDir().toString()); 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(opts)) .compilesWithoutError() .and() .generatesSources(forSourceString("Shadows", line)); }
.withCompilerOptions("-Xlint:-processing") .processedWith(new ButterKnifeProcessor()) .compilesWithoutWarnings() .and()
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)); }
.withCompilerOptions("-Xlint:-processing") .processedWith(new ButterKnifeProcessor()) .compilesWithoutWarnings() .and()
@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 }
.withCompilerOptions("-Xlint:-processing") .processedWith(new ButterKnifeProcessor()) .compilesWithoutWarnings() .and()
@Test public void shouldGracefullyHandleUnrecognisedAnnotation() { assertAbout(javaSources()) .that(ImmutableList.of( SHADOW_PROVIDER_SOURCE, SHADOW_EXTRACTOR_SOURCE, forResource("org/robolectric/annotation/TestWithUnrecognizedAnnotation.java"))) .processedWith(new RobolectricProcessor(DEFAULT_OPTS)) .compilesWithoutError(); }
.withCompilerOptions("-Xlint:-processing") .processedWith(new ButterKnifeProcessor()) .compilesWithoutWarnings() .and()
@Test public void realObjectWithCorrectClassName_shouldCompile() { assertAbout(javaSources()) .that(ImmutableList.of( SHADOW_EXTRACTOR_SOURCE, forResource("org/robolectric/annotation/processing/shadows/ShadowRealObjectWithCorrectClassName.java"))) .processedWith(new RobolectricProcessor(DEFAULT_OPTS)) .compilesWithoutError(); }
.withCompilerOptions("-Xlint:-processing") .processedWith(new ButterKnifeProcessor())
@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")); } }
.withCompilerOptions("-Xlint:-processing") .processedWith(new ButterKnifeProcessor()) .compilesWithoutWarnings() .and()
@Test public void generatedFile_shouldComplainAboutNonStaticInnerClasses() { assertAbout(javaSources()) .that(ImmutableList.of( SHADOW_PROVIDER_SOURCE, SHADOW_EXTRACTOR_SOURCE, forResource("org/robolectric/annotation/processing/shadows/ShadowOuterDummyWithErrs.java"))) .processedWith(new RobolectricProcessor(DEFAULT_OPTS)) .failsToCompile() .withErrorContaining("inner shadow classes must be static"); }
.withCompilerOptions("-Xlint:-processing") .processedWith(new ButterKnifeProcessor()) .compilesWithoutWarnings() .and()
@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); }
.withCompilerOptions("-Xlint:-processing") .processedWith(new ButterKnifeProcessor()) .compilesWithoutWarnings() .and() .withCompilerOptions("-Xlint:-processing") .processedWith(new ButterKnifeProcessor()) .compilesWithoutWarnings() .and()
@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); } }
sourceG, sourceH)) .withCompilerOptions("-Xlint:-processing") .processedWith(new ButterKnifeProcessor()) .compilesWithoutWarnings() .and()