本文整理汇总了Java中com.google.testing.compile.JavaFileObjects.forSourceLines方法的典型用法代码示例。如果您正苦于以下问题:Java JavaFileObjects.forSourceLines方法的具体用法?Java JavaFileObjects.forSourceLines怎么用?Java JavaFileObjects.forSourceLines使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.testing.compile.JavaFileObjects
的用法示例。
在下文中一共展示了JavaFileObjects.forSourceLines方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testHasNoModifiers
import com.google.testing.compile.JavaFileObjects; //导入方法依赖的package包/类
@Test
public void testHasNoModifiers() throws IOException {
JavaFileObject definitionClass = JavaFileObjects.forSourceLines(
"test.TestClass",
"package test;",
"",
"import org.springframework.context.annotation.Configuration;",
"import java.util.Date;",
"",
" @com.salesforce.aptspring.Verified",
" @Configuration",
" public class TestClass {",
"",
" String someVariable = \"I AM GOOD!\";",
"",
"}");
assertAbout(javaSources())
.that(Arrays.asList(definitionClass))
.processedWith(new VerifiedSpringConfiguration())
.failsToCompile()
.withErrorContaining("Only private static final constants are permitted in @Verified @Configuration classes")
.in(definitionClass)
.onLine(10);
}
示例2: testInvalidType
import com.google.testing.compile.JavaFileObjects; //导入方法依赖的package包/类
@Test
public void testInvalidType() {
String[] source = new String[]{
"package pub.devrel.bundler.objects;",
"",
"import java.util.Queue;",
"import pub.devrel.bundler.BundlerClass;",
"",
"@BundlerClass",
"public class HasInvalidField {",
"",
" public Queue<Object> queue;",
"",
" public HasInvalidField() {}",
"}"
};
JavaFileObject object = JavaFileObjects.forSourceLines(
"pub.devrel.bundler.objects.HasInvalidField",
source);
assertAbout(javaSource()).that(object)
.processedWith(new BundlerClassProcessor())
.failsToCompile()
.withErrorContaining("unknown type");
}
示例3: testConfigurationBeanMethodMustHaveAtLeastOneName
import com.google.testing.compile.JavaFileObjects; //导入方法依赖的package包/类
@Test
public void testConfigurationBeanMethodMustHaveAtLeastOneName() throws IOException {
JavaFileObject definitionClass = JavaFileObjects.forSourceLines(
"test.TestClass",
"package test;",
"",
"import org.springframework.context.annotation.Bean;",
"import org.springframework.context.annotation.Configuration;",
"",
"@com.salesforce.aptspring.Verified",
"@Configuration",
"public class TestClass {",
"",
" @Bean",
" private String getValue() { return \"I AM NOT GOOD!\"; }",
"",
"}");
assertAbout(javaSources())
.that(Arrays.asList(definitionClass))
.processedWith(new VerifiedSpringConfiguration())
.failsToCompile()
.withErrorContaining("All @Bean annotations must define at least one name for a bean")
.in(definitionClass)
.onLine(11);
}
示例4: testFieldIsntPrivate
import com.google.testing.compile.JavaFileObjects; //导入方法依赖的package包/类
@Test
public void testFieldIsntPrivate() throws IOException {
JavaFileObject definitionClass = JavaFileObjects.forSourceLines(
"test.TestClass",
"package test;",
"",
"import org.springframework.context.annotation.Configuration;",
"",
" @com.salesforce.aptspring.Verified",
" @Configuration",
" public class TestClass {",
"",
" static final String someVariable = \"x\";",
"",
"}");
assertAbout(javaSources())
.that(Arrays.asList(definitionClass))
.processedWith(new VerifiedSpringConfiguration())
.failsToCompile()
.withErrorContaining("Only private static final constants are permitted in @Verified @Configuration classes")
.in(definitionClass)
.onLine(9);
}
示例5: testMustHaveConfiguration
import com.google.testing.compile.JavaFileObjects; //导入方法依赖的package包/类
@Test
public void testMustHaveConfiguration() throws IOException {
JavaFileObject definitionClass = JavaFileObjects.forSourceLines(
"test.TestClass",
"package test;",
"",
"import org.springframework.context.annotation.Configuration;",
"",
"@com.salesforce.aptspring.Verified",
"public class TestClass {",
"",
" private static final String someVariable = \"I AM GOOD!\";",
"",
"}");
assertAbout(javaSources())
.that(Arrays.asList(definitionClass))
.processedWith(new VerifiedSpringConfiguration())
.failsToCompile()
.withErrorContaining("@Verified annotation must only be used on @Configuration or @Component classes")
.in(definitionClass)
.onLine(6);
}
示例6: testConfigurationMethodMustHaveBean
import com.google.testing.compile.JavaFileObjects; //导入方法依赖的package包/类
@Test
public void testConfigurationMethodMustHaveBean() throws IOException {
JavaFileObject definitionClass = JavaFileObjects.forSourceLines(
"test.TestClass",
"package test;",
"",
"import org.springframework.context.annotation.Configuration;",
"",
"@com.salesforce.aptspring.Verified",
"@Configuration",
"public class TestClass {",
"",
" private String getValue() { return \"I AM NOT GOOD!\"; }",
"",
"}");
assertAbout(javaSources())
.that(Arrays.asList(definitionClass))
.processedWith(new VerifiedSpringConfiguration())
.failsToCompile()
.withErrorContaining("All methods on @Configuration must have @Bean annotation")
.in(definitionClass)
.onLine(9);
}
示例7: testConfigurationBeanMethodMustBePublic
import com.google.testing.compile.JavaFileObjects; //导入方法依赖的package包/类
@Test
public void testConfigurationBeanMethodMustBePublic() throws IOException {
JavaFileObject definitionClass = JavaFileObjects.forSourceLines(
"test.TestClass",
"package test;",
"",
"import org.springframework.context.annotation.Bean;",
"import org.springframework.context.annotation.Configuration;",
"",
"@com.salesforce.aptspring.Verified",
"@Configuration",
"public class TestClass {",
"",
" @Bean(name = {\"stuff\",\"stuff2\"})",
" private String getValue() { return \"I AM NOT GOOD!\"; }",
"",
"}");
assertAbout(javaSources())
.that(Arrays.asList(definitionClass))
.processedWith(new VerifiedSpringConfiguration())
.failsToCompile()
.withErrorContaining("@Bean methods must be marked public")
.in(definitionClass)
.onLine(11);
}
示例8: testRootConfigurationCompilesWithValues
import com.google.testing.compile.JavaFileObjects; //导入方法依赖的package包/类
@Test
public void testRootConfigurationCompilesWithValues() throws IOException {
JavaFileObject definitionClass = JavaFileObjects.forSourceLines(
"test.TestClass",
"package test;",
"",
"import org.springframework.context.annotation.Bean;",
"import org.springframework.context.annotation.Configuration;",
"import org.springframework.context.annotation.ComponentScan;",
"import org.springframework.beans.factory.annotation.Value;",
"import org.springframework.beans.factory.annotation.Qualifier;",
"",
"@com.salesforce.aptspring.Verified(root=true)",
"@Configuration",
"public class TestClass {",
" ",
" @Bean(value=\"stuff1\")",
" public String getValue1(@Value(\"x\") String s) { return \"\"; }",
" ",
"}");
assertAbout(javaSources())
.that(Arrays.asList(definitionClass))
.processedWith(new VerifiedSpringConfiguration())
.compilesWithoutError();
}
示例9: testFieldIsntStatic
import com.google.testing.compile.JavaFileObjects; //导入方法依赖的package包/类
@Test
public void testFieldIsntStatic() throws IOException {
JavaFileObject definitionClass = JavaFileObjects.forSourceLines(
"test.TestClass",
"package test;",
"",
"import org.springframework.context.annotation.Configuration;",
"",
" @com.salesforce.aptspring.Verified",
" @Configuration",
" public class TestClass {",
"",
" private final String someVariable = \"x\";",
"",
"}");
assertAbout(javaSources())
.that(Arrays.asList(definitionClass))
.processedWith(new VerifiedSpringConfiguration())
.failsToCompile()
.withErrorContaining("Only private static final constants are permitted in @Verified @Configuration classes")
.in(definitionClass)
.onLine(9);
}
示例10: testFailIfUnexpectedElement
import com.google.testing.compile.JavaFileObjects; //导入方法依赖的package包/类
@Test
public void testFailIfUnexpectedElement() throws IOException {
JavaFileObject definitionClass = JavaFileObjects.forSourceLines(
"test.TestClass",
"package test;",
"",
"import org.springframework.context.annotation.Bean;",
"import org.springframework.context.annotation.Configuration;",
"",
"@com.salesforce.aptspring.Verified",
"@Configuration",
"public class TestClass {",
"",
" public enum Day { SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY };",
" ",
"}");
assertAbout(javaSources())
.that(Arrays.asList(definitionClass))
.processedWith(new VerifiedSpringConfiguration())
.failsToCompile()
.withErrorContaining("Only @Bean methods, private static final literals,"
+ " and default constructors are allowed on @Configuration classes")
.in(definitionClass)
.onLine(10);
}
示例11: testNoDefaultConstructor
import com.google.testing.compile.JavaFileObjects; //导入方法依赖的package包/类
@Test
public void testNoDefaultConstructor() {
String[] source = new String[]{
"package pub.devrel.bundler.objects;",
"",
"import pub.devrel.bundler.BundlerClass;",
"",
"@BundlerClass",
"public class NoDefaultConstructor {",
" public NoDefaultConstructor(String string) {}",
"}"
};
JavaFileObject object = JavaFileObjects.forSourceLines(
"pub.devrel.bundler.objects.NoDefaultConstructor",
source);
assertAbout(javaSource()).that(object)
.processedWith(new BundlerClassProcessor())
.failsToCompile()
.withErrorContaining("default constructor");
}
示例12: testConfigurationMayNotHaveNonPublicConstructors
import com.google.testing.compile.JavaFileObjects; //导入方法依赖的package包/类
@Test
public void testConfigurationMayNotHaveNonPublicConstructors() throws IOException {
JavaFileObject definitionClass = JavaFileObjects.forSourceLines(
"test.TestClass",
"package test;",
"",
"import org.springframework.context.annotation.Bean;",
"import org.springframework.context.annotation.Configuration;",
"",
"@com.salesforce.aptspring.Verified",
"@Configuration",
"public class TestClass {",
"",
" private TestClass() {",
" }",
"",
"}");
assertAbout(javaSources())
.that(Arrays.asList(definitionClass))
.processedWith(new VerifiedSpringConfiguration())
.failsToCompile()
.withErrorContaining("@Configuration should not have any non-public constructors.")
.in(definitionClass)
.onLine(10);
}
示例13: testFieldDoesntHaveConstantValue
import com.google.testing.compile.JavaFileObjects; //导入方法依赖的package包/类
@Test
public void testFieldDoesntHaveConstantValue() throws IOException {
JavaFileObject definitionClass = JavaFileObjects.forSourceLines(
"test.TestClass",
"package test;",
"",
"import org.springframework.context.annotation.Configuration;",
"",
" @com.salesforce.aptspring.Verified",
" @Configuration",
" public class TestClass {",
"",
" private static final String someVariable = null;",
"",
"}");
assertAbout(javaSources())
.that(Arrays.asList(definitionClass))
.processedWith(new VerifiedSpringConfiguration())
.failsToCompile()
.withErrorContaining("Only private static final constants are permitted in @Verified @Configuration classes")
.in(definitionClass)
.onLine(9);
}
示例14: testFieldIsntALiteral
import com.google.testing.compile.JavaFileObjects; //导入方法依赖的package包/类
@Test
public void testFieldIsntALiteral() throws IOException {
JavaFileObject definitionClass = JavaFileObjects.forSourceLines(
"test.TestClass",
"package test;",
"",
"import org.springframework.context.annotation.Configuration;",
"import java.util.Date;",
"",
" @com.salesforce.aptspring.Verified",
" @Configuration",
" public class TestClass {",
"",
" private static final Date someVariable = new Date();",
"",
"}");
assertAbout(javaSources())
.that(Arrays.asList(definitionClass))
.processedWith(new VerifiedSpringConfiguration())
.failsToCompile()
.withErrorContaining("Only private static final constants are permitted in @Verified @Configuration classes")
.in(definitionClass)
.onLine(10);
}
示例15: forSourceLines
import com.google.testing.compile.JavaFileObjects; //导入方法依赖的package包/类
private JavaFileObject forSourceLines(String... lines) {
return JavaFileObjects.forSourceLines(CLASS_NAME, ArrayUtils.addAll(
new String[] {
String.format("package %s;", PACKAGE_NAME), StringUtils.EMPTY,
String.format("import %s;", kls.getCanonicalName()), StringUtils.EMPTY,
String.format("@%s", name(kls))
},
lines
));
}