當前位置: 首頁>>代碼示例>>Java>>正文


Java JavaFileObjects.forSourceLines方法代碼示例

本文整理匯總了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);
}
 
開發者ID:salesforce,項目名稱:AptSpring,代碼行數:26,代碼來源:FieldTests.java

示例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");
}
 
開發者ID:google,項目名稱:easybundler,代碼行數:27,代碼來源:ProcessorTest.java

示例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);
}
 
開發者ID:salesforce,項目名稱:AptSpring,代碼行數:27,代碼來源:ParserTests.java

示例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);
}
 
開發者ID:salesforce,項目名稱:AptSpring,代碼行數:25,代碼來源:FieldTests.java

示例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);
}
 
開發者ID:salesforce,項目名稱:AptSpring,代碼行數:24,代碼來源:ParserTests.java

示例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);
}
 
開發者ID:salesforce,項目名稱:AptSpring,代碼行數:25,代碼來源:ParserTests.java

示例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);
}
 
開發者ID:salesforce,項目名稱:AptSpring,代碼行數:27,代碼來源:ParserTests.java

示例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();
}
 
開發者ID:salesforce,項目名稱:AptSpring,代碼行數:27,代碼來源:ParserTests.java

示例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);
}
 
開發者ID:salesforce,項目名稱:AptSpring,代碼行數:25,代碼來源:FieldTests.java

示例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);
}
 
開發者ID:salesforce,項目名稱:AptSpring,代碼行數:27,代碼來源:ParserTests.java

示例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");
}
 
開發者ID:google,項目名稱:easybundler,代碼行數:23,代碼來源:ProcessorTest.java

示例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);
}
 
開發者ID:salesforce,項目名稱:AptSpring,代碼行數:27,代碼來源:ParserTests.java

示例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);
}
 
開發者ID:salesforce,項目名稱:AptSpring,代碼行數:25,代碼來源:FieldTests.java

示例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);
}
 
開發者ID:salesforce,項目名稱:AptSpring,代碼行數:26,代碼來源:FieldTests.java

示例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
  ));
}
 
開發者ID:ashdavies,項目名稱:auto,代碼行數:11,代碼來源:AnnotationCompilerTest.java


注:本文中的com.google.testing.compile.JavaFileObjects.forSourceLines方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。