本文整理匯總了Java中com.google.testing.compile.JavaFileObjects類的典型用法代碼示例。如果您正苦於以下問題:Java JavaFileObjects類的具體用法?Java JavaFileObjects怎麽用?Java JavaFileObjects使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
JavaFileObjects類屬於com.google.testing.compile包,在下文中一共展示了JavaFileObjects類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: test
import com.google.testing.compile.JavaFileObjects; //導入依賴的package包/類
@Test
public void test() throws URISyntaxException, MalformedURLException {
Compilation compilation = Compiler.javac()
.withProcessors(new SyndesisExtensionActionProcessor())
.compile(JavaFileObjects.forSourceString(
"test.AnnotatedClassTest",
"package test;\n" +
"\n" +
"@io.syndesis.integration.runtime.api.SyndesisExtensionAction(\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.properties").isPresent());
}
示例2: testAnnotatedMembers_instanceField
import com.google.testing.compile.JavaFileObjects; //導入依賴的package包/類
@Test
public void testAnnotatedMembers_instanceField() {
List<Diagnostic<? extends JavaFileObject>> diagnostics = compiler.compile(
BETA, ANNOTATED_MEMBERS,
JavaFileObjects.forSourceLines("example.Test",
"package example;",
"",
"import com.google.common.foo.AnnotatedMembers;",
"",
"public class Test {",
" public static void foo(AnnotatedMembers instance) {",
" System.out.println(instance.annotatedInstanceField);", // error
" }",
"}")
);
compiler.assertErrorsOnLines("example/Test.java", diagnostics, 7);
}
示例3: methodVisibility
import com.google.testing.compile.JavaFileObjects; //導入依賴的package包/類
@Test public void methodVisibility() {
JavaFileObject source = JavaFileObjects.forSourceString("test.Test", ""
+ "package test;\n"
+ "import android.view.View;\n"
+ "import butterknife.OnClick;\n"
+ "public class Test {\n"
+ " @OnClick(1) public void thing1() {}\n"
+ " @OnClick(2) void thing2() {}\n"
+ " @OnClick(3) protected void thing3() {}\n"
+ "}"
);
assertAbout(javaSource()).that(source)
.withCompilerOptions("-Xlint:-processing")
.processedWith(new ButterKnifeProcessor())
.compilesWithoutWarnings();
}
示例4: compilation_withExtension_fails
import com.google.testing.compile.JavaFileObjects; //導入依賴的package包/類
@Test
public void compilation_withExtension_fails() {
expectedException.expect(RuntimeException.class);
javac()
.withProcessors(new GlideAnnotationProcessor())
.compile(
emptyAppModule(),
JavaFileObjects.forSourceLines(
"Extension",
"package com.bumptech.glide.test;",
"import com.bumptech.glide.annotation.GlideExtension;",
"@GlideExtension",
"class Extension {",
" private Extension() {}",
"}"));
}
示例5: testAnnotatedClass_extending
import com.google.testing.compile.JavaFileObjects; //導入依賴的package包/類
@Test
public void testAnnotatedClass_extending() {
List<Diagnostic<? extends JavaFileObject>> diagnostics = compiler.compile(
BETA, ANNOTATED_CLASS,
JavaFileObjects.forSourceLines(
"example.Test",
"package example;",
"",
"import com.google.common.foo.AnnotatedClass;",
"",
"public class Test extends AnnotatedClass {", // error
"}")
);
compiler.assertErrorsOnLines("example/Test.java", diagnostics, 5);
}
示例6: failsIfPrivateMethod
import com.google.testing.compile.JavaFileObjects; //導入依賴的package包/類
@Test public void failsIfPrivateMethod() {
JavaFileObject source = JavaFileObjects.forSourceString("test.Test", ""
+ "package test;\n"
+ "import butterknife.OnClick;\n"
+ "public class Test {\n"
+ " @OnClick(1)\n"
+ " private void doStuff() {\n"
+ " }\n"
+ "}"
);
assertAbout(javaSource()).that(source)
.processedWith(new ButterKnifeProcessor())
.failsToCompile()
.withErrorContaining("@OnClick methods must not be private or static. (test.Test.doStuff)")
.in(source).onLine(5);
}
示例7: testAnnotatedClass_asTypeArgument
import com.google.testing.compile.JavaFileObjects; //導入依賴的package包/類
@Test
public void testAnnotatedClass_asTypeArgument() {
List<Diagnostic<? extends JavaFileObject>> diagnostics = compiler.compile(
BETA, ANNOTATED_CLASS,
JavaFileObjects.forSourceLines(
"example.Test",
"package example;",
"",
"import com.google.common.foo.AnnotatedClass;",
"",
"import java.util.List;",
"",
"public class Test {",
" public static void foo(List<AnnotatedClass> stuff) {", // error
" }",
"}")
);
compiler.assertErrorsOnLines("example/Test.java", diagnostics, 8);
}
示例8: testAnnotatedClass_asParameter
import com.google.testing.compile.JavaFileObjects; //導入依賴的package包/類
@Test
public void testAnnotatedClass_asParameter() {
List<Diagnostic<? extends JavaFileObject>> diagnostics = compiler.compile(
BETA, ANNOTATED_CLASS,
JavaFileObjects.forSourceLines(
"example.Test",
"package example;",
"",
"import com.google.common.foo.AnnotatedClass;",
"",
"public class Test {",
" public static void foo(AnnotatedClass annotated) {", // error
" }",
"}")
);
compiler.assertErrorsOnLines("example/Test.java", diagnostics, 6);
}
示例9: testCleanClass
import com.google.testing.compile.JavaFileObjects; //導入依賴的package包/類
@Test
public void testCleanClass() {
List<Diagnostic<? extends JavaFileObject>> diagnostics = compiler.compile(BETA,
JavaFileObjects.forSourceLines(
"example.Test",
"package example;",
"",
"import java.util.Arrays;",
"",
"public class Test {",
" public static void main(String[] args) {",
" System.out.println(Arrays.asList(args));",
" }",
"}")
);
assertThat(diagnostics).isEmpty();
}
示例10: compilation_withAnnotatedStaticMethod_withoutRequestOptionsArg_fails
import com.google.testing.compile.JavaFileObjects; //導入依賴的package包/類
@Test
public void compilation_withAnnotatedStaticMethod_withoutRequestOptionsArg_fails() {
expectedException.expect(RuntimeException.class);
javac()
.withProcessors(new GlideAnnotationProcessor())
.compile(
emptyAppModule(),
JavaFileObjects.forSourceLines(
"Extension",
"package com.bumptech.glide.test;",
"import com.bumptech.glide.annotation.GlideExtension;",
"import com.bumptech.glide.annotation.GlideOption;",
"@GlideExtension",
"public class Extension {",
" private Extension() {}",
" @GlideOption",
" public static void doSomething() {}",
"}"));
}
示例11: testFindNodeClasses
import com.google.testing.compile.JavaFileObjects; //導入依賴的package包/類
@Test
public void testFindNodeClasses() throws FileNotFoundException {
JavaFileObject wand = JavaFileObjects.forResource("input/Wand.java");
JavaFileObject owner = JavaFileObjects.forResource("input/Owner.java");
JavaFileObject school = JavaFileObjects.forResource("input/School.java");
JavaFileObject autoValueWand = JavaFileObjects.forResource("expected/AutoValue_Wand.java");
JavaFileObject autoValueOwner = JavaFileObjects.forResource("expected/AutoValue_Owner.java");
JavaFileObject autoValueSchool = JavaFileObjects.forResource("expected/AutoValue_School.java");
JavaFileObject nodeWand = JavaFileObjects.forResource("expected/Node_Wand.java");
JavaFileObject nodeOwner = JavaFileObjects.forResource("expected/Node_Owner.java");
JavaFileObject nodeSchool = JavaFileObjects.forResource("expected/Node_School.java");
assertAbout(javaSources())
.that(Arrays.asList(school, owner, wand))
.processedWith(autoValueNodeProcessor, autoValueProcessor)
.compilesWithoutError()
.and()
.generatesSources(autoValueWand, autoValueOwner, autoValueSchool, nodeOwner, nodeSchool, nodeWand);
}
示例12: compilation_withAnnotatedStaticMethod_withNonRequestBuilderArg_fails
import com.google.testing.compile.JavaFileObjects; //導入依賴的package包/類
@Test
public void compilation_withAnnotatedStaticMethod_withNonRequestBuilderArg_fails() {
expectedException
.expectMessage(
"@GlideType methods must take a RequestBuilder object as their first and only"
+ " parameter, but given: java.lang.Object");
javac()
.withProcessors(new GlideAnnotationProcessor())
.compile(
emptyAppModule(),
JavaFileObjects.forSourceLines("Extension",
"package com.bumptech.glide.test;",
"import com.bumptech.glide.RequestBuilder;",
"import com.bumptech.glide.annotation.GlideExtension;",
"import com.bumptech.glide.annotation.GlideType;",
"@GlideExtension",
"public class Extension {",
" private Extension() {}",
" @GlideType(Number.class)",
" public static void type(Object arg) {}",
"}"));
}
示例13: compilationShoulNotFailIfDuplicateFoundAndSupressed
import com.google.testing.compile.JavaFileObjects; //導入依賴的package包/類
@Test
public void compilationShoulNotFailIfDuplicateFoundAndSupressed() {
final JavaFileObject source =
JavaFileObjects.forSourceString(
"com.groupon.android.dichecks.dummy.A",
Joiner.on('\n')
.join(
"package com.groupon.android.dichecks.dummy;",
"import javax.inject.Inject;",
"import javax.inject.Named;",
"public class A {",
" @Inject @Named(\"someNamedString\") String something;",
" @Inject InjectedClass aClass;",
"}",
"class B extends A {",
" @SuppressWarnings(\"" + CompilerOptions.OPTIONS_PREFIX + CompilerOptions.DUPLICATE_CHECK + "\")",
" @Inject InjectedClass aClass;",
"}",
"class D extends B {}",
"class C extends A {}",
"class InjectedClass {}"));
assertAbout(javaSource()).that(source).processedWith(new DiChecksProcessor()).compilesWithoutError();
}
示例14: compilation_withOverrideExtend_andOverridingMethod_succeeds
import com.google.testing.compile.JavaFileObjects; //導入依賴的package包/類
@Test
public void compilation_withOverrideExtend_andOverridingMethod_succeeds() {
Compilation compilation = javac()
.withProcessors(new GlideAnnotationProcessor())
.compile(
emptyAppModule(),
JavaFileObjects.forSourceLines(
"Extension",
"package com.bumptech.glide.test;",
"import com.bumptech.glide.annotation.GlideExtension;",
"import com.bumptech.glide.annotation.GlideOption;",
"import com.bumptech.glide.request.RequestOptions;",
"@GlideExtension",
"public class Extension {",
" private Extension() {}",
" @GlideOption(override = GlideOption.OVERRIDE_EXTEND)",
" public static void centerCrop(RequestOptions options) {}",
"}"));
assertThat(compilation).succeeded();
assertThat(compilation).hadWarningContaining("is using a legacy format.");
}
示例15: compilation_withAnnotatedStaticMethod_withRequestOptionsArg_succeeds
import com.google.testing.compile.JavaFileObjects; //導入依賴的package包/類
@Test
public void compilation_withAnnotatedStaticMethod_withRequestOptionsArg_succeeds() {
Compilation compilation = javac()
.withProcessors(new GlideAnnotationProcessor())
.compile(
emptyAppModule(),
JavaFileObjects.forSourceLines(
"Extension",
"package com.bumptech.glide.test;",
"import com.bumptech.glide.annotation.GlideExtension;",
"import com.bumptech.glide.annotation.GlideOption;",
"import com.bumptech.glide.request.RequestOptions;",
"@GlideExtension",
"public class Extension {",
" private Extension() {}",
" @GlideOption",
" public static void doSomething(RequestOptions options) {}",
"}"));
assertThat(compilation).succeeded();
assertThat(compilation).hadWarningContaining("is using a legacy format.");
}