Exemplo n.º 1
0
  @Test
  public void testCreateEnum() throws Exception {
    Project project = projectFactory.createTempProject();
    facetFactory.install(project, JavaSourceFacet.class);
    JavaSourceFacet facet = project.getFacet(JavaSourceFacet.class);
    JavaEnumSource javaEnum =
        Roaster.parse(
            JavaEnumSource.class, "package org.jboss.forge.test; public enum CreditCardType{}");
    facet.saveJavaSource(javaEnum);

    JavaResource javaResource = facet.getJavaResource("org.jboss.forge.test.CreditCardType");
    Assert.assertNotNull(javaResource);
    Assert.assertThat(javaResource.getJavaType(), is(instanceOf(JavaEnum.class)));

    CommandController controller =
        testHarness.createCommandController(JavaAddEnumConstantCommand.class, javaResource);
    controller.initialize();
    controller.setValueFor("named", "VISA");
    Assert.assertTrue(controller.isValid());
    Assert.assertTrue(controller.canExecute());
    Result result = controller.execute();
    Assert.assertThat(result, is(not(instanceOf(Failed.class))));

    javaResource = facet.getJavaResource("org.jboss.forge.test.CreditCardType");
    JavaEnumSource enumClass = javaResource.getJavaType();
    List<EnumConstantSource> enumConstants = enumClass.getEnumConstants();
    Assert.assertEquals(1, enumConstants.size());

    Assert.assertEquals("VISA", enumConstants.get(0).getName());
  }
Exemplo n.º 2
0
 public JavaResource createEmptyEnum(Project project, String enumName) throws IOException {
   JavaSourceFacet javaSourceFacet = project.getFacet(JavaSourceFacet.class);
   JavaEnumSource enumSource = Roaster.create(JavaEnumSource.class).setName(enumName);
   String packageName =
       project.getFacet(JavaSourceFacet.class).getBasePackage() + "." + DEFAULT_ENTITY_PACKAGE;
   enumSource.setPackage(packageName);
   return javaSourceFacet.saveJavaSource(enumSource);
 }
Exemplo n.º 3
0
 @Test
 public void testJavaDocEnumConstant() throws Exception {
   String text =
       "public enum MyEnum {"
           + "/**"
           + LINE_SEPARATOR
           + " * Do Something"
           + LINE_SEPARATOR
           + " * @author George Gastaldi"
           + LINE_SEPARATOR
           + " */"
           + LINE_SEPARATOR
           + ""
           + "MY_CONSTANT;}";
   JavaEnumSource javaEnum = Roaster.parse(JavaEnumSource.class, text);
   Assert.assertFalse(javaEnum.hasJavaDoc());
   EnumConstantSource enumConstant = javaEnum.getEnumConstant("MY_CONSTANT");
   Assert.assertTrue(enumConstant.hasJavaDoc());
   JavaDocSource<EnumConstantSource> javaDoc = enumConstant.getJavaDoc();
   String expected = "Do Something" + LINE_SEPARATOR + "@author George Gastaldi";
   Assert.assertEquals(expected, javaDoc.getFullText());
 }